git.iko.soy/typeable/attoparsec
on master help sign in
Write implementations of shrink for BP types
01a30cdBryan O'Sullivan
tests/QC/Buffer.hs+11−3
@@ -3,7 +3,8 @@
3
3
4module QC.Buffer (tests) where
4module QC.Buffer (tests) where
5
5
6+import Control.Applicative ((<$>))
6−import Data.Monoid (mconcat)
7+import Data.Monoid (Monoid(mconcat))
7import QC.Common ()
8import QC.Common ()
8import Test.Framework (Test)
9import Test.Framework (Test)
9import Test.Framework.Providers.QuickCheck2 (testProperty)
10import Test.Framework.Providers.QuickCheck2 (testProperty)
@@ -24,12 +25,19 @@ type BPT = BP T.Text BT.Buffer
24instance Arbitrary BPB where
25instance Arbitrary BPB where
25 arbitrary = do
26 arbitrary = do
26 bss <- arbitrary
27 bss <- arbitrary
28+ return $! toBP BB.buffer bss
29+
27− return $! BP bss (mconcat bss) (mconcat (map BB.buffer bss))
30+ shrink (BP bss _ _) = toBP BB.buffer <$> shrink bss
28
31
29instance Arbitrary BPT where
32instance Arbitrary BPT where
30 arbitrary = do
33 arbitrary = do
31 bss <- arbitrary
34 bss <- arbitrary
35+ return $! toBP BT.buffer bss
36+
37+ shrink (BP bss _ _) = toBP BT.buffer <$> shrink bss
38+
39+toBP :: (Monoid a, Monoid b) => (a -> b) -> [a] -> BP a b
32− return $! BP bss (mconcat bss) (mconcat (map BT.buffer bss))
40+toBP buf bss = BP bss (mconcat bss) (mconcat (map buf bss))
33
41
34b_unbuffer :: BPB -> Property
42b_unbuffer :: BPB -> Property
35b_unbuffer (BP _ts t buf) = t === BB.unbuffer buf
43b_unbuffer (BP _ts t buf) = t === BB.unbuffer buf