1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 16:02:43 +03:00

Fix tests

This commit is contained in:
joshvera 2015-12-08 12:35:40 -05:00
parent 5402a2bfbc
commit 51be1f341a

View File

@ -12,44 +12,44 @@ main :: IO ()
main = hspec $ do
describe "adjoinRows" $ do
it "empty lines are the left unit" $
adjoinRows [ Row [] [] ] [ Row [ Text "a" ] [ Text "b" ] ] `shouldBe` [ Row [ Text "a" ] [ Text "b" ] ]
adjoinRows [ Row EmptyLine EmptyLine ] [ Row (Line [ Text "a" ]) (Line [ Text "b" ]) ] `shouldBe` [ Row (Line [ Text "a" ]) (Line [ Text "b" ]) ]
it "empty lines are the left unit for multiple lines" $
adjoinRows [ Row [] [] ] [ Row [ Text "a" ] [ Text "b" ], Row [ Text "a" ] [ Text "b" ] ] `shouldBe` [ Row [ Text "a" ] [ Text "b" ], Row [ Text "a" ] [ Text "b" ] ]
adjoinRows [ Row EmptyLine EmptyLine ] [ Row (Line [ Text "a" ]) (Line [ Text "b" ]), Row (Line [ Text "a" ]) (Line [ Text "b" ]) ] `shouldBe` [ Row (Line [ Text "a" ]) (Line [ Text "b" ]), Row (Line [ Text "a" ]) (Line [ Text "b" ]) ]
it "two single line elements should concatenate into a single line" $
adjoinRows [ Row [ Text "a" ] [ Text "b" ] ] [ Row [ Text "a" ] [ Text "b" ] ] `shouldBe` [ Row [ Text "a", Text "a" ] [ Text "b", Text "b" ] ]
adjoinRows [ Row (Line [ Text "a" ]) (Line [ Text "b" ]) ] [ Row (Line [ Text "a" ]) (Line [ Text "b" ]) ] `shouldBe` [ Row (Line [ Text "a", Text "a" ]) (Line [ Text "b", Text "b" ]) ]
it "single line elements on the left concatenate onto the first of multiple lines on the right" $
adjoinRows [ Row [ Text "a1" ] [ Text "b1" ] ] [ Row [ Text "a2" ] [ Text "b2" ], Row [ Text "a3" ] [ Text "b3" ] ] `shouldBe` [ Row [ Text "a1", Text "a2" ] [ Text "b1", Text "b2" ], Row [ Text "a3" ] [ Text "b3" ] ]
adjoinRows [ Row (Line [ Text "a1" ]) (Line [ Text "b1" ]) ] [ Row (Line [ Text "a2" ]) (Line [ Text "b2" ]), Row (Line [ Text "a3" ]) (Line [ Text "b3" ]) ] `shouldBe` [ Row (Line [ Text "a1", Text "a2" ]) (Line [ Text "b1", Text "b2" ]), Row (Line [ Text "a3" ]) (Line [ Text "b3" ]) ]
it "the last of multiple line elements on the left concatenate onto the first of multiple lines on the right" $
adjoinRows [ Row [ Text "a1" ] [ Text "b1" ], Row [ Text "a2" ] [ Text "b2" ] ]
[ Row [ Text "a3" ] [ Text "b3" ], Row [ Text "a4" ] [ Text "b4" ] ]
adjoinRows [ Row (Line [ Text "a1" ]) (Line [ Text "b1" ]), Row (Line [ Text "a2" ]) (Line [ Text "b2" ]) ]
[ Row (Line [ Text "a3" ]) (Line [ Text "b3" ]), Row (Line [ Text "a4" ]) (Line [ Text "b4" ]) ]
`shouldBe`
[ Row [ Text "a1" ] [ Text "b1" ],
Row [ Text "a2", Text "a3" ] [ Text "b2", Text "b3" ],
Row [ Text "a4" ] [ Text "b4" ] ]
[ Row (Line [ Text "a1" ]) (Line [ Text "b1" ]),
Row (Line [ Text "a2", Text "a3" ]) (Line [ Text "b2", Text "b3" ]),
Row (Line [ Text "a4" ]) (Line [ Text "b4" ]) ]
describe "annotatedToRows" $ do
it "outputs one row for single-line unchanged leaves" $
annotatedToRows (unchanged "a" "leaf" (Leaf "")) "a" "a" `shouldBe` ([ Row [ span "a" ] [ span "a" ] ], (Range 0 1, Range 0 1))
annotatedToRows (unchanged "a" "leaf" (Leaf "")) "a" "a" `shouldBe` ([ Row (Line [ span "a" ]) (Line [ span "a" ]) ], (Range 0 1, Range 0 1))
it "outputs one row for single-line empty unchanged indexed nodes" $
annotatedToRows (unchanged "[]" "branch" (Indexed [])) "[]" "[]" `shouldBe` ([ Row [ Ul (Just "category-branch") [ Text "[]" ] ] [ Ul (Just "category-branch") [ Text "[]" ] ] ], (Range 0 2, Range 0 2))
annotatedToRows (unchanged "[]" "branch" (Indexed [])) "[]" "[]" `shouldBe` ([ Row (Line [ Ul (Just "category-branch") [ Text "[]" ] ]) (Line [ Ul (Just "category-branch") [ Text "[]" ] ]) ], (Range 0 2, Range 0 2))
it "outputs one row for single-line non-empty unchanged indexed nodes" $
annotatedToRows (unchanged "[ a, b ]" "branch" (Indexed [
Free . offsetAnnotated 2 2 $ unchanged "a" "leaf" (Leaf ""),
Free . offsetAnnotated 5 5 $ unchanged "b" "leaf" (Leaf "")
])) "[ a, b ]" "[ a, b ]" `shouldBe` ([ Row [ Ul (Just "category-branch") [ Text "[ ", span "a", Text ", ", span "b", Text " ]" ] ] [ Ul (Just "category-branch") [ Text "[ ", span "a", Text ", ", span "b", Text " ]" ] ] ], (Range 0 8, Range 0 8))
])) "[ a, b ]" "[ a, b ]" `shouldBe` ([ Row (Line [ Ul (Just "category-branch") [ Text "[ ", span "a", Text ", ", span "b", Text " ]" ] ]) (Line [ Ul (Just "category-branch") [ Text "[ ", span "a", Text ", ", span "b", Text " ]" ] ]) ], (Range 0 8, Range 0 8))
it "outputs one row for single-line non-empty formatted indexed nodes" $
annotatedToRows (formatted "[ a, b ]" "[ a, b ]" "branch" (Indexed [
Free . offsetAnnotated 2 2 $ unchanged "a" "leaf" (Leaf ""),
Free . offsetAnnotated 5 6 $ unchanged "b" "leaf" (Leaf "")
])) "[ a, b ]" "[ a, b ]" `shouldBe` ([ Row [ Ul (Just "category-branch") [ Text "[ ", span "a", Text ", ", span "b", Text " ]" ] ] [ Ul (Just "category-branch") [ Text "[ ", span "a", Text ", ", span "b", Text " ]" ] ] ], (Range 0 8, Range 0 9))
])) "[ a, b ]" "[ a, b ]" `shouldBe` ([ Row (Line [ Ul (Just "category-branch") [ Text "[ ", span "a", Text ", ", span "b", Text " ]" ] ]) (Line [ Ul (Just "category-branch") [ Text "[ ", span "a", Text ", ", span "b", Text " ]" ] ]) ], (Range 0 8, Range 0 9))
it "outputs two rows for two-line non-empty unchanged indexed nodes" $
annotatedToRows (unchanged "[ a,\nb ]" "branch" (Indexed [
@ -57,10 +57,10 @@ main = hspec $ do
Free . offsetAnnotated 5 5 $ unchanged "b" "leaf" (Leaf "")
])) "[ a,\nb ]" "[ a,\nb ]" `shouldBe`
([
Row [ Ul (Just "category-branch") [ Text "[ ", span "a", Text "," ] ]
[ Ul (Just "category-branch") [ Text "[ ", span "a", Text "," ] ],
Row [ Ul (Just "category-branch") [ Text "", span "b", Text " ]" ] ]
[ Ul (Just "category-branch") [ Text "", span "b", Text " ]" ] ]
Row (Line [ Ul (Just "category-branch") [ Text "[ ", span "a", Text "," ] ])
(Line [ Ul (Just "category-branch") [ Text "[ ", span "a", Text "," ] ]),
Row (Line [ Ul (Just "category-branch") [ Text "", span "b", Text " ]" ] ])
(Line [ Ul (Just "category-branch") [ Text "", span "b", Text " ]" ] ])
], (Range 0 8, Range 0 8))
it "outputs two rows for two-line non-empty formatted indexed nodes" $
@ -69,12 +69,12 @@ main = hspec $ do
Free . offsetAnnotated 5 5 $ unchanged "b" "leaf" (Leaf "")
])) "[ a,\nb ]" "[\na,\nb ]" `shouldBe`
([
Row [ Ul (Just "category-branch") [ Text "[ ", span "a", Text "," ] ]
[ Ul (Just "category-branch") [ Text "[" ] ],
Row [ Ul (Just "category-branch") [] ]
[ Ul (Just "category-branch") [ Text "", span "a", Text "," ] ],
Row [ Ul (Just "category-branch") [ Text "", span "b", Text " ]" ] ]
[ Ul (Just "category-branch") [ Text "", span "b", Text " ]" ] ]
Row (Line [ Ul (Just "category-branch") [ Text "[ ", span "a", Text "," ] ])
(Line [ Ul (Just "category-branch") [ Text "[" ] ]),
Row EmptyLine
(Line [ Ul (Just "category-branch") [ Text "", span "a", Text "," ] ]),
Row (Line [ Ul (Just "category-branch") [ Text "", span "b", Text " ]" ] ])
(Line [ Ul (Just "category-branch") [ Text "", span "b", Text " ]" ] ])
], (Range 0 8, Range 0 8))
where