diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2025-03-17 09:11:25 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2025-03-17 18:59:32 +0100 |
commit | 8b8b730d3ba98d6c9e4e6274844641043b5fefbb (patch) | |
tree | 4cb60dafa05b479d0ca287d501a51db88cecaaa4 /tests | |
parent | 7bfbb67d83011f3e1845dcb9e44c3b6a5e93a9da (diff) |
Moved the syntax module in its own library
Diffstat (limited to 'tests')
-rw-r--r-- | tests/analyser_dependency.ml | 2 | ||||
-rw-r--r-- | tests/analyser_filters.ml | 18 | ||||
-rw-r--r-- | tests/analyser_query_test.ml | 3 | ||||
-rw-r--r-- | tests/confLoader.ml | 8 | ||||
-rw-r--r-- | tests/configuration_toml.ml | 2 | ||||
-rw-r--r-- | tests/dune | 2 | ||||
-rw-r--r-- | tests/expression_repr.ml | 2 | ||||
-rw-r--r-- | tests/importCSV_test.ml | 15 | ||||
-rw-r--r-- | tests/importConf_test.ml | 5 | ||||
-rw-r--r-- | tests/sql_db.ml | 49 | ||||
-rw-r--r-- | tests/test_migration.ml | 8 |
11 files changed, 65 insertions, 49 deletions
diff --git a/tests/analyser_dependency.ml b/tests/analyser_dependency.ml index 8409d73..511b706 100644 --- a/tests/analyser_dependency.ml +++ b/tests/analyser_dependency.ml @@ -1,7 +1,7 @@ open StdLabels module A = ImportAnalyser.Dependency module Cont = ImportContainers -module Syntax = ImportConf.Syntax +module Syntax = ImporterSyntax module Expression = ImportExpression.T module Table = ImportDataTypes.Table open ConfLoader diff --git a/tests/analyser_filters.ml b/tests/analyser_filters.ml index c329af8..864cab7 100644 --- a/tests/analyser_filters.ml +++ b/tests/analyser_filters.ml @@ -1,4 +1,3 @@ -module CTE = ImportConf.CTE module Filters = ImportAnalyser.Filters module Chunk = ImportAnalyser.Chunk @@ -29,7 +28,9 @@ let empty_predicates () = The path is identified as pointing to a numeric column, and the associated query will replace null with 0. *) let simple_filter () = - let filter = CTE.of_filters Expression_builder.[ equal integer_one path' ] in + let filter = + ImporterSyntax.CTE.of_filters Expression_builder.[ equal integer_one path' ] + in let chunk_links = Chunk.create () in let chunk_predicates = Filters.generate_sql ~conf filter chunk_links in @@ -47,7 +48,8 @@ let simple_filter () = query will replace null with empty string. *) let multiple_filters () = let filter = - CTE.of_filters Expression_builder.[ integer_one; equal path' literal_zero ] + ImporterSyntax.CTE.of_filters + Expression_builder.[ integer_one; equal path' literal_zero ] in let chunk_links = Chunk.create () in let chunk_predicates = Filters.generate_sql ~conf filter chunk_links in @@ -66,7 +68,7 @@ let multiple_filters () = (** Create a simple configuration with a group expression and no other filters *) let group_filter () = - let filter = CTE.of_filters [ group_expression ] in + let filter = ImporterSyntax.CTE.of_filters [ group_expression ] in let chunk_links = Chunk.create () in let chunk_predicates = Filters.generate_sql ~conf filter chunk_links in @@ -90,7 +92,7 @@ let group_filter () = let expression_with_group () = let filter = - CTE.of_filters + ImporterSyntax.CTE.of_filters Expression_builder.[ equal integer_one path'; group_expression ] in let chunk_links = Chunk.create () in @@ -118,7 +120,7 @@ let expression_with_group () = included inside the CTE but in the main query. *) let group_with_expression () = let filter = - CTE.of_filters + ImporterSyntax.CTE.of_filters Expression_builder.[ group_expression; equal integer_one path' ] in let chunk_links = Chunk.create () in @@ -145,7 +147,9 @@ let group_with_expression () = (** Test the configuration with two group, each one generating it’s own CTE in the query *) let group_with_group () = - let filter = CTE.of_filters [ group_expression; group_expression ] in + let filter = + ImporterSyntax.CTE.of_filters [ group_expression; group_expression ] + in let chunk_links = Chunk.create () in let chunk_predicates = Filters.generate_sql ~conf filter chunk_links in diff --git a/tests/analyser_query_test.ml b/tests/analyser_query_test.ml index 16a9bca..fd8914b 100644 --- a/tests/analyser_query_test.ml +++ b/tests/analyser_query_test.ml @@ -1,8 +1,7 @@ open StdLabels module A = ImportAnalyser.Dependency module Q = ImportAnalyser.Query -module C = ImportConf -module Syntax = ImportConf.Syntax +module Syntax = ImporterSyntax module Expr = Expression_builder open Test_migration diff --git a/tests/confLoader.ml b/tests/confLoader.ml index 692cda9..13f9840 100644 --- a/tests/confLoader.ml +++ b/tests/confLoader.ml @@ -1,8 +1,8 @@ -let load' : string -> (ImportConf.Syntax.t, string) Result.t = +let load' : string -> (ImporterSyntax.t, string) Result.t = fun content -> Otoml.Parser.from_string content |> ImportConf.t_of_toml (** Read the configuration in toml and return the internal representation *) -let load : string -> ImportConf.Syntax.t = +let load : string -> ImporterSyntax.t = fun content -> Result.get_ok (load' content) let conf = @@ -37,7 +37,7 @@ let external_table_other = ImportDataTypes.Table.{ file = "other.xlsx"; tab = 1; name = "other" } let external_other = - ImportConf.Syntax.Extern. + ImporterSyntax.Extern. { intern_key = Path { alias = None; column = 1 }; target = external_table_other; @@ -50,7 +50,7 @@ let external_table_last = ImportDataTypes.Table.{ file = "last.xlsx"; tab = 1; name = "last_file" } let external_last = - ImportConf.Syntax.Extern. + ImporterSyntax.Extern. { intern_key = Path { alias = Some "other"; column = 1 }; target = external_table_last; diff --git a/tests/configuration_toml.ml b/tests/configuration_toml.ml index e51c727..0a36faf 100644 --- a/tests/configuration_toml.ml +++ b/tests/configuration_toml.ml @@ -34,7 +34,7 @@ let test_suit = | Error s -> raise (Failure s) | Ok result -> let expected = - ImportConf.Syntax.Extern. + ImporterSyntax.Extern. { target = { file = ""; tab = 1; name = "target" }; extern_key = Literal "_B"; @@ -6,10 +6,10 @@ otoml sqlite3 fmt + importerSyntax importConf importAnalyser importContainers - importCSV importDataTypes importErrors importExpression diff --git a/tests/expression_repr.ml b/tests/expression_repr.ml index 20a0484..9112704 100644 --- a/tests/expression_repr.ml +++ b/tests/expression_repr.ml @@ -4,7 +4,7 @@ module Expr = Expression_builder module M = Expr.Make (ImportExpression.Repr.E) open Test_migration -let eval = M.eval ~path_repr:ImportCSV.Csv.column_to_string +let eval = M.eval ~path_repr:ImportDataTypes.Path.column_to_string let test_expr expr = ImportExpression.Repr.E.observe ~top:true expr let assert_equal expected actual = diff --git a/tests/importCSV_test.ml b/tests/importCSV_test.ml index 8d83688..748c58b 100644 --- a/tests/importCSV_test.ml +++ b/tests/importCSV_test.ml @@ -1,4 +1,3 @@ -open ImportCSV open Test_migration let assert_equal = Alcotest.(check int "") @@ -8,19 +7,23 @@ let float_repr = let () = Alcotest.(check string) "Float repr" "3873921.620000" - ImportCSV.DataType.(to_string "C" (Float 3873921.62)) + ImportDataTypes.Value.(to_string "C" (Float 3873921.62)) in () let test_suit = [ - ("Column A" >:: fun () -> assert_equal 1 (Csv.column_of_string "A")); - ("Column a" >:: fun () -> assert_equal 1 (Csv.column_of_string "a")); + ( "Column A" >:: fun () -> + assert_equal 1 (ImportDataTypes.Path.column_of_string "A") ); + ( "Column a" >:: fun () -> + assert_equal 1 (ImportDataTypes.Path.column_of_string "a") ); ( "Column name" >:: fun () -> let () = for i = 1 to 1_000 do - let column_name = Csv.column_to_string i in - let column_index = Csv.column_of_string column_name in + let column_name = ImportDataTypes.Path.column_to_string i in + let column_index = + ImportDataTypes.Path.column_of_string column_name + in assert_equal i column_index done diff --git a/tests/importConf_test.ml b/tests/importConf_test.ml index 481b66c..5f98423 100644 --- a/tests/importConf_test.ml +++ b/tests/importConf_test.ml @@ -9,13 +9,14 @@ let check = Alcotest.(check (list Test_migration.extern_testable) "") configuration. *) let test_get_dependencies_for_source = "get_dependancies_for_table" >:: fun _ -> - let result = ImportConf.get_dependancies_for_table conf conf.source + let result = ImporterSyntax.get_dependancies_for_table conf conf.source and expected = [ external_other ] in check expected result let test_get_dependencies_for_other = "get_dependancies_for_table" >:: fun _ -> - let result = ImportConf.get_dependancies_for_table conf external_table_other + let result = + ImporterSyntax.get_dependancies_for_table conf external_table_other and expected = [ external_last ] in check expected result diff --git a/tests/sql_db.ml b/tests/sql_db.ml index ab402bc..34f5b12 100644 --- a/tests/sql_db.ml +++ b/tests/sql_db.ml @@ -67,10 +67,10 @@ columns = [ ":B", ":E"]|} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 123); (1, Integer 2); (4, Integer 5) ] ] ~expected: - (Ok ImportCSV.DataType.[ [| Content "123_"; Integer 2; Integer 5 |] ]) + (Ok ImportDataTypes.Value.[ [| Content "123_"; Integer 2; Integer 5 |] ]) (** Ensure the behavior of the sum function when a filter is given. It is expected to accumulate the values over each line *) @@ -87,7 +87,7 @@ columns = [ "sum(:C, [:B], [:A])", ]|} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (1, Content "A"); (2, Integer 100) ]; [ (0, Integer 2); (1, Content "A"); (2, Integer 100) ]; @@ -95,7 +95,7 @@ columns = [ ] ~expected: (Ok - ImportCSV.DataType. + ImportDataTypes.Value. [ [| Integer 1; Integer 100 |]; [| Integer 2; Integer 200 |]; @@ -115,13 +115,18 @@ columns = [ "sum(:C, [], [])", ]|} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (2, Integer 100) ]; [ (0, Integer 2); (2, Integer 100) ]; ] ~expected: - (Ok [ [| ImportCSV.DataType.Integer 1; ImportCSV.DataType.Integer 200 |] ]) + (Ok + [ + [| + ImportDataTypes.Value.Integer 1; ImportDataTypes.Value.Integer 200; + |]; + ]) (** Ensure the behavior of the sum function when no filter is given. It is expected to get the total sum for each line *) @@ -138,7 +143,7 @@ columns = [ "sum(:C, [], [:A])", ]|} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (2, Integer 100) ]; [ (0, Integer 2); (2, Integer 100) ]; @@ -146,8 +151,12 @@ columns = [ ~expected: (Ok [ - [| ImportCSV.DataType.Integer 1; ImportCSV.DataType.Integer 100 |]; - [| ImportCSV.DataType.Integer 2; ImportCSV.DataType.Integer 200 |]; + [| + ImportDataTypes.Value.Integer 1; ImportDataTypes.Value.Integer 100; + |]; + [| + ImportDataTypes.Value.Integer 2; ImportDataTypes.Value.Integer 200; + |]; ]) let sum_group = @@ -163,7 +172,7 @@ columns = [ "sum(:C, [:A], [])", ]|} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (2, Integer 100) ]; [ (0, Integer 1); (2, Integer 100) ]; @@ -171,7 +180,7 @@ columns = [ ] ~expected: (Ok - ImportCSV.DataType. + ImportDataTypes.Value. [ [| Integer 1; Integer 200 |]; [| Integer 1; Integer 200 |]; @@ -193,7 +202,7 @@ columns = [ "sum(:C, [:A], [])", ]|} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (2, Integer 100) ]; [ (0, Integer 1); (2, Integer 100) ]; @@ -201,7 +210,7 @@ columns = [ ] ~expected: (Ok - ImportCSV.DataType. + ImportDataTypes.Value. [ [| Integer 1; Integer 200 |]; [| Integer 2; Integer 100 |] ]) let filter_group = @@ -222,13 +231,13 @@ filters = [ |} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (1, Integer 100) ]; [ (0, Integer 2); (1, Integer 150) ]; [ (0, Integer 3); (1, Integer 200) ]; ] - ~expected:(Ok ImportCSV.DataType.[ [| Integer 3 |] ]) + ~expected:(Ok ImportDataTypes.Value.[ [| Integer 3 |] ]) (** The first filter will prevent the max value to pop, and only the second one will be reported *) @@ -251,13 +260,13 @@ filters = [ |} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (1, Integer 100) ]; [ (0, Integer 2); (1, Integer 150) ]; [ (0, Integer 3); (1, Integer 200) ]; ] - ~expected:(Ok ImportCSV.DataType.[ [| Integer 2 |] ]) + ~expected:(Ok ImportDataTypes.Value.[ [| Integer 2 |] ]) (** In this case, we first filter the line and keep only the max value, but the second filter will match the result and will produce an empty list *) @@ -280,7 +289,7 @@ filters = [ |} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (1, Integer 100) ]; [ (0, Integer 2); (1, Integer 150) ]; @@ -311,13 +320,13 @@ filters = [ |} ~input: - ImportCSV.DataType. + ImportDataTypes.Value. [ [ (0, Integer 1); (1, Integer 100) ]; [ (0, Integer 2); (1, Integer 150) ]; [ (0, Integer 3); (1, Integer 200) ]; ] - ~expected:(Ok [ [| ImportCSV.DataType.Integer 1 |] ]) + ~expected:(Ok [ [| ImportDataTypes.Value.Integer 1 |] ]) let test_suit = [ diff --git a/tests/test_migration.ml b/tests/test_migration.ml index e26f354..17e48cc 100644 --- a/tests/test_migration.ml +++ b/tests/test_migration.ml @@ -27,7 +27,7 @@ let sql_testable = let csv_data_type_testable = make_test (module struct - type t = ImportCSV.DataType.t = + type t = ImportDataTypes.Value.t = | Null | Error of string | Content of string @@ -38,7 +38,7 @@ let csv_data_type_testable = let csv_result = Alcotest.(list @@ array @@ csv_data_type_testable) let data_type_testable = make_test (module ImportDataTypes.Types) -let extern_testable = make_test (module ImportConf.Syntax.Extern) +let extern_testable = make_test (module ImporterSyntax.Extern) let table_testable = make_test (module ImportDataTypes.Table) let int_container_testable = make_test (module ImportContainers.IntSet) @@ -70,11 +70,11 @@ let chunk = let syntax = make_test (module struct - type t = ImportConf.Syntax.t + type t = ImporterSyntax.t let pp format t = Format.fprintf format "%s" - (Otoml.Printer.to_string (ImportConf.Syntax.repr t)) + (Otoml.Printer.to_string (ImporterSyntax.repr t)) let equal t1 t2 = t1 = t2 end) |