add initial tests
This commit is contained in:
parent
e5d84c9716
commit
8216e76b04
3
assembler/test/dune
Normal file
3
assembler/test/dune
Normal file
@ -0,0 +1,3 @@
|
||||
(tests
|
||||
(names test_hack)
|
||||
(libraries hack ounit2))
|
27
assembler/test/test_hack.ml
Normal file
27
assembler/test/test_hack.ml
Normal 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
|
Loading…
Reference in New Issue
Block a user