diff options
Diffstat (limited to 'tests/configuration_expression.ml')
-rw-r--r-- | tests/configuration_expression.ml | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/tests/configuration_expression.ml b/tests/configuration_expression.ml index fc4c0ec..cd28589 100644 --- a/tests/configuration_expression.ml +++ b/tests/configuration_expression.ml @@ -1,18 +1,14 @@ -open StdLabels -open OUnit2 -module Expression = ImportExpression.T module Path = ImportDataTypes.Path -open Path +open Test_migration -let printer = function - | Ok e -> ImportExpression.Repr.repr ImportConf.Path.repr e - | Error msg -> msg +let result_testable = + Alcotest.result Test_migration.expression_testable Alcotest.string let parse_dquoted = "parse_dquoted" >:: fun _ -> let expr = "match(\"\\(..\\)\", :B)" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (Function ("match", [ Literal "\\(..\\)"; Path { alias = None; column = 2 } ]))) @@ -22,7 +18,7 @@ let parse_quoted = "parse_quoted" >:: fun _ -> let expr = "match('\\(..\\)', :B)" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (Function ("match", [ Literal "\\(..\\)"; Path { alias = None; column = 2 } ]))) @@ -32,7 +28,7 @@ let concat = "concat" >:: fun _ -> let expr = ":A ^ :B" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (Concat [ @@ -44,7 +40,7 @@ let concat2 = "concat2" >:: fun _ -> let expr = "'A' ^ '_' ^ 'B'" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (Concat [ Literal "A"; Literal "_"; Literal "B" ])) result @@ -53,37 +49,37 @@ let litteral = (* The text is quoted in shall not be considered as a path *) let expr = "':A'" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Ok (Literal ":A")) result + Alcotest.check result_testable "" (Ok (Literal ":A")) result let empty = "empty" >:: fun _ -> let expr = "" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Ok Empty) result + Alcotest.check result_testable "" (Ok Empty) result let upper_nvl = "upper_nvl" >:: fun _ -> let expr = "NVL('','')" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Ok (Nvl [ Empty; Empty ])) result + Alcotest.check result_testable "" (Ok (Nvl [ Empty; Empty ])) result let lower_nvl = "lower_nvl" >:: fun _ -> let expr = "nvl('','')" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Ok (Nvl [ Empty; Empty ])) result + Alcotest.check result_testable "" (Ok (Nvl [ Empty; Empty ])) result let numeric = "numeric" >:: fun _ -> let expr = "123" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Ok (Integer "123")) result + Alcotest.check result_testable "" (Ok (Integer "123")) result let numeric_neg = "numeric_neg" >:: fun _ -> let expr = "-123" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Ok (Integer "-123")) result + Alcotest.check result_testable "" (Ok (Integer "-123")) result let op_priority = "operator_priority" >:: fun _ -> @@ -94,7 +90,7 @@ let op_priority = BOperator (GT, BOperator (Add, Integer "1", Integer "2"), Integer "2")) in - assert_equal ~printer (Ok expected) result + Alcotest.check result_testable "" (Ok expected) result let op_priority2 = "operator_priority" >:: fun _ -> @@ -105,13 +101,13 @@ let op_priority2 = BOperator (Equal, Concat [ Integer "1"; Integer "2" ], Integer "2")) in - assert_equal ~printer (Ok expected) result + Alcotest.check result_testable "" (Ok expected) result let join = "join" >:: fun _ -> let expr = "join('sep', :A, :B)" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (Join ( "sep", @@ -125,7 +121,7 @@ let join_empty = "join" >:: fun _ -> let expr = "join('', :A, :B)" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (Join ( "", @@ -139,30 +135,29 @@ let upper = "upper" >:: fun _ -> let expr = "upper('')" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Ok (Function' (Upper, [ Empty ]))) result + Alcotest.check result_testable "" (Ok (Function' (Upper, [ Empty ]))) result let trim = "trim" >:: fun _ -> let expr = "trim('')" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Ok (Function' (Trim, [ Empty ]))) result + Alcotest.check result_testable "" (Ok (Function' (Trim, [ Empty ]))) result (** Extract the columns from a window function *) let fold_values = "fold_values" >:: fun _ -> + let open Path in (* The expression we want to test *) let expr = - Expression.Window + ImportExpression.T.Window ( Previous (Path { alias = None; column = 1 }), [ Path { alias = None; column = 2 } ], [ Path { alias = None; column = 3 } ] ) in - (* Extract the columns from the expression. The result is sorted because - the order is not preserved during the extraction. *) let result = - Expression.fold_values ~init:[] ~f:(fun acc v -> v :: acc) expr - |> List.sort ~cmp:Path.compare + ImportExpression.T.fold_values ~init:[] ~f:(fun acc v -> v :: acc) expr + |> List.rev in let expected = @@ -173,21 +168,23 @@ let fold_values = ] in - assert_equal expected result + Alcotest.check + (Alcotest.list @@ Test_migration.make_test (module Path)) + "" expected result let bad_quote = "bad_quote" >:: fun _ -> let expr = "':source.A" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer (Error "Unclosed quote at line 1 : \"':source.A\"") - result + Alcotest.check result_testable "" + (Error "Unclosed quote at line 1 : \"':source.A\"") result let nested_expression = "nested_expression" >:: fun _ -> let expr = "1 = (1 = 0)" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (BOperator ( Equal, @@ -199,7 +196,7 @@ let priority_equality = "priority_equality" >:: fun _ -> let expr = "1 = 1 = 0" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (BOperator (Equal, Integer "1", BOperator (Equal, Integer "1", Integer "0")))) @@ -209,7 +206,7 @@ let priority_operator_and = "priority_equality" >:: fun _ -> let expr = "1 and 1 = 0" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (BOperator (And, Integer "1", BOperator (Equal, Integer "1", Integer "0")))) result @@ -218,7 +215,7 @@ let priority_operator_or = "priority_equality" >:: fun _ -> let expr = "1 <> 1 or 0" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Ok (BOperator (Or, BOperator (Different, Integer "1", Integer "1"), Integer "0"))) @@ -229,7 +226,7 @@ let unknown_function = let expr = "function()" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Error "Unknown function or wrong number of arguments for 'function'") result @@ -238,7 +235,7 @@ let wrong_arguments = let expr = "if()" in let result = ImportConf.expression_from_string expr in - assert_equal ~printer + Alcotest.check result_testable "" (Error "Unknown function or wrong number of arguments for 'if'") result let test_suit = |