Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 258e254

Browse files
committed
Run the sourceLineRanges test with QuickCheck.
1 parent 99df4b3 commit 258e254

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

semantic.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,11 @@ test-suite test
397397
, tasty-hedgehog ^>= 1.0.0.1
398398
, tasty-hspec ^>= 1.1.5.1
399399
, tasty-hunit ^>= 0.10.0.2
400+
, tasty-quickcheck ^>= 0.10
400401
, HUnit ^>= 1.6.0.0
401402
, leancheck >= 0.8 && <1
402403
, temporary ^>= 1.3
404+
, QuickCheck ^>= 2.13
403405
if flag(release)
404406
ghc-options: -dynamic
405407

test/Data/Source/Spec.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS_GHC -Wno-orphans #-}
12
module Data.Source.Spec (spec, testTree) where
23

34
import Data.Range
@@ -14,6 +15,7 @@ import qualified Hedgehog.Range
1415
import Hedgehog hiding (Range)
1516
import qualified Test.Tasty as Tasty
1617
import Test.Tasty.Hedgehog (testProperty)
18+
import qualified Test.Tasty.QuickCheck as QC
1719

1820
prop :: HasCallStack => String -> (Source -> PropertyT IO ()) -> Tasty.TestTree
1921
prop desc f
@@ -25,8 +27,8 @@ prop desc f
2527
testTree :: Tasty.TestTree
2628
testTree = 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

9294
insetRange :: Range -> Range
9395
insetRange 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

Comments
 (0)