Commit 5bb58470 authored by Julien Lopez's avatar Julien Lopez
Browse files

[TESTS][LAMBDA] Cleaning tests; better definition of "_"

parent f7a63894
......@@ -226,7 +226,8 @@ and parse_match_value env l list toptype = function
let t = Types.atom (Atoms.atom nil_atom) in
(t, Patterns.Constr(t), list, l, true)
else if mname = "_" then
(Types.any, Patterns.Constr(Types.any), list, l, true)
let t = type_of_ptype mtype in
(t, Patterns.Constr(t), list, l, true)
else
let lsize = Locals.cardinal l in
let l = Locals.add mname (lsize, type_of_ptype mtype) l in
......
......@@ -265,23 +265,19 @@ let tests_eval = "CDuce runtime tests (Typed -> Lambda -> Value)" >:::
"match" >:: ( fun test_ctxt ->
assert_equal ~msg:"Test CDuce.runtime.match.simple failed"
~printer:(fun x -> x) "1"
(run_test_eval "match 1 : Int with | 1 -> 1 | \"true\" -> \"true\"");
assert_equal ~msg:"Test CDuce.runtime.match.unused_branches failed"
~printer:(fun x -> x) "1"
(run_test_eval "match 1 : Int with
| s : String -> s | b : Bool -> b | i : Int -> i");
(run_test_eval "match 1 : Int with | 1 -> 1");
assert_equal ~msg:"Test CDuce.runtime.match.simple_var failed"
~printer:(fun x -> x) "2"
(run_test_eval "(fun f x : Int : Int ->
match x : Int with | y : Int -> x).2");
match x : Int with | _ : Int -> x).2");
assert_equal ~msg:"Test CDuce.runtime.match.medium failed"
~printer:(fun x -> x) "2"
(run_test_eval "(fun f x : Int : Int ->
match x : Int with | 1 -> 3 | x : Int -> x).2");
match x : Int with | 1 -> 3 | _ : Int -> x).2");
assert_equal ~msg:"Test CDuce.runtime.match.rec failed"
~printer:(fun x -> x) "3"
(run_test_eval "(fun f x : Int : Int ->
match x : Int with | 1 -> 3 | x : Int -> f.1).2");
match x : Int with | 1 -> 3 | _ : Int -> f.1).2");
);
"string" >:: ( fun test_ctxt ->
......@@ -294,26 +290,26 @@ let tests_eval = "CDuce runtime tests (Typed -> Lambda -> Value)" >:::
assert_equal ~msg:"Test CDuce.runtime.list.simple failed"
~printer:(fun x -> x) "1"
(run_test_eval "match [1; 2] : [Int] with
| (el : Int) :: (rest : [Int]) -> el
| x : Int -> 3");
| (el : Int) :: (_ : [Int]) -> el
| [] -> 3");
assert_equal ~msg:"Test CDuce.runtime.list.simple2 failed"
~printer:(fun x -> x) "3"
(run_test_eval "match 2 : Int with
| (el : Int) :: (rest : [Int]) -> el
| x : Int -> 3");
(run_test_eval "match [] : [Int] with
| (el : Int) :: (_ : [Int]) -> el
| [] -> 3");
assert_equal ~msg:"Test CDuce.runtime.list.tail failed"
~printer:(fun x -> x) "Abstraction(([ Int* ], [ Int* ]),{})"
(run_test_eval "fun tail x : [Int] : [Int] -> match x : [Int] with
| (el : Int) :: (rest : [Int]) -> rest");
| (_ : Int) :: (rest : [Int]) -> rest");
assert_equal ~msg:"Test CDuce.runtime.list.tail.eval failed"
~printer:(fun x -> x) "(2, (5, Atom(nil), {}), {})"
(run_test_eval "(fun tail x : [Int] : [Int] -> match x : [Int] with
| (el : Int) :: (rest : [Int]) -> rest).[1; 2; 5]");
| (_ : Int) :: (rest : [Int]) -> rest).[1; 2; 5]");
assert_equal ~msg:"Test CDuce.runtime.list.last failed"
~printer:(fun x -> x) "7"
(run_test_eval "(fun f x : [Int] : [Int] -> match x : [Int] with
| (el : Int) :: [] -> el
| (el : Int) :: (rest : [Int]) -> f.rest).[1; 2; 5; 4; 8; 7]");
| (_ : Int) :: (rest : [Int]) -> f.rest).[1; 2; 5; 4; 8; 7]");
assert_equal ~msg:"Test CDuce.runtime.list.plusone failed"
~printer:(fun x -> x) "(2, (3, (6, (5, (9, 8, {}), {}), {}), {}), {})"
(run_test_eval "(fun f x : [Int] : [Int] -> match x : [Int] with
......@@ -329,20 +325,20 @@ let tests_eval = "CDuce runtime tests (Typed -> Lambda -> Value)" >:::
~printer:(fun x -> x) "Abstraction(([ Char* ] | Int, [ Char* ] | Int),{})"
(run_test_eval "fun f x : (Int | String) : (Int | String) ->
match x : (Int | String) with
| x : Int -> 2
| x : String -> \"Piece of cake\"");
| _ : Int -> 2
| _ : String -> \"Piece of cake\"");
assert_equal ~msg:"Test CDuce.runtime.union.match_applied failed"
~printer:(fun x -> x) "2"
(run_test_eval "(fun f x : (Int | String) : (Int | String) ->
match x : (Int | String) with
| x : Int -> 2
| x : String -> \"Piece of cake\").5");
| _ : Int -> 2
| _ : String -> \"Piece of cake\").5");
assert_equal ~msg:"Test CDuce.runtime.union.match_applied2 failed"
~printer:(fun x -> x) "\"Piece of cake\""
(run_test_eval "(fun f x : (Int | String) : (Int | String) ->
match x : (Int | String) with
| x : Int -> 2
| x : String -> \"Piece of cake\").\"test\"");
| _ : Int -> 2
| _ : String -> \"Piece of cake\").\"test\"");
);
"union_precise" >:: ( fun test_ctxt ->
......@@ -391,11 +387,11 @@ let tests_eval = "CDuce runtime tests (Typed -> Lambda -> Value)" >:::
Arrow)* ], [ (`$A & Int | Char | Atom | (Any,Any) |
<(Any) (Any)>Any | Arrow)* ]),{})"
(run_test_eval "fun tail x : ['A{}] : ['A{}] -> match x : ['A{}] with
| (el : 'A{}) :: (rest : ['A{}]) -> rest");
| (_ : 'A{}) :: (rest : ['A{}]) -> rest");
assert_equal ~msg:"Test CDuce.runtime.poly.tail_applied failed"
~printer:(fun x -> x) "(7, (8, (5, Atom(nil), {}), {}), {})"
(run_test_eval "(fun tail x : ['A{}] : ['A{}] -> match x : ['A{}] with
| (el : 'A{}) :: (rest : ['A{}]) -> rest).[3; 7; 8; 5]");
| (_ : 'A{}) :: (rest : ['A{}]) -> rest).[3; 7; 8; 5]");
);
......
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