Pattern pretty printer prints syntactically correct code.

Include auto-generated test case that was previously broken.
This commit is contained in:
Max New 2013-12-29 20:19:21 -06:00
parent 24751a3d85
commit d003062586
2 changed files with 30 additions and 8 deletions

View file

@ -35,7 +35,7 @@ instance Pretty Pattern where
PData name ps ->
if isTuple name then
PP.parens . commaCat $ map pretty ps
else sep (PP.text name : map prettyParens ps)
else hsep (PP.text name : map prettyParens ps)
prettyParens pattern = parensIf needsThem (pretty pattern)
where
@ -43,4 +43,4 @@ prettyParens pattern = parensIf needsThem (pretty pattern)
case pattern of
PData name (_:_) | not (isTuple name) -> True
PAlias _ _ -> True
_ -> False
_ -> False

View file

@ -1,24 +1,46 @@
module Tests.Property where
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import Test.HUnit (assert)
import Test.QuickCheck
import SourceSyntax.Literal (Literal)
import SourceSyntax.PrettyPrint (Pretty, pretty)
import Parse.Helpers (IParser, iParse)
import Parse.Literal (literal)
import Parse.Pattern (expr)
import SourceSyntax.Literal as Lit
import SourceSyntax.Pattern as Pat
import SourceSyntax.PrettyPrint (Pretty, pretty)
import Parse.Helpers (IParser, iParse)
import Parse.Literal (literal)
import Parse.Pattern (expr)
import Tests.Property.Arbitrary
propertyTests :: Test
propertyTests =
testGroup "Parse/Print Agreement Tests"
[
testProperty "Literal test" $ prop_parse_print literal
testCase "Long Pattern test" $ assert (prop_parse_print expr longPat)
, testProperty "Literal test" $ prop_parse_print literal
, testProperty "Pattern test" $ prop_parse_print expr
]
where
-- This test was autogenerated from the Pattern test and should be
-- left in all its ugly glory.
longPat = Pat.PData "I" [ Pat.PLiteral (Lit.Chr '+')
, Pat.PRecord [
"q7yclkcm7k_ikstrczv_"
, "wQRv6gKsvvkjw4b5F"
,"c9'eFfhk9FTvsMnwF_D"
,"yqxhEkHvRFwZ"
,"o"
,"nbUlCn3y3NnkVoxhW"
,"iJ0MNy3KZ_lrs"
,"ug"
,"sHHsX"
,"mRKs9d"
,"o2KiCX5'ZRzHJfRi8" ]
, Pat.PVar "su'BrrbPUK6I33Eq" ]
prop_parse_print :: (Pretty a, Arbitrary a, Eq a) => IParser a -> a -> Bool
prop_parse_print p x =
either (const False) (== x) . parse_print p $ x