module Main where
import Text.PrettyPrint.HughesPJ

allTestsDoc userbug = text "foo" $$ nest 5 (listsep list) where
    listsep = brackets. fsep . (if userbug then punctuate else rpunctuate) comma
    list =   (replicate 10 (fsep [nest 2 a, op, nest 2 b]))++
             (replicate 10 (text "Two"))
    a = text "a"
    op = text "~?="
    b = text "b"
    rpunctuate sep [] = []
    rpunctuate sep (x:xs) = space <> x : (map (sep <>) xs)
main = do
    putStrLn $ renderStyle (Style PageMode 44 1.8) $ nest 10 (allTestsDoc True)
    putStrLn $ renderStyle (Style PageMode 44 1.8) $ nest 10 (allTestsDoc False)

{-
Correct implementation:
          foo  [ a ~?= b
                ,a ~?= b ,a ~?= b
                ,a ~?= b ,a ~?= b
                ,a ~?= b ,a ~?= b
                ,a ~?= b ,a ~?= b
                ,a ~?= b ,Two ,Two
                ,Two ,Two ,Two ,Two
                ,Two ,Two ,Two ,Two]
                
User bug, HughesPJ, ghc HEAD, 24.06.2008:

          foo  [a ~?= b, a ~?= b,
              a ~?= b, a ~?= b,
            a ~?= b, a ~?= b,
          a ~?= b, a ~?= b,
        a ~?= b, a ~?= b, Two,
    Two, Two, Two, Two, Two,
    Two, Two, Two, Two]

User bug, HughesPJ 0608 with HughesPJ_2.patch (correct):

          foo  [a ~?= b, a ~?= b,
                a ~?= b, a ~?= b,
                a ~?= b, a ~?= b,
                a ~?= b, a ~?= b,
                a ~?= b, a ~?= b, Two,
              Two, Two, Two, Two, Two,
              Two, Two, Two, Two]
-}
