mirror of
https://github.com/github/semantic.git
synced 2024-12-29 01:42:43 +03:00
Swap the order of the operands to splitPatchByLines.
This commit is contained in:
parent
4a4eb23cb5
commit
3a555df147
@ -40,12 +40,12 @@ hasChanges = or . fmap (or . (True <$))
|
||||
splitDiffByLines :: Diff leaf Info -> Both (Source Char) -> [Row (SplitDiff leaf Info, Range)]
|
||||
splitDiffByLines diff sources = case diff of
|
||||
Free (Annotated annotation syntax) -> splitAnnotatedByLines sources (ranges annotation) (Diff.categories <$> annotation) syntax
|
||||
Pure patch -> splitPatchByLines patch sources
|
||||
Pure patch -> splitPatchByLines sources patch
|
||||
where ranges annotations = characterRange <$> annotations
|
||||
|
||||
-- | Split a patch, which may span multiple lines, into rows of split diffs.
|
||||
splitPatchByLines :: Patch (Term leaf Info) -> Both (Source Char) -> [Row (SplitDiff leaf Info, Range)]
|
||||
splitPatchByLines patch sources = zipWithDefaults makeRow (pure mempty) $ fmap (fmap (first (Pure . constructor patch))) <$> lines
|
||||
splitPatchByLines :: Both (Source Char) -> Patch (Term leaf Info) -> [Row (SplitDiff leaf Info, Range)]
|
||||
splitPatchByLines sources patch = zipWithDefaults makeRow (pure mempty) $ fmap (fmap (first (Pure . constructor patch))) <$> lines
|
||||
where lines = (maybe [] . splitAbstractedTerm copoint unwrap (:<) <$> sources) <*> unPatch patch
|
||||
constructor (Replace _ _) = SplitReplace
|
||||
constructor (Insert _) = SplitInsert
|
||||
|
@ -98,7 +98,7 @@ spec = parallel $ do
|
||||
describe "splitPatchByLines" $ do
|
||||
prop "starts at initial indices" $
|
||||
\ patch sources -> let indices = length <$> sources in
|
||||
fmap start . maybeFirst . Maybe.catMaybes <$> Both.unzip (fmap maybeFirst . unRow . fmap Prelude.snd <$> (splitPatchByLines (patchWithBoth patch (leafWithRangeInSource <$> sources <*> (Range <$> indices <*> ((2 *) <$> indices)))) ((Source.++) <$> sources <*> sources))) `shouldBe` (<$) <$> indices <*> unPatch patch
|
||||
fmap start . maybeFirst . Maybe.catMaybes <$> Both.unzip (fmap maybeFirst . unRow . fmap Prelude.snd <$> (splitPatchByLines ((Source.++) <$> sources <*> sources) (patchWithBoth patch (leafWithRangeInSource <$> sources <*> (Range <$> indices <*> ((2 *) <$> indices)))))) `shouldBe` (<$) <$> indices <*> unPatch patch
|
||||
|
||||
describe "openLineBy" $ do
|
||||
it "produces the earliest non-empty line in a list, if open" $
|
||||
|
Loading…
Reference in New Issue
Block a user