-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_parser.ml
36 lines (32 loc) · 1.26 KB
/
test_parser.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
open Lqccs
let assertException source ind =
try
let lexbuf = Lexing.from_string ~with_positions:true source in
Parsing.parse Scanner.next_token lexbuf |> ignore;
Printf.printf "[FAIL] Test #%2d\n" ind
with
| Scanner.Lexing_error (_, msg)
| Parsing.Syntax_error (_, msg) ->
Printf.printf "[ OK ] Test #%2d: %s\n" ind msg
let assertNotException source ind =
try
let lexbuf = Lexing.from_string ~with_positions:true source in
Parsing.parse Scanner.next_token lexbuf |> ignore;
Printf.printf "[ OK ] Test #%2d\n" ind
with
| Scanner.Lexing_error (_, msg)
| Parsing.Syntax_error (_, msg) ->
Printf.printf "[FAIL] Test #%2d: %s\n" ind msg
let tests = [
assertNotException "M(q1 > x).Discard() \\ ()";
assertException "M(q1 > x).Discard(). \\ ()";
assertNotException "c1:int?y.M(q1 > x).Discard(q1) \\ (c1: int)";
assertNotException "H(q1).M(q1 > x).((if x=0 then a:int!1 else b:int!1) || Discard(q1)) \\ ()";
assertException "c:int?q1.Discard(q1) \\ ()"; (* cannot receive on a variable that starts with q *)
assertException "Discard() ++ (Discard() || Discard()) \\ ()"; (* cannot use par inside a choice *)
]
let _ =
Printf.printf "\n--- Parser ---\n";
List.iteri (fun ind funtest ->
funtest (ind + 1)
) tests