blob: d7bb333b01029d642dc54be5d9df48b58556c346 (
plain)
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
41
42
43
44
45
|
module Get_type = Qsp_syntax.Get_type
module T = Qsp_syntax.T
let _position = (Lexing.dummy_pos, Lexing.dummy_pos)
let type_of : Get_type.t Alcotest.testable =
Alcotest.testable Get_type.pp Get_type.equal
let add_number () =
let actual =
Get_type.boperator _position T.Plus
(Get_type.integer _position "0")
(Get_type.integer _position "1")
in
let expected = Get_type.(Raw Integer) in
let msg = "Adding integer" in
Alcotest.(check' type_of ~msg ~expected ~actual)
let add_literal_number () =
let actual =
Get_type.boperator _position T.Plus
(Get_type.literal _position [ T.Text "2" ])
(Get_type.integer _position "1")
in
let expected = Get_type.(Raw Integer) in
let msg = "A string containing integer is considered as integer" in
Alcotest.(check' type_of ~msg ~expected ~actual)
let concat_text () =
let actual =
Get_type.boperator _position T.Plus
(Get_type.literal _position [ T.Text "a" ])
(Get_type.integer _position "1")
in
let expected = Get_type.(Raw String) in
let msg = "Concatenate" in
Alcotest.(check' type_of ~msg ~expected ~actual)
let test =
( "Type expression",
[
Alcotest.test_case "int + int" `Quick add_number;
Alcotest.test_case "'int' + int" `Quick add_literal_number;
Alcotest.test_case "str + int" `Quick concat_text;
] )
|