{- CSci 556: Multiparadigm Programming, Spring 2017
   Prefix Expression Language: Testing Version 6
   H. Conrad Cunningham, Professor
   Computer and Information Science
   University of Mississippi, USA

1234567890123456789012345678901234567890123456789012345678901234567890

2017-05-20: V4--Separated test module from Prefix Parser V3
2017-05-20: V5--Updated to test Prefix Parser V5 (using Either)
2017-06-09: V6--Updated to test Prefix Parser V6 

TODO:
- Test more thoroughly

-}

module TestPrefix06
  (main, test)
where

import Data.Either

import ParsePrefix06

{- PARTIAL TESTING -}

{- Function "test" takes a string and prints both the "Expr"
   and "[Token]" returns from "expr".
-}

test :: String -> IO()
test xs = putStrLn ("\nExpression:  " ++ (show xs) ++
                    "\nTokens:      " ++ (show toks) ++
                    "\nResult:      " ++ (showAST ex1) ++
                    "\nAfter:       " ++ (show ts) ++
                    "\nParse:       " ++ (showAST ex2))
    where
        toks     = lexer xs
        (ex1,ts) = parseExpression toks
        ex2      = parse xs

showAST :: Either ErrMsg Expr -> String
showAST (Left msg) = "ERROR " ++ show msg
showAST (Right ex)  = show ex

-- A few test cases

test00  = test ""                    -- Fails
test01  = test "x3"
test02  = test "3"
test03  = test "(+ xx 1)"
test04  = test "(+ yy 3)"
test05  = test "(+ x (* 0 (+ 3 x2)))"
test06  = test "(+ x (* 0 (+ 3 x2))" -- Fails
test07  = test ")*(&)("              -- Fails
test08  = test "x1xd!"               -- Fails
test09  = test "-12"
test10  = test "-   12"
test11  = test "(-12)"               -- Fails
test12  = test "(+ 3 - 12)"          
test13  = test "(- 3 - 12)" 
test14  = test "(- 3 - - 12)"        -- Fails
test15  = test "(neg (+ 1 2))"
test16  = test "(cos (+ 1 2))"
test17  = test "(sin (+ 1 2))"
test18  = test "(if z (+ x 1) (- y 1))"
test19  = test "(neg (+ 1 2) 13)"
test20  = test "(+ (+ 1 2))"
test21  = test "(+ (+ 1 2) x y z)"
test22  = test "min"
test23  = test "(<= 2 3 )"
test24  = test "(<= (== 2 3) x)"
test25  = test "(! 0)"
test26  = test "(! 1  2)"
test27  = test "(&& 0 1)"
test28  = test "(|| 0 1)"
test29  = test "(, 0 1)"
test30  = test "()"
test31  = test "(())"

main =
    do
        test00
        test01
        test02
        test03
        test04
        test05
        test06
        test07
        test08
        test09
        test10
        test11
        test12
        test13
        test14
        test15
        test16
        test17
        test18
        test19
        test20
        test21
        test22
        test23
        test24
        test25
        test26
        test27
        test28
        test29
        test30
        test31

