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

1234567890123456789012345678901234567890123456789012345678901234567890

2017-05-23: V2--Updated to test Infix Parser V2 (using Either)
2017-07-06: V3--Updated to test Infix Parser V3

TODO:
- Test more thoroughly

-}

module TestInfix03
  (main, test)
where

import Data.Either

import ParseInfix03


{- 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 " ++ msg
showAST (Right ex)  = show ex

-- Partial Testing of the package

test00 = test ""
test01 = test "x3"
test02 = test "3"
test03 = test "xx+ 1"
test04 = test "xy * 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)"
test12 = test "(3 + - 12)"
test13 = test "(3 - - 12)"
test14 = test "(3 - - - 12)"      -- Fails

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
-}

