From 8e012f4804ecf1665819e761283120a3c0e73643 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Fri, 17 Jan 2025 20:48:43 +0100 Subject: Switched from OUnit to alcotest --- tests/expression_query.ml | 51 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'tests/expression_query.ml') diff --git a/tests/expression_query.ml b/tests/expression_query.ml index e2abc43..367a1e2 100644 --- a/tests/expression_query.ml +++ b/tests/expression_query.ml @@ -1,13 +1,11 @@ -open OUnit2 module T = ImportExpression.T module Expr = Expression_builder module M = Expr.Make (ImportExpression.Query.Query) +open Test_migration let eval = M.eval ~path_repr:(fun formatter n -> Format.fprintf formatter "%s" n) -let printer = Fun.id - let test_expr ?(nested = ImportExpression.Query.QueryParameter.Literal) expr = let buffer = Buffer.create 16 in let formatter = Format.formatter_of_buffer buffer in @@ -15,26 +13,29 @@ let test_expr ?(nested = ImportExpression.Query.QueryParameter.Literal) expr = Format.pp_print_flush formatter (); Buffer.contents buffer +let assert_equal expected actual = + Alcotest.check Alcotest.string expected expected actual + let empty = "empty" >:: fun _ -> let expr = eval Expr.empty in let content = test_expr expr and expected = "''" in - assert_equal ~printer expected content + assert_equal expected content let litteral = "literal" >:: fun _ -> let expr = eval Expr.literal_test in let content = test_expr expr and expected = "'test'" in - assert_equal ~printer expected content + assert_equal expected content let litteral_quoted = "literal_quoted" >:: fun _ -> let expr = eval Expr.literal_quoted in let content = test_expr expr and expected = "'\''" in - assert_equal ~printer expected content + assert_equal expected content let litteral_raw = "literal_raw" >:: fun _ -> @@ -42,7 +43,7 @@ let litteral_raw = let nested = ImportExpression.Query.QueryParameter.(Raw Literal) in let content = test_expr expr ~nested and expected = "test" in - assert_equal ~printer expected content + assert_equal expected content let path = "path" >:: fun _ -> @@ -50,28 +51,28 @@ let path = let expr = eval @@ Expr.path "test" in let content = test_expr expr and expected = "test" in - assert_equal ~printer expected content + assert_equal expected content let concat = "concat" >:: fun _ -> let expr = eval Expr.concat in let content = test_expr expr and expected = "'' || 'test'" in - assert_equal ~printer expected content + assert_equal expected content let nvl = "nvl" >:: fun _ -> let expr = eval @@ Expr.nvl Expr.empty Expr.literal_test in let content = test_expr expr and expected = "COALESCE('', 'test')" in - assert_equal ~printer expected content + assert_equal expected content let upper = "upper" >:: fun _ -> let expr = eval @@ Expr.function' T.Upper [ Expr.literal_test ] in let content = test_expr expr and expected = "UPPER('test')" in - assert_equal ~printer expected content + assert_equal expected content let join = "join" >:: fun _ -> @@ -81,62 +82,62 @@ let join = in let content = test_expr expr and expected = "CONCAT(',', '', 'test')" in - assert_equal ~printer expected content + assert_equal expected content let boperator_eq = "boperator_eq" >:: fun _ -> let expr = eval @@ Expr.equal Expr.empty Expr.literal_test in let content = test_expr expr and expected = "''='test'" in - assert_equal ~printer expected content + assert_equal expected content let boperator_div = "boperator_div" >:: fun _ -> let expr = eval @@ Expr.divide Expr.integer_one Expr.integer_zero in let content = test_expr expr and expected = "CAST(1 AS REAL)/0" in - assert_equal ~printer expected content + assert_equal expected content let boperator_neq = "boperator_neq" >:: fun _ -> let expr = eval @@ Expr.different Expr.empty Expr.literal_test in let content = test_expr expr and expected = "''<>'test'" in - assert_equal ~printer expected content + assert_equal expected content let expr = "expr" >:: fun _ -> let expr = eval Expr.expr in let content = test_expr expr and expected = "(test NOT NULL)" in - assert_equal ~printer expected content + assert_equal expected content let unify_int = "unify_int" >:: fun _ -> let expr = eval @@ Expr.equal (Expr.path "external") Expr.integer_zero in let content = test_expr expr and expected = "COALESCE(external,0)=0" in - assert_equal ~printer expected content + assert_equal expected content let unify_string = "unify_string" >:: fun _ -> let expr = eval @@ Expr.equal (Expr.path "external") Expr.literal_zero in let content = test_expr expr and expected = "COALESCE(external,'')='0'" in - assert_equal ~printer expected content + assert_equal expected content let in_string = "in_string" >:: fun _ -> let expr = eval @@ Expr.in_ (Expr.path "external") [ Expr.literal_zero ] in let content = test_expr expr and expected = "COALESCE(external,'') IN('0')" in - assert_equal ~printer expected content + assert_equal expected content let not_in_string = "in_string" >:: fun _ -> let expr = eval @@ Expr.not_in (Expr.path "external") [ Expr.literal_zero ] in let content = test_expr expr and expected = "COALESCE(external,'') NOT IN('0')" in - assert_equal ~printer expected content + assert_equal expected content (* Evaluate the max function *) let max = @@ -151,7 +152,7 @@ let max = UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)" in - assert_equal ~printer expected content + assert_equal expected content let in_int = "in_int" >:: fun _ -> @@ -160,7 +161,7 @@ let in_int = @@ Expr.in_ (Expr.path "external") [ Expr.integer_zero; Expr.integer_one ] in let content = test_expr expr and expected = "COALESCE(external,0) IN(0, 1)" in - assert_equal ~printer expected content + assert_equal expected content let counter_no_order = "counter_no_order" >:: fun _ -> @@ -169,7 +170,7 @@ let counter_no_order = let content = test_expr expr and expected = "COUNT() OVER (PARTITION BY :A)" in - assert_equal ~printer expected content + assert_equal expected content let counter_order = "counter_no_order" >:: fun _ -> @@ -178,7 +179,7 @@ let counter_order = let content = test_expr expr and expected = "ROW_NUMBER() OVER (PARTITION BY :A ORDER BY :B)" in - assert_equal ~printer expected content + assert_equal expected content let cmp = "cmp" >:: fun _ -> @@ -195,7 +196,7 @@ let cmp = ]) in let content = test_expr expr and expected = "IIF(0=1, 0, IIF(0>1, 1, -1))" in - assert_equal ~printer expected content + assert_equal expected content let test_suit = [ -- cgit v1.2.3