From 5ee2303dc7156f1af2a573e7d957f35287490242 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 16 Aug 2007 12:17:49 +0000 Subject: [PATCH] Moved some functions into TestUtil from RainParseTest --- RainParseTest.hs | 36 ------------------------------------ TestUtil.hs | 11 +++++++++++ 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/RainParseTest.hs b/RainParseTest.hs index 95ee079..7365039 100644 --- a/RainParseTest.hs +++ b/RainParseTest.hs @@ -51,42 +51,6 @@ makeIf list = A.If m $ A.Several m (map makeChoice list) dyExp :: A.DyadicOp -> A.Variable -> A.Variable -> A.Expression dyExp op v0 v1 = A.Dyadic m op (A.ExprVariable m v0) (A.ExprVariable m v1) -makeAssign :: A.Variable -> A.Expression -> A.Process -makeAssign v e = A.Assign m [v] $ A.ExpressionList m [e] - - -makeLiteralString :: String -> A.Expression -makeLiteralString str = A.Literal m (A.Array [A.Dimension (length str)] A.Byte) (A.ArrayLiteral m (map makeLiteralChar str)) - where - makeLiteralChar :: Char -> A.ArrayElem - makeLiteralChar c = A.ArrayElemExpr $ A.Literal m A.Byte (A.ByteLiteral m [c] {-(show (fromEnum c))-}) - -data EachType = Seq | Par - -makeEach :: EachType -> String -> A.Type -> A.Expression -> A.Process -> A.Process -makeEach ty loopVar listType listVar body - = case listSpec of - Nothing -> A.Seq m builtRep - Just lspec -> A.Seq m $ A.Spec m lspec builtRep - where --- Possibly put list into temporary: - (actualListVar,listSpec) = calcListVar listVar listType - -- Produce the loop using a replicator: - rep = A.For m (simpleName (loopVar ++ ".index")) (A.Literal m A.Int (A.IntLiteral m "0")) (A.SizeExpr m (A.ExprVariable m actualListVar)) - -- Add a specification for abbreviating the array item: - spec = A.Specification m (simpleName loopVar) - (A.Is m A.Abbrev A.Byte (A.SubscriptedVariable m (A.Subscript m (A.ExprVariable m (variable (loopVar ++ ".index")))) actualListVar) ) - --TODO workout where the SEQ/PAR distinction goes - builtRep = A.Rep m rep (A.Spec m spec (A.OnlyP m body)) - calcListVar :: A.Expression -> A.Type -> (A.Variable,Maybe A.Specification) - calcListVar (A.ExprVariable _ v) _ = (v,Nothing) - --HACK! need proper nonce - calcListVar v ty = (variable var,Just $ A.Specification m (simpleName var) (A.IsExpr m A.ValAbbrev ty v)) - where var = "listvar" - - - - testIf :: [ParseTest A.Process] testIf = [ diff --git a/TestUtil.hs b/TestUtil.hs index 3ff9c2e..3db602c 100644 --- a/TestUtil.hs +++ b/TestUtil.hs @@ -37,6 +37,17 @@ makePar procList = A.Par m A.PlainPar $ A.Several m (map (\x -> A.OnlyP m x) pro makeRepPar :: A.Process -> A.Process makeRepPar proc = A.Par m A.PlainPar $ A.Rep m (A.For m (simpleName "i") (intLiteral 0) (intLiteral 3)) (A.OnlyP m proc) +makeAssign :: A.Variable -> A.Expression -> A.Process +makeAssign v e = A.Assign m [v] $ A.ExpressionList m [e] + + +makeLiteralString :: String -> A.Expression +makeLiteralString str = A.Literal m (A.Array [A.Dimension (length str)] A.Byte) (A.ArrayLiteral m (map makeLiteralChar str)) + where + makeLiteralChar :: Char -> A.ArrayElem + makeLiteralChar c = A.ArrayElemExpr $ A.Literal m A.Byte (A.ByteLiteral m [c] {-(show (fromEnum c))-}) + + assertEqualCustom :: (Show a) => String -> (a -> a -> Bool) -> a -> a -> Assertion assertEqualCustom preface cmp expected actual = unless (cmp actual expected) (assertFailure msg)