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

Commit 735340b

Browse files
authored
Merge pull request #216 from github/the-point-of-no-carriage-return
Source generators produce multiline strings
2 parents 368fc7b + f7547ce commit 735340b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

test/Data/Source/Spec.hs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Test.Hspec
99

1010
import qualified Generators as Gen
1111
import qualified Hedgehog.Gen as Gen
12-
import Hedgehog ((===))
12+
import Hedgehog ((===), label)
1313
import qualified Hedgehog.Range
1414
import Hedgehog hiding (Range)
1515
import qualified Test.Tasty as Tasty
@@ -25,11 +25,15 @@ prop desc f
2525
testTree :: Tasty.TestTree
2626
testTree = Tasty.testGroup "Data.Source"
2727
[ 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-
31-
, prop "produces exhaustive ranges" $
32-
\ source -> foldMap (`slice` source) (sourceLineRanges source) === source
28+
[ testProperty "produces 1 more range than there are newlines" $ property $ do
29+
source <- forAll (Gen.source (Hedgehog.Range.linear 0 100))
30+
label (summarize source)
31+
(length (sourceLineRanges source) === length (Text.splitOn "\r\n" (toText source) >>= Text.splitOn "\r" >>= Text.splitOn "\n"))
32+
33+
, testProperty "produces exhaustive ranges" $ property $ do
34+
source <- forAll (Gen.source (Hedgehog.Range.linear 0 100))
35+
label (summarize source)
36+
foldMap (`slice` source) (sourceLineRanges source) === source
3337
]
3438

3539
, Tasty.testGroup "spanToRange"
@@ -68,6 +72,10 @@ testTree = Tasty.testGroup "Data.Source"
6872
]
6973

7074
]
75+
where summarize src = case sourceLines src of
76+
[] -> "empty"
77+
[x] -> if nullSource x then "empty" else "single-line"
78+
_ -> "multiple lines"
7179

7280
spec :: Spec
7381
spec = do

test/Generators.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import qualified Data.Source
99
import Data.Functor.Identity
1010

1111
source :: (GenBase m ~ Identity, MonadGen m) => Hedgehog.Range Int -> m Data.Source.Source
12-
source r = Data.Source.fromUTF8 <$> Gen.utf8 r Gen.unicode
12+
source r = Data.Source.fromUTF8 <$> Gen.utf8 r (Gen.frequency [ (1, pure '\r'), (1, pure '\n'), (20, Gen.unicode) ])

0 commit comments

Comments
 (0)