9 [ClosTrans.Plain (Ast.Expr xs)]
12 {(Node.empty x) with Node.filename = "<string>"; Node.lineno = 0}
15 OUnit.assert_equal ~printer:(string_of_list $ List.map ClosTrans.to_string) x y
20 assert_failure "not raise"
21 with Syntax_error _ ->
22 assert_bool "raised" true
39 let define_class name super attrs =
40 DefineClass (node name,node super,List.map node attrs)
42 let define_method name self obj args body =
43 DefineMethod (node name,(node self,node obj),List.map node args,body)
46 ("lisp module test" >::: [
49 OUnit.assert_equal [] @@ Lisp.compile_string "");
52 OUnit.assert_equal [] @@
53 Lisp.compile_string "; foo bar");
56 ok (expr (string "hello")) @@
57 Lisp.compile_string "\"hello\"");
61 Lisp.compile_string "42");
64 ok (expr (float 42.)) @@
65 Lisp.compile_string "42.";
66 ok (expr (float 42.5)) @@
67 Lisp.compile_string "42.5");
70 ok (expr (bool true)) @@
71 Lisp.compile_string "#t";
72 ok (expr (bool false)) @@
73 Lisp.compile_string "#f");
76 ok (expr (Call [var "print"])) @@
77 Lisp.compile_string "(print)";
78 ok (expr (Call [var "print";string "hello"])) @@
79 Lisp.compile_string "(print \"hello\")";
80 ok (expr (Call [var "print";string "hello";string "world"])) @@
81 Lisp.compile_string "(print \"hello\" \"world\")");
84 ok (expr (Call [var "+";int 1;int 2])) @@
85 Lisp.compile_string "(+ 1 2)";
86 ok (expr (Call [var "-";int 1;int 2])) @@
87 Lisp.compile_string "(- 1 2)";
88 ok (expr (Call [var "*";int 1;int 2])) @@
89 Lisp.compile_string "(* 1 2)";
90 ok (expr (Call [var "/";int 1;int 2])) @@
91 Lisp.compile_string "(/ 1 2)");
94 ok (expr (Call [var "=";int 1;int 2])) @@
95 Lisp.compile_string "(= 1 2)";
96 ok (expr (Call [var "<";int 1;int 2])) @@
97 Lisp.compile_string "(< 1 2)";
98 ok (expr (Call [var "<=";int 1;int 2])) @@
99 Lisp.compile_string "(<= 1 2)";
100 ok (expr (Call [var ">";int 1;int 2])) @@
101 Lisp.compile_string "(> 1 2)";
102 ok (expr (Call [var ">=";int 1;int 2])) @@
103 Lisp.compile_string "(>= 1 2)");
106 ok (expr (If (int 1,int 2,int 3))) @@
107 Lisp.compile_string "(if 1 2 3)");
115 Lisp.compile_string "(cond (1 2) (3 4) (else 5))");
116 "cond without else" >::
123 Lisp.compile_string "(cond (1 2) (3 4))");
126 ok (expr (Let ([node "x",int 1;node "y",int 2],Block [var "x";var "y"]))) @@
127 Lisp.compile_string "(let ((x 1) (y 2)) x y)");
130 ok (expr (LetRec ([node "x",int 1;node "y",int 2],Block [var "x";var "y"]))) @@
131 Lisp.compile_string "(letrec ((x 1) (y 2)) x y)");
134 ok (expr (Block [int 1;int 2])) @@
135 Lisp.compile_string "(begin 1 2)");
138 ok (expr (Lambda ([],Block [int 42]))) @@
139 Lisp.compile_string "(lambda () 42)");
142 ok (expr (Lambda ([node "a";node "b";node "c"],Block [int 42]))) @@
143 Lisp.compile_string "(lambda (a b c) 42)");
146 ok (expr (New (node ("","Foo"),[]))) @@
147 Lisp.compile_string "(new Foo)");
150 ok (expr (New (node ("","Foo"),[int 1;int 2]))) @@
151 Lisp.compile_string "(new Foo 1 2)");
154 ok (expr (Invoke (var "foo",node "baz",[int 1;int 2]))) @@
155 Lisp.compile_string "(. foo (baz 1 2))");
158 ok [Plain (Define (node "x",Block [int 42]))] @@
159 Lisp.compile_string "(define x 42)";
160 ok [Plain (Define (node "f",Lambda ([node "x"],Block [int 42])))] @@
161 Lisp.compile_string "(define (f x) 42)");
164 ok [define_class "Foo" ("","Object") ["x";"y"]] @@
165 Lisp.compile_string "(define-class Foo (Object) (x y))";
166 ok [define_class "Foo" ("flash.text","Object") ["x";"y"]] @@
167 Lisp.compile_string "(define-class Foo (flash.text.Object) (x y))";
168 ok [define_class "Foo" ("flash.text","Object") []] @@
169 Lisp.compile_string "(define-class Foo (flash.text.Object) ())");
172 ok [define_method "f" "self" "Object" ["x";"y"] (Block [int 42])] @@
173 Lisp.compile_string "(define-method f ((self Object) x y) 42)");
176 ok (expr (SlotRef (var "obj",node "name"))) @@
177 Lisp.compile_string "(slot-ref obj name)");
180 ok (expr (SlotSet (var "obj",node "name",int 42))) @@
181 Lisp.compile_string "(slot-set! obj name 42)");
184 syntax_error (fun () ->
185 Lisp.compile_string "(if a)"))