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