From 34c61702de2633933ac5517ff32b14ec7c2c4039 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 20 Aug 2007 18:44:11 +0000 Subject: [PATCH] Rain: added a new test for testing the parsing of top-level declarations --- RainParse.hs | 3 +++ RainParseTest.hs | 28 +++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/RainParse.hs b/RainParse.hs index 3477ded..6145c74 100644 --- a/RainParse.hs +++ b/RainParse.hs @@ -270,6 +270,9 @@ statement <|> do { m <- md ; sSemiColon ; return $ A.Skip m} "statement" +topLevelDecl :: RainParser A.Structured +topLevelDecl = return $ A.Several emptyMeta [] --Dummy value, for now + rainSourceFile :: RainParser (A.Process, CompState) rainSourceFile = do whiteSpace diff --git a/RainParseTest.hs b/RainParseTest.hs index 1748454..9121897 100644 --- a/RainParseTest.hs +++ b/RainParseTest.hs @@ -25,6 +25,7 @@ import Test.HUnit import Metadata (Meta,emptyMeta) import Prelude hiding (fail) import TestUtil +import TreeUtil import CompState data ParseTest a = Show a => ExpPass (String, RP.RainParser a , (a -> Assertion)) | ExpFail (String, RP.RainParser a) @@ -178,6 +179,30 @@ testEach = A.OnlyP m $ makeSeq[(makeAssign (variable "c") (A.Literal m A.Int (A.IntLiteral m "1"))),(makeAssign (variable "c") (A.Literal m A.Int (A.IntLiteral m "2")))] ) ] +testTopLevelDecl :: [ParseTest A.Structured] +testTopLevelDecl = + [ + pass ("process noargs() {}", RP.topLevelDecl, + assertPatternMatch "testTopLevelDecl 0" $ tag3 A.Spec DontCare + (tag3 A.Specification DontCare "noargs" $ tag4 A.Proc DontCare A.PlainSpec ([] :: [A.Formal]) (tag2 A.OnlyP DontCare (tag1 A.Skip DontCare)) ) + (tag1 A.Main DontCare) + ) + , pass ("process onearg(int: x) {x = 0;}", RP.topLevelDecl, + assertPatternMatch "testTopLevelDecl 1" $ tag3 A.Spec DontCare + (tag3 A.Specification DontCare "onearg" $ tag4 A.Proc DontCare A.PlainSpec [tag3 A.Formal A.ValAbbrev A.Int (simpleName "x")] + (tag2 A.OnlyP DontCare $ tag2 A.Seq DontCare $ tag2 A.Several DontCare [tag2 A.OnlyP DontCare $ makeAssign (variable "x") (intLiteral 0)]) ) + (tag1 A.Main DontCare) + ) + , fail ("process", RP.topLevelDecl) + , fail ("process () {}", RP.topLevelDecl) + , fail ("process foo", RP.topLevelDecl) + , fail ("process foo ()", RP.topLevelDecl) + , fail ("process foo () {", RP.topLevelDecl) + , fail ("process foo ( {} )", RP.topLevelDecl) + , fail ("process foo (int: x)", RP.topLevelDecl) + , fail ("process foo (int x) {}", RP.topLevelDecl) + + ] --Returns the list of tests: @@ -190,7 +215,8 @@ tests = TestList parseTests testPar, parseTests testEach, parseTests testIf, - parseTests testAssign + parseTests testAssign, + parseTests testTopLevelDecl ] --TODO test: -- input (incl. ext input)