add initial tests

This commit is contained in:
konarak committed 2022-08-01 14:59:06 +05:30
1 parent e5d84c9716
commit 8216e76b04
2 files changed
+30

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
(tests
(names test_hack)
(libraries hack ounit2))
+27
View File
@@ -0,0 +1,27 @@
open OUnit2
open Hack.Ast
open Hack.Translate
let peq case value = assert_equal value (parse case)
let test_parse_g_instr _ = peq "(LOOP)" (Ginstr "LOOP")
let test_parse_a_instr _ =
peq "@100" (Aconst 100);
peq "@ABC" (Ainstr "ABC")
;;
let test_parse_c_instr _ =
peq "M-D" (Cinstr ("", "M-D", ""));
peq "0;JMP" (Cinstr ("", "0", "JMP"));
peq "D=A+1" (Cinstr ("D", "A+1", ""))
;;
let suite =
"suite"
>::: [ "G Instruction" >:: test_parse_g_instr
; "A Instruction" >:: test_parse_a_instr
; "C Instruction" >:: test_parse_c_instr
]
;;
let () = run_test_tt_main suite