-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathStatementParserTest.ml
More file actions
40 lines (31 loc) · 1.21 KB
/
StatementParserTest.ml
File metadata and controls
40 lines (31 loc) · 1.21 KB
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
37
38
39
40
(*
Part of the Austral project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE file for details.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*)
open OUnit2
open Austral_core.Cst
open Austral_core.ParserInterface
open TestUtil
let p = parse_stmt
let peq (s: string) (v: 'a) =
eq v (p s)
let test_if _ =
(* Discarding block *)
let db e = CBlock [CDiscarding e]
in
peq "if true then nil; end if;" (CIf (CBoolConstant true, db CNilConstant, CSkip));
peq "if true then nil; else nil; end if;" (CIf (CBoolConstant true, db CNilConstant, db CNilConstant));
peq "if true then nil; else if false then nil; end if;" (CIf (CBoolConstant true, db CNilConstant, CIf (CBoolConstant false, db CNilConstant, CSkip)));
peq "if true then nil; else if false then nil; else nil; end if;" (CIf (CBoolConstant true, db CNilConstant, CIf (CBoolConstant false, db CNilConstant, db CNilConstant)))
let test_return _ =
peq "return 123;" (CReturn (CIntConstant "123"))
let test_skip _ =
peq "skip;" CSkip
let suite =
"Statement parser" >::: [
"If statement" >:: test_if;
"Return statement" >:: test_return;
"Skip statement" >:: test_skip
]
let _ = run_test_tt_main suite