Commit 2183f6c1 authored by Julien Lopez's avatar Julien Lopez

Remove parsing of strings in comments.

[TESTS] Add functions nth and rev and tests for stdlib/list
parent 5e86318a
......@@ -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"
| _ ->
......
......@@ -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
......@@ -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)
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