From 7b812087945b9ca5c14a829cea52b28d0caaa2d9 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Sat, 18 Aug 2007 10:59:00 +0000 Subject: [PATCH] Rain: refactored the pass tests to remove duplicate code --- RainPassTest.hs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/RainPassTest.hs b/RainPassTest.hs index 4606c93..303324c 100644 --- a/RainPassTest.hs +++ b/RainPassTest.hs @@ -11,16 +11,19 @@ import CompState import Control.Monad.Error (runErrorT) import Control.Monad.Identity import Types +import Pass +import Data.Generics + +testPass :: (Data a, Data b) => String -> a -> PassM b -> (State CompState ()) -> Test +testPass testName expected actualPass startStateTrans = TestCase $ + do result <- (evalStateT (runErrorT actualPass) (execState startStateTrans emptyState)) + case result of + Left err -> assertFailure (testName ++ "; pass actually failed: " ++ err) + Right resultItem -> assertPatternMatch testName expected resultItem testEachPass0 :: Test -testEachPass0 = TestCase $ - do origResult <- (evalStateT (runErrorT (transformEach orig)) startState) - case origResult of - Left err -> assertFailure ("testEachPass0; pass failed with: " ++ err) - Right origTrans -> assertPatternMatch "testEachPass0" exp origTrans +testEachPass0 = testPass "testEachPass0" exp (transformEach orig) startState' where - startState :: CompState - startState = execState startState' emptyState startState' :: State CompState () startState' = do defineName (simpleName "c") A.NameDef {A.ndType = A.Declaration m A.Byte} @@ -55,14 +58,8 @@ testEachPass0 = TestCase $ testEachPass1 :: Test -testEachPass1 = TestCase $ - do origResult <- (evalStateT (runErrorT (transformEach orig)) startState) - case origResult of - Left err -> assertFailure ("testEachPass1; pass failed with: " ++ err) - Right origTrans -> assertPatternMatch "testEachPass1" exp origTrans +testEachPass1 = testPass "testEachPass0" exp (transformEach orig) startState' where - startState :: CompState - startState = execState startState' emptyState startState' :: State CompState () startState' = do defineName (simpleName "c") A.NameDef {A.ndType = A.Declaration m A.Byte} defineName (simpleName "d") A.NameDef {A.ndType = A.Declaration m (A.Array [A.Dimension 10] A.Byte)}