-
Notifications
You must be signed in to change notification settings - Fork 0
/
pretty-compact.hs
57 lines (47 loc) · 1.48 KB
/
pretty-compact.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE TypeSynonymInstances, TemplateHaskell #-}
import Test.Speculate hiding (string, char)
import Test.LeanCheck
import Data.Function (on)
import Data.List (isPrefixOf)
import Text.PrettyPrint.Compact
renderWidth :: Monoid a => Int -> Doc a -> String
renderWidth n = renderWith defaultOptions{optsPageWidth = n}
renders :: Monoid a => Doc a -> [String]
renders d = [renderWidth n d | n <- [1..8] ++ [10,20..80]]
instance Monoid a => Eq (Doc a) where
(==) = (==) `on` renders
instance Monoid a => Ord (Doc a) where
(<=) = and .: (zipWith isPrefixOf `on` renders)
where (.:) = (.) . (.)
instance Monoid a => Listable (Doc a) where
tiers = cons1 text
\/ cons2 (<>)
\/ cons2 (<+>)
\/ cons2 ($$)
\/ cons2 (</>)
\/ cons2 (<//>)
\/ cons2 (<$$>)
instance Monoid a => Show (Doc a) where
show = render
da :: Doc Any
da = undefined
instance Name (Doc a) where name _ = "d1"
main :: IO ()
main = speculate args
{ instances = [reifyInstances da]
, showConditions = False
, maxSize = 4
, maxTests = 360
, constants =
[ constant "text" $ text ->: da
, constant "char" $ char ->: da
, constant "flush" $ flush -:> da
, constant "hang" $ hang ->:> da
, constant "<>" $ (<>) -:> da
, constant "<+>" $ (<+>) -:> da
, constant "$$" $ ($$) -:> da
, constant "</>" $ (</>) -:> da
, constant "<//>" $ (<//>) -:> da
, constant "<$$>" $ (<$$>) -:> da
]
}