Commit 1eb86124 authored by Julien Lopez's avatar Julien Lopez
Browse files

[TESTS][LAMBDA] Add tests; fix a test on sequences; `nil defined but not used

parent 385e678c
......@@ -61,20 +61,24 @@ let rec _to_typed env l expr =
env, l, { exp_loc=loc; exp_typ=empty;
exp_descr=Pair(exp_descr1, exp_descr2) }
| Var (origloc, vname) ->
let line = Loc.start_line origloc in
let cbegin = Loc.start_off origloc - Loc.start_bol origloc in
let cend = Loc.stop_off origloc - Loc.start_bol origloc in
let index = (try Locals.find vname l with Not_found ->
Printf.eprintf "File %s, line %d, characters %d-%d:\nUnbound identifier %s\n"
if vname = "`nil" then
let nil_atom = Atoms.V.mk_ascii "nil" in
env, l, { exp_loc=loc; exp_typ=(Types.atom (Atoms.atom nil_atom)); exp_descr=(Cst (Atom nil_atom)) }
else
let line = Loc.start_line origloc in
let cbegin = Loc.start_off origloc - Loc.start_bol origloc in
let cend = Loc.stop_off origloc - Loc.start_bol origloc in
let index = (try Locals.find vname l with Not_found -> Printf.eprintf
"File %s, line %d, characters %d-%d:\nUnbound identifier %s\n"
(Loc.file_name origloc) line cbegin cend vname; raise Error) in
env, l, { exp_loc=loc; exp_typ=empty; exp_descr=Var(index, vname) }
env, l, { exp_loc=loc; exp_typ=empty; exp_descr=Var(index, vname) }
| Int (_, i) ->
let i = Big_int.big_int_of_int i in
let i = big_int_of_int i in
env, l, { exp_loc=loc; exp_typ=(type_of_string "Int");
exp_descr=Cst(Integer i) }
| String (_, s) ->
let s = String (0, (String.length s) - 1, s,
Integer (Big_int.big_int_of_int 0)) in
Integer (big_int_of_int 0)) in
env, l, { exp_loc=loc; exp_typ=(type_of_string "String");
exp_descr=Cst s }
......@@ -98,7 +102,6 @@ and parse_abstr env l fv loc fun_name params rtype body =
let brs = { br_typ=rtype; br_accept=any; br_branches=[b] } in
let abstr = { fun_name=fun_name; fun_iface=iface; fun_body=brs;
fun_typ=fun_typ; fun_fv=oldfv } in
(* TODO: Fix exp_typ *)
env, l, { exp_loc=loc; exp_typ=any; exp_descr=Abstraction(abstr) }
in
_parse_abstr env l fv loc fun_name params (type_of_ptype rtype) body 0
......
......@@ -25,7 +25,6 @@ let tests = "CDuce runtime tests" >:::
assert_equal ~msg:"Test CDuce.runtime.abstr.simple failed"
~printer:(fun x -> x) "Abstraction((Int, Int))"
(run_test "fun f x : Int : Int -> 2");
(* TODO: Fix this test. See compute.ml in type_of_string function *)
assert_equal ~msg:"Test CDuce.runtime.abstr.medium failed"
~printer:(fun x -> x) "Abstraction((Int, [ Char* ] -> [ Int Char* ]))"
(run_test "fun f x : Int y : String : (Int*String) -> x,y");
......@@ -80,6 +79,10 @@ let tests = "CDuce runtime tests" >:::
~printer:(fun x -> x) "2"
(run_test "(fun f x : Int : Int ->
match x : Int with | 1 -> 3 | x : Int -> x).2");
assert_equal ~msg:"Test CDuce.runtime.match.rec failed"
~printer:(fun x -> x) "3"
(run_test "(fun f x : Int : Int ->
match x : Int with | 1 -> 3 | x : Int -> f.1).2");
);
"string" >:: ( fun test_ctxt ->
......@@ -100,14 +103,19 @@ let tests = "CDuce runtime tests" >:::
| (el : Int) :: (rest : [Int]) -> el
| x : Int -> 3");
assert_equal ~msg:"Test CDuce.runtime.list.tail failed"
~printer:(fun x -> x) "Abstraction(([ Int* ], [ Int* ]))"
(run_test "fun tail x : [Int] : [Int] -> match x : [Int] with
| (el : Int) :: (rest : [Int]) -> rest");
assert_equal ~msg:"Test CDuce.runtime.list.tail.eval failed"
~printer:(fun x -> x) "(2, 5)"
(run_test "(fun f x : [Int] : [Int] -> match x : [Int] with
(run_test "(fun tail x : [Int] : [Int] -> match x : [Int] with
| (el : Int) :: (rest : [Int]) -> rest).[1; 2; 5]");
(* TODO: Fix this test, we need to define [] aka `nil *)
assert_equal ~msg:"Test CDuce.runtime.list.last failed"
~printer:(fun x -> x) "4"
~printer:(fun x -> x) "7"
(run_test "(fun f x : [Int] : [Int] -> match x : [Int] with
| el : Int -> el
| (el : Int) :: (rest : [Int]) -> f.rest).[1; 2; 5; 4]");
| (el : Int) :: (rest : [Int]) -> f.rest
| el : [Int] -> el).[1; 2; 5; 4; 8; 7]");
);
]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment