on master help sign in
Switch from QuickCheck 1 to QuickCheck 2
ce01136Bryan O'Sullivan
tests/Makefile+1−1
@@ -5,7 +5,7 @@ ghc-base-flags := -funbox-strict-fields -package criterion \
5 -package bytestring -ignore-package text \
5 -package bytestring -ignore-package text \
6 -fno-ignore-asserts
6 -fno-ignore-asserts
7ghc-test-flags := -package QuickCheck -package test-framework \
7ghc-test-flags := -package QuickCheck -package test-framework \
8− -package test-framework-quickcheck -package test-framework-hunit \
8+ -package test-framework-quickcheck2 -package test-framework-hunit \
9 -package HUnit
9 -package HUnit
10ghc-base-flags += -Wall -fno-warn-orphans -fno-warn-missing-signatures
10ghc-base-flags += -Wall -fno-warn-orphans -fno-warn-missing-signatures
11ghc-flags := $(ghc-base-flags) -i../dist/build -package-name text-$(version)
11ghc-flags := $(ghc-base-flags) -i../dist/build -package-name text-$(version)
tests/Properties.hs+2−2
@@ -2,7 +2,7 @@
2 ScopedTypeVariables, TypeSynonymInstances #-}
2 ScopedTypeVariables, TypeSynonymInstances #-}
3{-# OPTIONS_GHC -fno-enable-rewrite-rules #-}
3{-# OPTIONS_GHC -fno-enable-rewrite-rules #-}
4
4
5−import Test.QuickCheck hiding (evaluate)
5+import Test.QuickCheck
6import Text.Show.Functions ()
6import Text.Show.Functions ()
7
7
8import qualified Data.Bits as Bits (shiftL, shiftR)
8import qualified Data.Bits as Bits (shiftL, shiftR)
@@ -27,7 +27,7 @@ import qualified Data.List as L
27import Prelude hiding (replicate)
27import Prelude hiding (replicate)
28import System.IO.Unsafe (unsafePerformIO)
28import System.IO.Unsafe (unsafePerformIO)
29import Test.Framework (defaultMain, testGroup)
29import Test.Framework (defaultMain, testGroup)
30−import Test.Framework.Providers.QuickCheck (testProperty)
30+import Test.Framework.Providers.QuickCheck2 (testProperty)
31import Data.Text.Search (indices)
31import Data.Text.Search (indices)
32import qualified Data.Text.Lazy.Search as S (indices)
32import qualified Data.Text.Lazy.Search as S (indices)
33import qualified SlowFunctions as Slow
33import qualified SlowFunctions as Slow
tests/QuickCheckUtils.hs−16
@@ -17,7 +17,6 @@ instance Random Int64 where
17
17
18instance Arbitrary Int64 where
18instance Arbitrary Int64 where
19 arbitrary = choose (minBound,maxBound)
19 arbitrary = choose (minBound,maxBound)
20− coarbitrary c = variant (fromEnum c `rem` 4)
21
20
22instance Random Word8 where
21instance Random Word8 where
23 randomR = integralRandomR
22 randomR = integralRandomR
@@ -25,11 +24,9 @@ instance Random Word8 where
25
24
26instance Arbitrary Word8 where
25instance Arbitrary Word8 where
27 arbitrary = choose (minBound,maxBound)
26 arbitrary = choose (minBound,maxBound)
28− coarbitrary c = variant (fromEnum c `rem` 4)
29
27
30instance Arbitrary B.ByteString where
28instance Arbitrary B.ByteString where
31 arbitrary = B.pack `fmap` arbitrary
29 arbitrary = B.pack `fmap` arbitrary
32− coarbitrary s = coarbitrary (B.unpack s)
33
30
34instance Random Word16 where
31instance Random Word16 where
35 randomR = integralRandomR
32 randomR = integralRandomR
@@ -37,7 +34,6 @@ instance Random Word16 where
37
34
38instance Arbitrary Word16 where
35instance Arbitrary Word16 where
39 arbitrary = choose (minBound,maxBound)
36 arbitrary = choose (minBound,maxBound)
40− coarbitrary c = variant (fromEnum c `rem` 4)
41
37
42instance Random Word32 where
38instance Random Word32 where
43 randomR = integralRandomR
39 randomR = integralRandomR
@@ -45,19 +41,12 @@ instance Random Word32 where
45
41
46instance Arbitrary Word32 where
42instance Arbitrary Word32 where
47 arbitrary = choose (minBound,maxBound)
43 arbitrary = choose (minBound,maxBound)
48− coarbitrary c = variant (fromEnum c `rem` 4)
49−
50−instance Arbitrary Char where
51− arbitrary = oneof [choose ('\0','\55295'), choose ('\57344','\1114111')]
52− coarbitrary c = variant (fromEnum c `rem` 4)
53
44
54instance Arbitrary T.Text where
45instance Arbitrary T.Text where
55 arbitrary = T.pack `fmap` arbitrary
46 arbitrary = T.pack `fmap` arbitrary
56− coarbitrary s = coarbitrary (T.unpack s)
57
47
58instance Arbitrary TL.Text where
48instance Arbitrary TL.Text where
59 arbitrary = TL.pack `fmap` arbitrary
49 arbitrary = TL.pack `fmap` arbitrary
60− coarbitrary s = coarbitrary (TL.unpack s)
61
50
62newtype NotEmpty a = NotEmpty { notEmpty :: a }
51newtype NotEmpty a = NotEmpty { notEmpty :: a }
63 deriving (Eq, Ord, Show)
52 deriving (Eq, Ord, Show)
@@ -67,19 +56,15 @@ instance Functor NotEmpty where
67
56
68instance Arbitrary a => Arbitrary (NotEmpty [a]) where
57instance Arbitrary a => Arbitrary (NotEmpty [a]) where
69 arbitrary = sized (\n -> NotEmpty `fmap` (choose (1,n+1) >>= vector))
58 arbitrary = sized (\n -> NotEmpty `fmap` (choose (1,n+1) >>= vector))
70− coarbitrary = coarbitrary . notEmpty
71
59
72instance Arbitrary (NotEmpty T.Text) where
60instance Arbitrary (NotEmpty T.Text) where
73 arbitrary = (fmap T.pack) `fmap` arbitrary
61 arbitrary = (fmap T.pack) `fmap` arbitrary
74− coarbitrary = coarbitrary . notEmpty
75
62
76instance Arbitrary (NotEmpty TL.Text) where
63instance Arbitrary (NotEmpty TL.Text) where
77 arbitrary = (fmap TL.pack) `fmap` arbitrary
64 arbitrary = (fmap TL.pack) `fmap` arbitrary
78− coarbitrary = coarbitrary . notEmpty
79
65
80instance Arbitrary (NotEmpty B.ByteString) where
66instance Arbitrary (NotEmpty B.ByteString) where
81 arbitrary = (fmap B.pack) `fmap` arbitrary
67 arbitrary = (fmap B.pack) `fmap` arbitrary
82− coarbitrary = coarbitrary . notEmpty
83
68
84data Small = S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7
69data Small = S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7
85 | S8 | S9 | S10 | S11 | S12 | S13 | S14 | S15
70 | S8 | S9 | S10 | S11 | S12 | S13 | S14 | S15
@@ -120,7 +105,6 @@ instance Random Small where
120
105
121instance Arbitrary Small where
106instance Arbitrary Small where
122 arbitrary = choose (minBound,maxBound)
107 arbitrary = choose (minBound,maxBound)
123− coarbitrary c = variant (fromEnum c `rem` 4)
124
108
125integralRandomR :: (Integral a, RandomGen g) => (a,a) -> g -> (a,g)
109integralRandomR :: (Integral a, RandomGen g) => (a,a) -> g -> (a,g)
126integralRandomR (a,b) g = case randomR (fromIntegral a :: Integer,
110integralRandomR (a,b) g = case randomR (fromIntegral a :: Integer,