on master help sign in
Pattern pretty printer prints syntactically correct code.

Include auto-generated test case that was previously broken.

commitd0030625868662bec22077f36a49cbff9098ec7e authorMax New <maxsnew@gmail.com> dateSun 29 Dec 2013, 20:19 (13 years ago) parent24751a3
2 files changed+30−8
compiler/SourceSyntax/Pattern.hs+2−2 tests/Tests/Property.hs+28−6
compiler/SourceSyntax/Pattern.hs+2−2
@@ -35,7 +35,7 @@ instance Pretty Pattern where
3535 PData name ps ->
3636 if isTuple name then
3737 PP.parens . commaCat $ map pretty ps
38− else sep (PP.text name : map prettyParens ps)
38+ else hsep (PP.text name : map prettyParens ps)
3939
4040prettyParens pattern = parensIf needsThem (pretty pattern)
4141 where
@@ -43,4 +43,4 @@ prettyParens pattern = parensIf needsThem (pretty pattern)
4343 case pattern of
4444 PData name (_:_) | not (isTuple name) -> True
4545 PAlias _ _ -> True
46− _ -> False
46+ _ -> False
tests/Tests/Property.hs+28−6
@@ -1,24 +1,46 @@
11module Tests.Property where
22
33import Test.Framework
4+import Test.Framework.Providers.HUnit
45import Test.Framework.Providers.QuickCheck2
6+import Test.HUnit (assert)
57import Test.QuickCheck
68
7−import SourceSyntax.Literal (Literal)
8−import SourceSyntax.PrettyPrint (Pretty, pretty)
9−import Parse.Helpers (IParser, iParse)
10−import Parse.Literal (literal)
11−import Parse.Pattern (expr)
9+import SourceSyntax.Literal as Lit
10+import SourceSyntax.Pattern as Pat
11+import SourceSyntax.PrettyPrint (Pretty, pretty)
12+import Parse.Helpers (IParser, iParse)
13+import Parse.Literal (literal)
14+import Parse.Pattern (expr)
1215import Tests.Property.Arbitrary
1316
1417propertyTests :: Test
1518propertyTests =
1619 testGroup "Parse/Print Agreement Tests"
1720 [
18− testProperty "Literal test" $ prop_parse_print literal
21+ testCase "Long Pattern test" $ assert (prop_parse_print expr longPat)
22+ , testProperty "Literal test" $ prop_parse_print literal
1923 , testProperty "Pattern test" $ prop_parse_print expr
2024 ]
2125
26+ where
27+ -- This test was autogenerated from the Pattern test and should be
28+ -- left in all its ugly glory.
29+ longPat = Pat.PData "I" [ Pat.PLiteral (Lit.Chr '+')
30+ , Pat.PRecord [
31+ "q7yclkcm7k_ikstrczv_"
32+ , "wQRv6gKsvvkjw4b5F"
33+ ,"c9'eFfhk9FTvsMnwF_D"
34+ ,"yqxhEkHvRFwZ"
35+ ,"o"
36+ ,"nbUlCn3y3NnkVoxhW"
37+ ,"iJ0MNy3KZ_lrs"
38+ ,"ug"
39+ ,"sHHsX"
40+ ,"mRKs9d"
41+ ,"o2KiCX5'ZRzHJfRi8" ]
42+ , Pat.PVar "su'BrrbPUK6I33Eq" ]
43+
2244prop_parse_print :: (Pretty a, Arbitrary a, Eq a) => IParser a -> a -> Bool
2345prop_parse_print p x =
2446 either (const False) (== x) . parse_print p $ x