git.iko.soy/typeable/attoparsec
on master help sign in
Merge some shared test code into a common module
commitc045c10a9b639018913d4625fa0d22243f68df6e authorBryan O'Sullivan <bos@serpentine.com> dateWed 7 May 2014, 14:55 (12 years ago) parent99c33d5
4 files changed+29−34
attoparsec.cabal+1 tests/QC/ByteString.hs+1−17 tests/QC/Common.hs+25 tests/QC/Text.hs+2−17
attoparsec.cabal+1
@@ -73,6 +73,7 @@ test-suite tests
7373 hs-source-dirs: tests
7474 main-is: QC.hs
7575 other-modules: QC.ByteString
76+ QC.Common
7677 QC.Text
7778
7879 ghc-options:
tests/QC/ByteString.hs+1−17
@@ -1,5 +1,4 @@
11{-# LANGUAGE BangPatterns, OverloadedStrings #-}
2−{-# OPTIONS_GHC -fno-warn-orphans #-}
32module QC.ByteString (tests) where
43
54import Control.Applicative ((<$>), (<*>))
@@ -7,6 +6,7 @@ import Data.Char (chr, ord)
76import Data.Int (Int64)
87import Data.Word (Word8)
98import Prelude hiding (take, takeWhile)
9+import QC.Common ()
1010import Test.Framework (Test)
1111import Test.Framework.Providers.QuickCheck2 (testProperty)
1212import Test.QuickCheck
@@ -17,22 +17,6 @@ import qualified Data.ByteString as B
1717import qualified Data.ByteString.Lazy as L
1818import qualified Data.ByteString.Lazy.Char8 as L8
1919
20−instance Arbitrary B.ByteString where
21− arbitrary = B.pack <$> arbitrary
22−
23−instance Arbitrary L.ByteString where
24− arbitrary = sized $ \n -> resize (round (sqrt (toEnum n :: Double)))
25− ((L.fromChunks . map (B.pack . nonEmpty)) <$> arbitrary)
26− where nonEmpty (NonEmpty a) = a
27−
28−-- Naming.
29−
30−{-
31−label (NonEmpty s) = case parse (anyWord8 <?> s) B.empty of
32− (_, Left err) -> s `isInfixOf` err
33− _ -> False
34−-}
35−
3620-- Basic byte-level combinators.
3721
3822maybeP :: PL.Parser r -> L.ByteString -> Maybe r
tests/QC/Common.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
2+module QC.Common () where
3+
4+import Control.Applicative ((<$>))
5+import Test.QuickCheck
6+import qualified Data.ByteString as B
7+import qualified Data.ByteString.Lazy as BL
8+import qualified Data.Text as T
9+import qualified Data.Text.Lazy as TL
10+
11+instance Arbitrary B.ByteString where
12+ arbitrary = B.pack <$> arbitrary
13+
14+instance Arbitrary BL.ByteString where
15+ arbitrary = sized $ \n -> resize (round (sqrt (toEnum n :: Double)))
16+ ((BL.fromChunks . map (B.pack . nonEmpty)) <$> arbitrary)
17+ where nonEmpty (NonEmpty a) = a
18+
19+instance Arbitrary T.Text where
20+ arbitrary = T.pack <$> arbitrary
21+
22+instance Arbitrary TL.Text where
23+ arbitrary = sized $ \n -> resize (round (sqrt (toEnum n :: Double)))
24+ ((TL.fromChunks . map (T.pack . nonEmpty)) <$> arbitrary)
25+ where nonEmpty (NonEmpty a) = a
tests/QC/Text.hs+2−17
@@ -1,11 +1,12 @@
11{-# LANGUAGE BangPatterns, OverloadedStrings #-}
2−{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-warnings-deprecations #-}
2+{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
33module QC.Text (tests) where
44
55import Control.Applicative ((<$>), (<*>))
66import Data.Attoparsec.Text (Parser)
77import Data.Int (Int64)
88import Prelude hiding (take, takeWhile)
9+import QC.Common ()
910import Test.Framework (Test)
1011import Test.Framework.Providers.QuickCheck2 (testProperty)
1112import Test.QuickCheck
@@ -15,22 +16,6 @@ import qualified Data.Char as Char
1516import qualified Data.Text as T
1617import qualified Data.Text.Lazy as L
1718
18−instance Arbitrary T.Text where
19− arbitrary = T.pack <$> arbitrary
20−
21−instance Arbitrary L.Text where
22− arbitrary = sized $ \n -> resize (round (sqrt (toEnum n :: Double)))
23− ((L.fromChunks . map (T.pack . nonEmpty)) <$> arbitrary)
24− where nonEmpty (NonEmpty a) = a
25−
26−-- Naming.
27−
28−{-
29−label (NonEmpty s) = case parse (anyChar <?> s) T.empty of
30− (_, Left err) -> s `isInfixOf` err
31− _ -> False
32−-}
33−
3419-- Basic byte-level combinators.
3520
3621maybeP :: Parser r -> L.Text -> Maybe r