1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 10:15:55 +03:00
semantic/test/Spec.hs

35 lines
2.0 KiB
Haskell
Raw Normal View History

2015-12-03 19:44:28 +03:00
module Main where
2015-12-03 19:38:49 +03:00
import Diff
import Range
2015-12-03 19:44:42 +03:00
import Split
import Syntax
import qualified Data.Set as Set
2015-12-03 19:38:49 +03:00
import Test.Hspec
2015-11-18 01:44:16 +03:00
main :: IO ()
2015-12-03 19:44:42 +03:00
main = hspec $ do
2015-12-04 17:00:40 +03:00
describe "adjoinRows" $ do
it "empty lines are the left unit" $
2015-12-04 00:24:35 +03:00
adjoinRows [ Row [] [] ] [ Row [ Text "a" ] [ Text "b" ] ] `shouldBe` [ Row [ Text "a" ] [ Text "b" ] ]
it "empty lines are the left unit for multiple lines" $
2015-12-04 00:24:35 +03:00
adjoinRows [ Row [] [] ] [ Row [ Text "a" ] [ Text "b" ], Row [ Text "a" ] [ Text "b" ] ] `shouldBe` [ Row [ Text "a" ] [ Text "b" ], Row [ Text "a" ] [ Text "b" ] ]
2015-12-03 19:44:42 +03:00
it "two single line elements should concatenate into a single line" $
2015-12-04 00:24:35 +03:00
adjoinRows [ Row [ Text "a" ] [ Text "b" ] ] [ Row [ Text "a" ] [ Text "b" ] ] `shouldBe` [ Row [ Text "a", Text "a" ] [ Text "b", Text "b" ] ]
2015-12-03 20:07:03 +03:00
it "single line elements on the left concatenate onto the first of multiple lines on the right" $
2015-12-04 00:24:35 +03:00
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" ] ]
2015-12-03 20:07:03 +03:00
it "the last of multiple line elements on the left concatenate onto the first of multiple lines on the right" $
2015-12-04 00:24:35 +03:00
adjoinRows [ Row [ Text "a1" ] [ Text "b1" ], Row [ Text "a2" ] [ Text "b2" ] ] [ Row [ Text "a3" ] [ Text "b3" ], Row [ Text "a4" ] [ Text "b4" ] ] `shouldBe` [ Row [ Text "a1" ] [ Text "b1" ], Row [ Text "a2", Text "a3" ] [ Text "b2", Text "b3" ], Row [ Text "a4" ] [ Text "b4" ] ]
describe "annotatedToRows" $ do
it "outputs one row for single-line unchanged leaves" $
2015-12-04 17:40:38 +03:00
annotatedToRows (Annotated (Info (Range 0 1) lineRange $ Set.fromList [ "leaf" ], Info (Range 0 1) lineRange $ Set.fromList [ "leaf" ]) (Leaf "")) "a" "a" `shouldBe` ([ Row [ Span (Just "leaf") "a" ] [ Span (Just "leaf") "a" ] ], Range 0 1, Range 0 1)
where
oneLineUnchangedIndexedSource = "[ a, b, c ]"
oneLineUnchangedIndexedRange = totalRange oneLineUnchangedIndexedSource
2015-12-04 17:40:38 +03:00
lineRange = Range 0 0