1+ {-# OPTIONS_GHC -Wno-orphans #-}
12module Data.Source.Spec (spec , testTree ) where
23
34import Data.Range
@@ -14,6 +15,7 @@ import qualified Hedgehog.Range
1415import Hedgehog hiding (Range )
1516import qualified Test.Tasty as Tasty
1617import Test.Tasty.Hedgehog (testProperty )
18+ import qualified Test.Tasty.QuickCheck as QC
1719
1820prop :: HasCallStack => String -> (Source -> PropertyT IO () ) -> Tasty. TestTree
1921prop desc f
@@ -25,8 +27,8 @@ prop desc f
2527testTree :: Tasty. TestTree
2628testTree = Tasty. testGroup " Data.Source"
2729 [ Tasty. testGroup " sourceLineRanges"
28- [ prop " produces 1 more range than there are newlines" $
29- \ source -> length (sourceLineRanges source) === succ (Text. count " \n " (toText source))
30+ [ QC. testProperty " produces 1 more range than there are newlines" $
31+ \ source -> length (sourceLineRanges source) QC. === succ (Text. count " \n " (toText source))
3032
3133 , prop " produces exhaustive ranges" $
3234 \ source -> foldMap (`slice` source) (sourceLineRanges source) === source
@@ -91,3 +93,8 @@ insetSpan sourceSpan = sourceSpan { spanStart = (spanStart sourceSpan) { posColu
9193
9294insetRange :: Range -> Range
9395insetRange Range {.. } = Range (succ start) (pred end)
96+
97+
98+ instance QC. Arbitrary Source where
99+ arbitrary = fromText . Text. pack <$> QC. listOf (QC. oneof [ pure ' \r ' , pure ' \n ' , QC. arbitraryUnicodeChar ])
100+ shrink src = fromText . Text. pack <$> QC. shrinkList QC. shrinkNothing (Text. unpack (toText src))
0 commit comments