aboutsummaryrefslogtreecommitdiff
path: root/test/dup_cases.ml
blob: 8d4274ed12a605a71b561ffc42c52b089c5fed6b (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
module Check = Make_checkTest.M (Qsp_checks.Dup_test)

let _position = (Lexing.dummy_pos, Lexing.dummy_pos)

let _test_instruction : string -> Qsp_syntax.Report.t list -> unit =
  Check._test_instruction

(** Two differents test shall not report error *)
let ok () =
  _test_instruction {|
if 1: 
    0
elseif 2:
    0
end

if 3: 
    0
end
|} []

(** The rnd function can generate different result, this is not a warning *)
let ok_rnd () = _test_instruction {|
if rnd: 
    0
elseif rnd:
    0
end
|} []

(** The same test in two differents block shall be considered as a duplicate.
 *)
let ok_act () =
  _test_instruction
    {|

act "action":
    if 1: 
        0
    end
end

act "action":
    if 1: 
        0
    end
end
|}
    []

let duplicate_case () =
  _test_instruction
    {|
if 0 = '1': 
    0
elseif 0 = '1':
    0
end
|}
    [
      {
        level = Error;
        loc = _position;
        message = "This case is duplicated line(s) 5";
      };
    ]

let duplicate_root_test () =
  _test_instruction
    {|
if args[0] = 1: 
    0
end
if args[0] = 1: 
    0
elseif 1:
    0
end
|}
    [
      {
        level = Error;
        loc = _position;
        message = "This case is duplicated line(s) 6";
      };
    ]

let duplicate_nonroot_test () =
  _test_instruction
    {|
act 0:
    if 1: 
        0
    end
    if 1:
        0
    end
end

if 0:
    if 1: 
        0
    end
    if 1:
        0
    end
else
    if 1: 
        0
    end
    if 1:
        0
    end
end
|}
    []

let test =
  ( "Duplicates predicates checker",
    [
      Alcotest.test_case "Ok" `Quick ok;
      Alcotest.test_case "Ok rnd" `Quick ok_rnd;
      Alcotest.test_case "Ok_act" `Quick ok_act;
      Alcotest.test_case "duplicate_cases" `Quick duplicate_case;
      Alcotest.test_case "duplicate_root" `Quick duplicate_root_test;
      Alcotest.test_case "duplicate_nonroottest" `Quick duplicate_nonroot_test;
    ] )