OSDN Git Service

Add UnitTest for closTrans
authormzp <mzpppp@gmail.com>
Sat, 1 Nov 2008 02:05:42 +0000 (11:05 +0900)
committermzp <mzpppp@gmail.com>
Sat, 1 Nov 2008 02:05:42 +0000 (11:05 +0900)
src/OMakefile
src/closTrans.ml
test/OMakefile
test/runner.ml
test/test_clostrans.ml [new file with mode: 0644]

index 310f9be..0dfe6dd 100644 (file)
@@ -46,6 +46,7 @@ FILES[] =
        base
        bytes
        closuretrans
+       closTrans
        codegen
        cpool
        hList
index 4a7b458..2878525 100644 (file)
@@ -22,7 +22,7 @@ let methods_table program =
             ());
     tbl
 
-let classize tbl program =
+let classize program tbl =
   HList.concat_map 
     (function
         Plain stmt ->
@@ -31,3 +31,6 @@ let classize tbl program =
           [Ast.Class (klass,super,Hashtbl.find_all tbl klass)]
        | DefineMethod _ ->
           []) program
+
+let trans program =
+  classize program @@ methods_table program
index eecd8a9..02f4cdd 100644 (file)
@@ -54,6 +54,7 @@ FILES[] =
        test_base
        test_bytes
        test_closuretrans
+       test_clostrans
        test_codegen
        test_cpool
        test_hList
index 454e208..a31b8f4 100644 (file)
@@ -13,6 +13,7 @@ open Test_asm
 open Test_ast
 open Test_base
 open Test_bytes
+open Test_clostrans
 open Test_closuretrans
 open Test_codegen
 open Test_cpool
diff --git a/test/test_clostrans.ml b/test/test_clostrans.ml
new file mode 100644 (file)
index 0000000..f12a6b0
--- /dev/null
@@ -0,0 +1,20 @@
+open Base
+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"
+
+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
+
+test plain_is_not_change =
+    assert_equal (Expr (Int 42)) @@ the_one @@ trans [Plain (Expr (Int 42))]