diff options
author | Chimrod <> | 2024-03-27 15:50:56 +0100 |
---|---|---|
committer | Chimrod <> | 2024-03-27 15:50:56 +0100 |
commit | 246d3c93e6c628e333c047e225edd284ed156ecb (patch) | |
tree | b0e017132fdf587b83269441d1c54b2446cf0c02 /test | |
parent | 14504f36b603984c14b05995a8928cbd40dfa670 (diff) | |
parent | baa258ac91df8a80209b322e8d42c5deb2ada536 (diff) |
Added the check (I should have had order my commit betters)
Diffstat (limited to 'test')
-rw-r--r-- | test/dup_cases.ml | 128 | ||||
-rw-r--r-- | test/qsp_parser_test.ml | 1 |
2 files changed, 129 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; + ] ) diff --git a/test/qsp_parser_test.ml b/test/qsp_parser_test.ml index 609da3f..4754a15 100644 --- a/test/qsp_parser_test.ml +++ b/test/qsp_parser_test.ml @@ -8,4 +8,5 @@ let () = Dead_end.test; Nested_string.test; Location.test; + Dup_cases.test; ] |