1(import test)23(include "parser.scm")4(include "interpreter.scm")56(define (interpret str #!optional (env '()))7 (let ((prog (parse-loop-prog str)))8 (if prog9 (eval-loop-prog env prog)10 #f)))1112(test-group "parser"13 (test "variable assignment with literal"14 '((assign (var . "x")15 (lit . 5)))16 (parse-loop-prog "x := 5;"))1718 (test "variable assignment with expression"19 '((assign (var . "y")20 (expr (var . "y")21 (op . minus)22 (var . "y"))))23 (parse-loop-prog "y:=y-y;"))2425 (test "variable assign with variable"26 '((assign (var . "a") (var . "b")))27 (parse-loop-prog "a:=b;"))2829 (test "loop with variable condition"30 '((loop (var . "x")31 ((assign (var . "x") (var . "x")))))32 (parse-loop-prog "LOOP x DO x:=x; DONE;"))3334 (test "loop with loop in body"35 '((loop (lit . 1)36 ((loop (lit . 2)37 ((assign (var . "x") (lit . 5)))))))38 (parse-loop-prog "LOOP 1 DO LOOP 2 DO x:=5; DONE; DONE;"))3940 (test "sequence of multiple assignments"41 '((assign (var . "x") (lit . 1))42 (assign (var . "x") (lit . 2)))43 (parse-loop-prog "x := 1; x := 2;")))4445(test-group "interpreter"46 (test "variable assignment with literal"47 '(("a" . 1)) (interpret "a := 1;"))4849 (test "variable assignment with variable"50 '(("y" . 42) ("x" . 42)) (interpret "y := x;" '(("x" . 42))))5152 (test "variable assignment with expression"53 '(("x" . 2)) (interpret "x := 1 + 1;"))5455 (test "variable default values"56 '(("x" . 1)) (interpret "x := y + 1;"))5758 (test "loop with literal condition"59 '(("x" . 3)) (interpret "LOOP 3 DO x := x + 1; DONE;"))6061 (test "loop with condition modification"62 '(("z". 2)) (interpret "LOOP z DO z := z + 1; DONE;" '(("z" . 1))))6364 (test "loop with false condition"65 '() (interpret "LOOP 0 DO x := 42; DONE;")))