aboutsummaryrefslogtreecommitdiff
path: root/tests/expression_query.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2025-01-17 20:48:43 +0100
committerSébastien Dailly <sebastien@dailly.me>2025-01-22 12:22:26 +0100
commit8e012f4804ecf1665819e761283120a3c0e73643 (patch)
treec168efe3e1f0edf5e45695c643e62b3e5447be37 /tests/expression_query.ml
parentbf2af26d896bb499f2c312a4f1ecd3210e2d7780 (diff)
Switched from OUnit to alcotest
Diffstat (limited to 'tests/expression_query.ml')
-rw-r--r--tests/expression_query.ml51
1 files changed, 26 insertions, 25 deletions
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 =
[