diff --git a/RainParseTest.hs b/RainParseTest.hs index dde0b84..12074ed 100644 --- a/RainParseTest.hs +++ b/RainParseTest.hs @@ -177,6 +177,28 @@ testPar = ,pass ("par { ; ; }",RP.statement, assertEqual "Par Skip Test" $ A.Par m A.PlainPar $ A.Several m [(A.OnlyP m (A.Skip m)),(A.OnlyP m (A.Skip m))] ) ] + +-- | Test innerBlock, particularly with declarations mixed with statements: +testBlock :: [ParseTest A.Structured] +testBlock = + [ + pass("{ a = b; }",RP.innerBlock,assertPatternMatch "testBlock 0" (tag2 A.Several DontCare [tag2 A.OnlyP DontCare $ makeSimpleAssignPattern "a" "b"]) ) + ,pass("{ a = b; b = c; }",RP.innerBlock,assertPatternMatch "testBlock 1" (tag2 A.Several DontCare + [tag2 A.OnlyP DontCare $ makeSimpleAssignPattern "a" "b",tag2 A.OnlyP DontCare $ makeSimpleAssignPattern "b" "c"]) ) + ,pass("{ uint8: x; a = b; }",RP.innerBlock,assertPatternMatch "testBlock 2" $ tag2 A.Several DontCare [tag3 A.Spec DontCare + (tag3 A.Specification DontCare (simpleNamePattern "x") $ tag2 A.Declaration DontCare A.Byte) $ tag2 A.Several DontCare + [tag2 A.OnlyP DontCare $ makeSimpleAssignPattern "a" "b"] + ]) + ,pass("{ uint8: x; a = b; b = c; }",RP.innerBlock,assertPatternMatch "testBlock 2" $ tag2 A.Several DontCare [tag3 A.Spec DontCare + (tag3 A.Specification DontCare (simpleNamePattern "x") $ tag2 A.Declaration DontCare A.Byte) $ tag2 A.Several DontCare + [tag2 A.OnlyP DontCare $ makeSimpleAssignPattern "a" "b",tag2 A.OnlyP DontCare $ makeSimpleAssignPattern "b" "c"] + ]) + ,pass("{ b = c; uint8: x; a = b; }",RP.innerBlock,assertPatternMatch "testBlock 2" $ tag2 A.Several DontCare [tag2 A.OnlyP DontCare $ makeSimpleAssignPattern "b" "c", + tag3 A.Spec DontCare + (tag3 A.Specification DontCare (simpleNamePattern "x") $ tag2 A.Declaration DontCare A.Byte) $ tag2 A.Several DontCare + [tag2 A.OnlyP DontCare $ makeSimpleAssignPattern "a" "b"] + ]) + ] testEach :: [ParseTest A.Process] testEach = @@ -295,6 +317,7 @@ tests = TestList parseTests testWhile, parseTests testSeq, parseTests testPar, + parseTests testBlock, parseTests testEach, parseTests testIf, parseTests testAssign, diff --git a/TestUtil.hs b/TestUtil.hs index a39eb23..af3045a 100644 --- a/TestUtil.hs +++ b/TestUtil.hs @@ -70,6 +70,9 @@ makeNamesWR (x,y) = (map variable x,map variable y) makeSimpleAssign :: String -> String -> A.Process makeSimpleAssign dest src = A.Assign m [A.Variable m $ simpleName dest] (A.ExpressionList m [exprVariable src]) +makeSimpleAssignPattern :: String -> String -> Pattern +makeSimpleAssignPattern lhs rhs = stopCaringPattern m $ mkPattern $ makeSimpleAssign lhs rhs + makeSeq :: [A.Process] -> A.Process makeSeq procList = A.Seq m $ A.Several m (map (\x -> A.OnlyP m x) procList)