Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 59 lines (50 sloc) 1.687 kB
ad7796a @hiratara more samples
authored
1 {-# LANGUAGE TemplateHaskell #-}
2 module QC where
3
4e9612f @hiratara more samples
authored
4 import Test.QuickCheck
ad7796a @hiratara more samples
authored
5 import Test.QuickCheck.All
4e9612f @hiratara more samples
authored
6 import Prettify2
7 import Control.Monad (liftM, liftM2)
ad7796a @hiratara more samples
authored
8 import Data.List (intersperse)
4e9612f @hiratara more samples
authored
9
10 -- instance Arbitrary Doc where
11 -- arbitrary = do
12 -- n <- choose (1, 6) :: Gen Int
13 -- case n of
14 -- 1 -> return Empty
15 -- 2 -> do x <- arbitrary
16 -- return (Char x)
17 -- 3 -> do x <-arbitrary
18 -- return (Text x)
19 -- 4 -> return Line
20 -- 5 -> do x <- arbitrary
21 -- y <- arbitrary
22 -- return (Concat x y)
23 -- 6 -> do x <- arbitrary
24 -- y <- arbitrary
25 -- return (Union x y)
26 -- _ -> error ""
27
28 instance Arbitrary Doc where
29 arbitrary = oneof [
30 return Empty,
31 liftM Char arbitrary,
32 liftM Text arbitrary,
33 return Line,
34 liftM2 Concat arbitrary arbitrary,
35 liftM2 Union arbitrary arbitrary
36 ]
e143951 @hiratara more samples
authored
37
38 prop_empty_id x = empty <> x == x
39 &&
40 x <> empty == x
41
42 prop_char c = char c == Char c
43 prop_text s = text s == if null s then Empty else Text s
44 prop_line = line == Line
45 prop_double d = double d == text (show d)
46
ad7796a @hiratara more samples
authored
47 prop_hcat xs = hcat xs == glue xs
48 where glue [] = empty
49 glue (d:ds) = d <> glue ds
50
51 prop_punctuate s xs = punctuate s xs == combine (intersperse s xs)
52 where combine [] = []
53 combine [x] = [x]
54 combine (x:Empty:ys) = x : combine ys
55 combine (Empty:y:ys) = y : combine ys
56 combine (x:y:ys) = (Concat x y) : combine ys
57
58 runTests = $quickCheckAll
Something went wrong with that request. Please try again.