{-# LANGUAGE OverloadedStrings #-} import Test.HUnit (Assertion, (@=?), runTestTT, Test(..), Counts(..)) import System.Exit (ExitCode(..), exitWith) import Data.Char (toUpper) import Prelude hiding (print,(++),(+),(-),(*),(/),(%),(==),(/=),(>=),(>),(<=),(<),(&&),(||),not,abs,return) import qualified Prelude as P import Language.Huckleberry.V10101 exitProperly :: IO Counts -> IO () exitProperly m = do counts <- m exitWith $ if failures counts P./= 0 P.|| errors counts P./= 0 then ExitFailure 1 else ExitSuccess testCase :: String -> Assertion -> Test testCase label assertion = TestLabel label (TestCase assertion) main :: IO () main = exitProperly $ runTestTT $ TestList [ TestList huckleberryTests ] huckleberryTests :: [Test] huckleberryTests = [ testCase "number literal" $ "?1234\n" @=? (translate $ print 1234) , testCase "number literal" $ "?102575\n" @=? (translate $ print 0x190AF) , testCase "string literal" $ "?\"abcd\"\n" @=? (translate $ print "abcd") , testCase "variable" $ "?A\n" @=? (translate $ print a) , testCase "variable" $ "?A+1\n" @=? (translate $ print $ a+1) , testCase "array" $ "?[8]\n" @=? (translate $ print $ arr 8) , testCase "array" $ "?[A]\n" @=? (translate $ print $ arr a) , testCase "array" $ "?[A+1]\n" @=? (translate $ print $ arr (a+1)) , testCase "++" $ "?\"abc\";\"def\"\n" @=? (translate $ print $ "abc" ++ "def") , testCase "++" $ "?1234;5678\n" @=? (translate $ print $ 1234 ++ 5678) , testCase "++" $ "?\"abc\";5678\n" @=? (translate $ print $ "abc" ++ 5678) , testCase "++" $ "?1234;\"def\"\n" @=? (translate $ print $ 1234 ++ "def") , testCase "let'" $ "LETA,1\n" @=? (translate $ let' a [1]) , testCase "let'" $ "LETA+1,1\n" @=? (translate $ let' (a+1) [1]) , testCase "let'" $ "LETA,1,2,3\n" @=? (translate $ let' a [1,2,3]) , testCase "let'" $ "LETA+1,1,2,3\n" @=? (translate $ let' (a+1) [1,2,3]) , testCase "let'" $ "LET[8],1,2,3\n" @=? (translate $ let' (arr 8) [1,2,3]) , testCase "let'" $ "LET[A],A+1,2,3\n" @=? (translate $ let' (arr a) [a+1,2,3]) , testCase "let'" $ "LET[A+1],1,2,3\n" @=? (translate $ let' (arr (a+1)) [1,2,3]) , testCase "=:" $ "A=1\n" @=? (translate $ a=:1) , testCase "=:" $ "A=B\n" @=? (translate $ a=:b) , testCase "ifThenElse" $ "IFA=B?\"S\"ELSE?\"N\"\n" @=? (translate $ ifThenElse (a==b) (print "S") (print "N")) , testCase "ifThen" $ "IFA=B?\"S\"\n" @=? (translate $ ifThen (a==b) (print "S")) , testCase "forStepNext" $ "FORA=0TO99STEP2:?[A+1]+2:NEXT\n" @=? (translate $ forStepNext a 0 99 2 (print $ arr (a+1) +2)) , testCase "forNext" $ "FORA=0TO99:?[A+1]+2:NEXT\n" @=? (translate $ forNext a 0 99 (print $ arr (a+1) +2)) , testCase "pre" $ "?(A-1)*(B+1)\n" @=? (translate $ print $ pre(a-1)*pre(b+1)) , testCase "pre" $ "?A-1*B+1\n" @=? (translate $ print $ (a-1)*(b+1)) , testCase "led" $ "LEDA+1\n" @=? (translate $ led (a+1)) , testCase "wait" $ "WAITA+1\n" @=? (translate $ wait(a+1)) , testCase "run" $ "RUN\n" @=? (translate $ run) , testCase "list" $ "LISTA+1,B+2\n" @=? (translate $ list (a+1) (b+2)) , testCase "list'" $ "LIST\n" @=? (translate $ list') , testCase "goto" $ "GOTOA+1\n" @=? (translate $ goto (a+1)) , testCase "end" $ "END\n" @=? (translate $ end) , testCase "btn" $ "?BTN(A+1)+2\n" @=? (translate $ print $ (btn (a+1)) +2) , testCase "new" $ "NEW\n" @=? (translate $ new) , testCase "locate" $ "LCA+1,B+2\n" @=? (translate $ locate (a+1) (b+2)) , testCase "cls" $ "CLS\n" @=? (translate $ cls) , testCase "rnd" $ "?RND(A+1)+2\n" @=? (translate $ print $ (rnd (a+1)) +2) , testCase "save" $ "SAVEA+1\n" @=? (translate $ save (a+1)) , testCase "save'" $ "SAVE\n" @=? (translate $ save') , testCase "load" $ "LOADA+1\n" @=? (translate $ load (a+1)) , testCase "load'" $ "LOAD\n" @=? (translate $ load') , testCase "files" $ "FILESA+1\n" @=? (translate $ files (a+1)) , testCase "beep" $ "BEEPA+1,B+2\n" @=? (translate $ beep (a+1) (b+2)) , testCase "beep'" $ "BEEP\n" @=? (translate $ beep') , testCase "play" $ "PLAY\"ABCD\"\n" @=? (translate $ play "ABCD") , testCase "play'" $ "PLAY\n" @=? (translate $ play') , testCase "tempo" $ "TEMPOA+1\n" @=? (translate $ tempo (a+1)) , testCase "+" $ "?A+B\n" @=? (translate $ print $ a+b) , testCase "-" $ "?A-B\n" @=? (translate $ print $ a-b) , testCase "*" $ "?A*B\n" @=? (translate $ print $ a*b) , testCase "/" $ "?A/B\n" @=? (translate $ print $ a/b) , testCase "%" $ "?A%B\n" @=? (translate $ print $ a%b) , testCase "input" $ "INPUT\"Q?\",A\n" @=? (translate $ input "Q?" a) , testCase "tick" $ "?TICK()+1\n" @=? (translate $ print $ tick +1) , testCase "clt" $ "CLT\n" @=? (translate $ clt) , testCase "inkey" $ "?INKEY()+1\n" @=? (translate $ print $ inkey +1) , testCase "chr" $ "?CHR$(A+1);\"def\"\n" @=? (translate $ print $ chr (a+1) ++ "def") , testCase "chr'" $ "?CHR$(65,66,67)\n" @=? (translate $ print $ chr'[65,66,67]) , testCase "asc" $ "?ASC(\"abcd\")\n" @=? (translate $ print $ asc "abcd") , testCase "scroll" $ "SCROLLA+1\n" @=? (translate $ scroll (a+1)) , testCase "scr" $ "?SCR(A+1,B+2)+2\n" @=? (translate $ print $ (scr (a+1) (b+2))+2) , testCase "scr'" $ "?SCR()+1\n" @=? (translate $ print $ scr'+1) , testCase "vpeek" $ "?SCR(A+1,B+2)+2\n" @=? (translate $ print $ (vpeek (a+1) (b+2))+2) , testCase "vpeek'" $ "?SCR()+1\n" @=? (translate $ print $ vpeek'+1) , testCase "==" $ "?A=B\n" @=? (translate $ print $ a==b) , testCase "/=" $ "?A!=B\n" @=? (translate $ print $ a/=b) , testCase ">=" $ "?A>=B\n" @=? (translate $ print $ a>=b) , testCase ">" $ "?A>B\n" @=? (translate $ print $ a>b) , testCase "<=" $ "?A<=B\n" @=? (translate $ print $ a<=b) , testCase "<" $ "?A>B\n" @=? (translate $ print $ a`shiftR`b) , testCase "shiftL" $ "?A<