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
2183f6c1
Commit
2183f6c1
authored
Jun 24, 2014
by
Julien Lopez
Browse files
Remove parsing of strings in comments.
[TESTS] Add functions nth and rev and tests for stdlib/list
parent
5e86318a
Changes
3
Hide whitespace changes
Inline
Side-by-side
parser/ulexer.ml
View file @
2183f6c1
...
...
@@ -315,14 +315,6 @@ and comment start = lexer
comment
start
lexbuf
|
"*)"
->
()
|
'
"' ->
string (L.lexeme_start lexbuf) '"
'
lexbuf
;
clear_buff
()
;
comment
start
lexbuf
|
"'"
->
string
(
L
.
lexeme_start
lexbuf
)
'\''
lexbuf
;
clear_buff
()
;
comment
start
lexbuf
|
eof
->
error
start
(
start
+
2
)
"Unterminated comment"
|
_
->
...
...
tests/stdlib/list/list.cd
View file @
2183f6c1
...
...
@@ -8,10 +8,25 @@ let hd ([('a)+] -> 'a) [el _*] -> el
let tl ([('a)+] -> [('a)*])
| [el] -> [el]
| [_; t] -> t
| [_; rest] -> rest
let nth (l : [('a)*])(n : Int) : 'a =
let aux (l : [('a)*])(n : Int) : 'a = match l with
| [] -> raise "Failure \"List.nth\""
| [el; rest] -> if n >> 0 then aux rest (n - 1) else el in
if n << 0 then raise "Invalid_argument \"List.nth\"" else aux l n
(* Typing error
let rev (l : [('a)*]) : [('a)*] =
let aux (l : [('a)*])(res : [('a)*]) : [('a)*] = match l with
| [] -> res
| [el; rest] -> aux rest ([el] @ res) in
aux l []
*)
(* Iterators *)
let iter (f : ('a -> []))(l : [('a)*]) : [] = match l with
| [] -> []
| [el rest::('a)*] -> f el; iter f rest
| [el; rest] -> f el; iter f rest
tests/stdlib/list/listtest.cd
View file @
2183f6c1
...
...
@@ -20,23 +20,41 @@ let run_test_suite_debug (l : [(Latin1, ('a), ('a)) *]) : [] = match l with
(* Tests *)
let length_tests = [
("Test stdlib.length.1 failed", length [2 5 4], 3)
("Test stdlib.length.2 failed", length [], 0)
("Test stdlib.
list.
length.1 failed", length [2 5 4], 3)
("Test stdlib.
list.
length.2 failed", length [], 0)
] in
let hd_tests = [
("Test stdlib.hd.1 failed", hd [1], 1)
("Test stdlib.hd.2 failed", hd [2 5 4], 2)
("Test stdlib.
list.
hd.1 failed", hd [1], 1)
("Test stdlib.
list.
hd.2 failed", hd [2 5 4], 2)
] in
let tl_tests = [
("Test stdlib.tl.1 failed", tl [1], [1])
("Test stdlib.tl.2 failed", tl [2 5 4], [5 4])
("Test stdlib.
list.
tl.1 failed", tl [1], [1])
("Test stdlib.
list.
tl.2 failed", tl [2 5 4], [5 4])
] in
let nth_tests = [
("Test stdlib.list.nth.1 failed", nth [1 2 3] 1, 2)
("Test stdlib.list.nth.2 failed", nth [4 5 6 7] 3, 7)
("Test stdlib.list.nth.3 failed", try nth [4 5 6 7] 4 with e -> e,
"Failure \"List.nth\"")
("Test stdlib.list.nth.4 failed", try nth [4 5 6 7] -1 with e -> e,
"Invalid_argument \"List.nth\"")
] in
(*
let rev_tests = [
("Test stdlib.list.rev.1 failed", rev [], [])
("Test stdlib.list.rev.2 failed", rev [1 7 5 2], [2 5 7 1])
] in
*)
(* Run tests *)
run_test_suite length_tests;
run_test_suite hd_tests;
run_test_suite tl_tests;
run_test_suite nth_tests;
(* run_test_suite rev_tests; *)
print (string_of !nb_success); print " / "; print (string_of !nb_tests)
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