OSDN Git Service

[UPDATE]add test for syntax error
authormzp <mzpppp@gmail.com>
Sun, 16 Nov 2008 15:00:36 +0000 (00:00 +0900)
committermzp <mzpppp@gmail.com>
Sun, 16 Nov 2008 15:00:36 +0000 (00:00 +0900)
src/lisp.ml
src/lisp.mli
test/test_lisp.ml
test/test_tuple.ml [new file with mode: 0644]

index b2ff605..56949f6 100644 (file)
@@ -2,6 +2,8 @@ open Base
 open Sexp
 open ClosTrans
 
+exception Syntax_error of string
+
 let symbol = function
     Symbol n -> n
   | _ -> failwith "expected symbol"
@@ -99,3 +101,4 @@ let compile stream =
 
 let compile_string string =
   compile @@ Stream.of_string string
+
index b11d557..197e36f 100644 (file)
@@ -1,2 +1,4 @@
+exception Syntax_error of string
+
 val compile : char Stream.t -> ClosTrans.program
 val compile_string : string -> ClosTrans.program
index d7b3597..458f608 100644 (file)
@@ -11,6 +11,13 @@ let result xs =
 let ok x y =
   OUnit.assert_equal ~printer:(string_of_list $ List.map ClosTrans.to_string) x y
 
+let syntax_error f =
+  try
+    f ();
+    assert_failure "not raise"
+  with Syntax_error _ ->
+    assert_bool "raised" true
+
 let _ =
   ("lisp module test" >::: [
      "empty" >::
@@ -147,8 +154,9 @@ let _ =
      "slot-set!" >::
        (fun () ->
          ok (result (SlotSet (Var "obj","name",Int 42))) @@
-           Lisp.compile_string "(slot-set! obj name 42)")
+           Lisp.compile_string "(slot-set! obj name 42)");
+     "syntax error" >::
+       (fun () ->
+         syntax_error (fun () ->
+                         Lisp.compile_string "(if a)"))
    ]) +> run_test_tt
-  
-
-
diff --git a/test/test_tuple.ml b/test/test_tuple.ml
new file mode 100644 (file)
index 0000000..d44c0e6
--- /dev/null
@@ -0,0 +1,30 @@
+open Base
+open OUnit
+open Util
+
+let inc x = 
+  x + 1
+
+let _ =
+  ("Tuple" >:::
+     ["T2" >::: [
+       "map1" >:: 
+         (fun () ->
+            ok (2,1) @@ Tuple.T2.map1 inc (1,1));
+       "map2" >::
+         (fun () ->
+            ok (1,2) @@ Tuple.T2.map2 inc (1,1));
+      ];
+      "T3" >::: [
+       "map1" >::
+         (fun () ->
+            ok (2,1,1) @@ Tuple.T3.map1 inc (1,1,1));
+       "map2" >::
+         (fun () ->
+            ok (1,2,1) @@ Tuple.T3.map2 inc (1,1,1));
+       "map3" >::
+         (fun () ->
+            ok (1,1,2) @@ Tuple.T3.map3 inc (1,1,1));
+      ]
+     ]) +> run_test_tt
+