| 1 | module Main where |
|---|
| 2 | import Text.PrettyPrint.HughesPJ |
|---|
| 3 | |
|---|
| 4 | allTestsDoc userbug = text "foo" $$ nest 5 (listsep list) where |
|---|
| 5 | listsep = brackets. fsep . (if userbug then punctuate else rpunctuate) comma |
|---|
| 6 | list = (replicate 10 (fsep [nest 2 a, op, nest 2 b]))++ |
|---|
| 7 | (replicate 10 (text "Two")) |
|---|
| 8 | a = text "a" |
|---|
| 9 | op = text "~?=" |
|---|
| 10 | b = text "b" |
|---|
| 11 | rpunctuate sep [] = [] |
|---|
| 12 | rpunctuate sep (x:xs) = space <> x : (map (sep <>) xs) |
|---|
| 13 | main = do |
|---|
| 14 | putStrLn $ renderStyle (Style PageMode 44 1.8) $ nest 10 (allTestsDoc True) |
|---|
| 15 | putStrLn $ renderStyle (Style PageMode 44 1.8) $ nest 10 (allTestsDoc False) |
|---|
| 16 | |
|---|
| 17 | {- |
|---|
| 18 | Correct implementation: |
|---|
| 19 | foo [ a ~?= b |
|---|
| 20 | ,a ~?= b ,a ~?= b |
|---|
| 21 | ,a ~?= b ,a ~?= b |
|---|
| 22 | ,a ~?= b ,a ~?= b |
|---|
| 23 | ,a ~?= b ,a ~?= b |
|---|
| 24 | ,a ~?= b ,Two ,Two |
|---|
| 25 | ,Two ,Two ,Two ,Two |
|---|
| 26 | ,Two ,Two ,Two ,Two] |
|---|
| 27 | |
|---|
| 28 | User bug, HughesPJ, ghc HEAD, 24.06.2008: |
|---|
| 29 | |
|---|
| 30 | foo [a ~?= b, a ~?= b, |
|---|
| 31 | a ~?= b, a ~?= b, |
|---|
| 32 | a ~?= b, a ~?= b, |
|---|
| 33 | a ~?= b, a ~?= b, |
|---|
| 34 | a ~?= b, a ~?= b, Two, |
|---|
| 35 | Two, Two, Two, Two, Two, |
|---|
| 36 | Two, Two, Two, Two] |
|---|
| 37 | |
|---|
| 38 | User bug, HughesPJ 0608 with HughesPJ_2.patch (correct): |
|---|
| 39 | |
|---|
| 40 | foo [a ~?= b, a ~?= b, |
|---|
| 41 | a ~?= b, a ~?= b, |
|---|
| 42 | a ~?= b, a ~?= b, |
|---|
| 43 | a ~?= b, a ~?= b, |
|---|
| 44 | a ~?= b, a ~?= b, Two, |
|---|
| 45 | Two, Two, Two, Two, Two, |
|---|
| 46 | Two, Two, Two, Two] |
|---|
| 47 | -} |
|---|