nand2tetris/compiler/backend/test/test_backend.ml

32 lines
791 B
OCaml
Raw Normal View History

open OUnit2
open Backend.Ast
open Backend.Translate
let peq case value = assert_equal value (parse case)
let test_parse_a_command _ =
peq "add" (ArithmeticCommand Add);
peq "sub" (ArithmeticCommand Sub);
peq "neg" (ArithmeticCommand Neg);
peq "eq" (ArithmeticCommand Eq);
peq "gt" (ArithmeticCommand Gt);
peq "lt" (ArithmeticCommand Lt);
peq "and" (ArithmeticCommand And);
peq "or" (ArithmeticCommand Or);
peq "not" (ArithmeticCommand Not)
;;
let test_parse_m_command _ =
peq "pop local 12" (MemoryAccessCommand (Pop, Local, 12));
peq "push argument 4" (MemoryAccessCommand (Push, Argument, 4))
;;
let suite =
"suite"
>::: [ "A Instruction" >:: test_parse_a_command
; "M Instruction" >:: test_parse_m_command
]
;;
let () = run_test_tt_main suite