1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 00:33:59 +03:00

Migrate the splitAnnotatedByLines tests to splitAbstractedTerm.

This commit is contained in:
Rob Rix 2016-03-09 09:32:51 -05:00
parent be1f548c61
commit ec0c1c448e

View File

@ -46,18 +46,6 @@ arbitraryLeaf = toTuple <$> arbitrary
spec :: Spec
spec = parallel $ do
describe "splitAnnotatedByLines" $ do
let makeTerm = ((Free .) . Annotated) :: Info -> Syntax (Source Char) (SplitDiff (Source Char) Info) -> SplitDiff (Source Char) Info
prop "outputs one row for single-line unchanged leaves" $
forAll (arbitraryLeaf `suchThat` isOnSingleLine) $
\ (source, info@(Info range categories), syntax) -> splitAnnotatedByLines makeTerm (pure source) (pure $ Info range categories) syntax `shouldBe` [
both (pure (makeTerm info $ Leaf source, Range 0 (length source))) (pure (makeTerm info $ Leaf source, Range 0 (length source))) ]
prop "outputs one row for single-line empty unchanged indexed nodes" $
forAll (arbitrary `suchThat` (\ a -> filter (/= '\n') (toList a) == toList a)) $
\ source -> splitAnnotatedByLines makeTerm (pure source) (pure $ Info (totalRange source) mempty) (Indexed []) `shouldBe` [
both (pure (makeTerm (Info (totalRange source) mempty) $ Indexed [], Range 0 (length source))) (pure (makeTerm (Info (totalRange source) mempty) $ Indexed [], Range 0 (length source))) ]
describe "splitDiffByLines" $ do
prop "preserves line counts in equal sources" $
\ source ->
@ -94,6 +82,17 @@ spec = parallel $ do
\ source -> let range = totalRange source in
splitAbstractedTerm sequenceA (:<) (Identity source) (Identity (Info range mempty)) (Leaf source) `shouldBe` (Identity . pure . ((:< Leaf source) . (`Info` mempty) &&& id) <$> actualLineRanges range source)
let makeTerm = ((Free .) . Annotated) :: Info -> Syntax (Source Char) (SplitDiff (Source Char) Info) -> SplitDiff (Source Char) Info
prop "outputs one row for single-line unchanged leaves" $
forAll (arbitraryLeaf `suchThat` isOnSingleLine) $
\ (source, info@(Info range categories), syntax) -> splitAbstractedTerm (zipDefaults mempty) makeTerm (pure source) (pure $ Info range categories) syntax `shouldBe` [
both (pure (makeTerm info $ Leaf source, Range 0 (length source))) (pure (makeTerm info $ Leaf source, Range 0 (length source))) ]
prop "outputs one row for single-line empty unchanged indexed nodes" $
forAll (arbitrary `suchThat` (\ a -> filter (/= '\n') (toList a) == toList a)) $
\ source -> splitAbstractedTerm (zipDefaults mempty) makeTerm (pure source) (pure $ Info (totalRange source) mempty) (Indexed []) `shouldBe` [
both (pure (makeTerm (Info (totalRange source) mempty) $ Indexed [], Range 0 (length source))) (pure (makeTerm (Info (totalRange source) mempty) $ Indexed [], Range 0 (length source))) ]
describe "splitPatchByLines" $ do
prop "starts at initial indices" $
\ patch sources -> let indices = length <$> sources in