-- $Id: CoreLangTest.hs,v 1.3 1998/02/15 05:45:26 leavens Exp $

-- Gary T. Leavens
-- Semantic testing for the language of Chapter 1

module CoreLangTest where
import CoreLangParser
import CoreTypeHelpers
import CoreTyping
import CoreSemantics
import Domains
import CoreLangProgs
import Testing

sample_store :: DStore
sample_store = [1..10]


evalC :: Command -> String
evalC c = let ca@(_ ::: Node atr _) = annotate c
          in if atr == Aerr
             then "type error"
             else show (meaningC ca sample_store)
evalE :: Expression -> String
evalE e = let ea@(_ ::: Node atr _) = annotate e
          in if atr == Aerr
             then "type error"
             else show (meaningE ea sample_store)


repC :: String -> IO ()
repC = putStrLn . evalC . read
repE :: String -> IO ()
repE = putStrLn . evalE . read


test n = repC (prog n)


runC :: String -> DStore
runC c = meaningC (annotate (read c)) sample_store


tests :: [TestCase DStore DStore]
tests = map (\(c,m) -> eqTest c (runC c) (m sample_store)) progs_with_results

-- The following runs all the test programs

go :: IO ()
go = run_tests tests
