1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00
semantic/test/Source/Spec.hs

26 lines
944 B
Haskell
Raw Normal View History

2016-09-13 18:35:10 +03:00
module Source.Spec where
import Prologue
import Range
2016-09-13 18:35:10 +03:00
import Source
import SourceSpan
2016-09-13 18:35:10 +03:00
import Test.Hspec
import Test.Hspec.QuickCheck
2016-09-13 18:35:10 +03:00
spec :: Spec
spec = parallel $ do
describe "actualLineRanges" $ do
prop "produces 1 more range than there are newlines" $
\ s -> length (actualLineRanges (totalRange s) (fromList s)) `shouldBe` succ (length (filter (== '\n') s))
prop "produces exhaustive ranges" $
\ s -> let source = fromList s in
foldMap (`slice` source) (actualLineRanges (totalRange s) source) `shouldBe` source
2016-09-13 18:59:46 +03:00
describe "sourceSpanToRange" $ do
prop "computes the range covering a span in some source" $
\ s -> let source = fromList s
spans = zipWith (\ i Range {..} -> SourceSpan "" (SourcePos i 0) (SourcePos i (end - start))) [0..] ranges
ranges = actualLineRanges (totalRange source) source in
2016-09-13 20:14:02 +03:00
sourceSpanToRange source <$> spans `shouldBe` ranges