Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cduce
cduce
Commits
5bb58470
Commit
5bb58470
authored
Apr 30, 2014
by
Julien Lopez
Browse files
[TESTS][LAMBDA] Cleaning tests; better definition of "_"
parent
f7a63894
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/lambda/src/compute.ml
View file @
5bb58470
...
...
@@ -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
...
...
tests/lambda/src/main.ml
View file @
5bb58470
...
...
@@ -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]"
);
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment