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
1eb86124
Commit
1eb86124
authored
Apr 16, 2014
by
Julien Lopez
Browse files
[TESTS][LAMBDA] Add tests; fix a test on sequences; `nil defined but not used
parent
385e678c
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/lambda/src/compute.ml
View file @
1eb86124
...
...
@@ -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:
\n
Unbound 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:
\n
Unbound 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
...
...
tests/lambda/src/main.ml
View file @
1eb86124
...
...
@@ -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
]"
);
);
]
...
...
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