@@ -1,4 +1,3 @@
1−{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
3{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
@@ -9,7 +8,6 @@ import Test.Hspec
9import Test.QuickCheck
8import Test.QuickCheck
10import Text.Inflections
9import Text.Inflections
11import Text.Megaparsec
10import Text.Megaparsec
14import qualified Data.List.NonEmpty as NE
12import qualified Data.List.NonEmpty as NE
15import qualified Data.Set as S
13import qualified Data.Set as S
@@ -18,35 +16,21 @@ import qualified Data.Set as S
18import Control.Applicative
16import Control.Applicative
21−instance Arbitrary Text where
22− arbitrary = pack <$> (arbitrary :: Gen String)
24−arbitraryParseErrorBundle :: Gen (ParseErrorBundle Text Void)
25−arbitraryParseErrorBundle = ParseErrorBundle <$> nonEmptyParseErrors <*> arbitraryPosState
27− posArbitrary = mkPos <$> ((+1) . abs <$> arbitrary)
28− nonEmptyParseErrors :: Gen (NE.NonEmpty (ParseError Text Void))
29− nonEmptyParseErrors = NE.fromList <$> listOf1 arbitraryParseError
19+arbitraryParseError :: Gen (ParseError Char Void)
30− arbitrarySourcePos :: Gen SourcePos
31− arbitrarySourcePos = SourcePos <$> arbitrary <*> posArbitrary <*> posArbitrary
32− arbitraryPosState :: Gen (PosState Text)
37− <*> arbitrarySourcePos
41−arbitraryParseError :: Gen (ParseError Text Void)
42arbitraryParseError = oneof [trivialError, fancyError]
20arbitraryParseError = oneof [trivialError, fancyError]
44− trivialError = TrivialError <$> arbitrary <*> maybeErrorItem <*> setErrorItem
22+ trivialError = TrivialError <$> nonEmptyArbitrary <*> maybeErrorItem <*> setErrorItem
45− fancyError = FancyError <$> arbitrary <*> setErrorFancy
23+ fancyError = FancyError <$> nonEmptyArbitrary <*> setErrorFancy
24+ nonEmptyArbitrary = NE.fromList <$> listOf1 arbitrarySourcePos
46 setErrorFancy = S.fromList <$> listOf arbitraryErrorFancy
25 setErrorFancy = S.fromList <$> listOf arbitraryErrorFancy
47 maybeErrorItem = oneof [ Just <$> arbitraryErrorItem, return Nothing]
26 maybeErrorItem = oneof [ Just <$> arbitraryErrorItem, return Nothing]
48 setErrorItem = S.fromList <$> listOf arbitraryErrorItem
27 setErrorItem = S.fromList <$> listOf arbitraryErrorItem
29+arbitrarySourcePos :: Gen SourcePos
30+arbitrarySourcePos = SourcePos <$> arbitrary <*> posArbitrary <*> posArbitrary
32+ posArbitrary = mkPos <$> ((+1) . abs <$> arbitrary)
50arbitraryErrorFancy :: Gen (ErrorFancy e)
34arbitraryErrorFancy :: Gen (ErrorFancy e)
51arbitraryErrorFancy = oneof [ ErrorFail <$> arbitrary ]
35arbitraryErrorFancy = oneof [ ErrorFail <$> arbitrary ]
@@ -88,7 +72,7 @@ spec = do
88 describe "betterThrow" $ do
72 describe "betterThrow" $ do
89 context "when given a parse error" $
73 context "when given a parse error" $
90 it "throws the correct exception" $
74 it "throws the correct exception" $
91− property $ forAll arbitraryParseErrorBundle $ \err ->
75+ property $ forAll arbitraryParseError $ \err ->
92 betterThrow (Left err) `shouldThrow`
76 betterThrow (Left err) `shouldThrow`
93 (== InflectionParsingFailed err)
77 (== InflectionParsingFailed err)