From 862fc4fb9b5271939c88bf2e56c7ed6e71728d27 Mon Sep 17 00:00:00 2001 From: mzp Date: Sat, 1 Nov 2008 11:17:06 +0900 Subject: [PATCH] Add more unit test - test for mixed with DefineClass and Plain --- test/test_clostrans.ml | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/test/test_clostrans.ml b/test/test_clostrans.ml index f12a6b0..bd4e74b 100644 --- a/test/test_clostrans.ml +++ b/test/test_clostrans.ml @@ -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 -- 2.11.0