OSDN Git Service

Add more unit test
authormzp <mzpppp@gmail.com>
Sat, 1 Nov 2008 02:17:06 +0000 (11:17 +0900)
committermzp <mzpppp@gmail.com>
Sat, 1 Nov 2008 02:17:06 +0000 (11:17 +0900)
- test for mixed with DefineClass and Plain

test/test_clostrans.ml

index f12a6b0..bd4e74b 100644 (file)
@@ -3,18 +3,23 @@ open ClosTrans
 open Ast
 
 let assert_equal x y =
-  OUnit.assert_equal ~printer:Ast.to_string_stmt x y
-
-let the_one =
-  function [x] -> x
-    | _ -> failwith "list is not one"
+  OUnit.assert_equal ~printer:(string_of_list $ List.map Ast.to_string_stmt) x y
 
 test trans =
-    let expect = Class ("Foo",("bar","Baz"),
-                       [("f",["self";"x"],Int 42)]) in
-    let source = [DefineClass ("Foo",("bar","Baz"),[]);
-                 DefineMethod ("f",("self","Foo"),["x"],Int 42)] in
-      assert_equal expect @@ the_one @@ trans source
+  let expect = [Class ("Foo",("bar","Baz"),
+                     [("f",["self";"x"],Int 42)])] in
+  let source = [DefineClass ("Foo",("bar","Baz"),[]);
+               DefineMethod ("f",("self","Foo"),["x"],Int 42)] in
+    assert_equal expect @@ trans source
 
 test plain_is_not_change =
-    assert_equal (Expr (Int 42)) @@ the_one @@ trans [Plain (Expr (Int 42))]
+  assert_equal [Expr (Int 42)] @@ trans [Plain (Expr (Int 42))]
+
+test trans_with_mix =
+  let expect = [Class ("Foo",("bar","Baz"),
+                     [("f",["self";"x"],Int 42)]);
+               Expr (Int 42)] in
+  let source = [DefineClass ("Foo",("bar","Baz"),[]);
+               Plain (Expr (Int 42));
+               DefineMethod ("f",("self","Foo"),["x"],Int 42)] in
+    assert_equal expect @@ trans source