aboutsummaryrefslogtreecommitdiff
path: root/test/dup_cases.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/dup_cases.ml')
-rw-r--r--test/dup_cases.ml128
1 files changed, 128 insertions, 0 deletions
diff --git a/test/dup_cases.ml b/test/dup_cases.ml
new file mode 100644
index 0000000..4ae95b1
--- /dev/null
+++ b/test/dup_cases.ml
@@ -0,0 +1,128 @@
+module Check = Make_checkTest.M (Qsp_syntax.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 = Warn;
+ 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 = Warn;
+ 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;
+ ] )