From a2af866d90a95930760442e81f82327384f42bb6 Mon Sep 17 00:00:00 2001 From: mzp Date: Sun, 9 Nov 2008 23:28:06 +0900 Subject: [PATCH] [REFACOTR]clos --- test/test_clostrans.ml | 94 +++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/test/test_clostrans.ml b/test/test_clostrans.ml index 9d9f44e..57c3610 100644 --- a/test/test_clostrans.ml +++ b/test/test_clostrans.ml @@ -1,57 +1,51 @@ open Base open ClosTrans open Ast +open OUnit -let assert_equal x y = +let ok x y = 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 @@ trans source +let _ = + ("clos module test" >::: [ + "basic" >:: + (fun () -> + ok [Class ("Foo",("bar","Baz"),[], + [("f",["self";"x"],Int 42)])] @@ + trans [DefineClass ("Foo",("bar","Baz"),[]); + DefineMethod ("f",("self","Foo"),["x"],Int 42)]); + "attributes" >:: + (fun () -> + ok [Class ("Foo",("bar","Baz"),["x";"y"],[])] @@ + trans [DefineClass ("Foo",("bar","Baz"),["x";"y"])]); + "plain is not change" >:: + (fun () -> + ok [Expr (Int 42)] @@ + trans [Plain (Expr (Int 42))]); + "define and plain is mixed" >:: + (fun () -> + ok [Class ("Foo",("bar","Baz"),[], + [("f",["self";"x"],Int 42)]); + Expr (Int 42)] @@ + trans [DefineClass ("Foo",("bar","Baz"),[]); + Plain (Expr (Int 42)); + DefineMethod ("f",("self","Foo"),["x"],Int 42)]); + "invoke" >:: + (fun () -> + ok [Class ("Foo",("bar","Baz"),[], + [("f",["self";"x"],Int 42)]); + Expr (Invoke (Var "obj","f",[Int 10]))] @@ + trans [DefineClass ("Foo",("bar","Baz"),[]); + DefineMethod ("f",("self","Foo"),["x"],Int 42); + Plain (Expr (Call [Var "f";Var "obj";Int 10]))]); + "invoke deep" >:: + (fun () -> + ok [Expr (If (Invoke (Var "obj","f",[Int 10]), + Block [], + Block []))] @@ + trans [DefineMethod ("f",("self","Foo"),["x"],Int 42); + Plain (Expr (If (Call [Var "f";Var "obj";Int 10], + Block [], + Block [])))]) + ]) +> run_test_tt -test attributes = - let expect = - [Class ("Foo",("bar","Baz"),["x";"y"], - [])]in - let source = - [DefineClass ("Foo",("bar","Baz"),["x";"y"])] in - assert_equal expect @@ trans source - - -test plain_is_not_change = - 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 - -test invoke = - let expect = - [Class ("Foo",("bar","Baz"),[], - [("f",["self";"x"],Int 42)]); - Expr (Invoke (Var "obj","f",[Int 10]))] in - let source = - [DefineClass ("Foo",("bar","Baz"),[]); - DefineMethod ("f",("self","Foo"),["x"],Int 42); - Plain (Expr (Call [Var "f";Var "obj";Int 10]))] in - assert_equal expect @@ trans source - -test invoke_if = - let expect = - [Expr (If (Invoke (Var "obj","f",[Int 10]), - Block [], - Block []))] in - let source = - [DefineMethod ("f",("self","Foo"),["x"],Int 42); - Plain (Expr (If (Call [Var "f";Var "obj";Int 10], - Block [], - Block [])))] in - assert_equal expect @@ trans source -- 2.11.0