aboutsummaryrefslogtreecommitdiff
path: root/tests/configuration_toml.ml
blob: 3c8bfc28acb09fe490cd7f6881ded8443195782b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
open OUnit2
module Expression = ImportExpression.T
module Path = ImportDataTypes.Path

let test_suit =
  [
    ( "parse_extern" >:: fun _ ->
      let toml = Otoml.Parser.from_file "configuration/simple.toml" in
      let toml = ImportConf.t_of_toml toml in
      match toml with
      | Error s -> raise (Failure s)
      | Ok result ->
          let open ImportConf.Syntax in
          let expected =
            {
              target = { file = ""; tab = 1; name = "target" };
              extern_key = Literal "_B";
              intern_key =
                Function
                  ( "function",
                    [
                      Path { alias = None; column = 1 };
                      Path { alias = None; column = 2 };
                    ] );
              match_rule = None;
              allow_missing = true;
            }
          in

          let printer s =
            String.concat "," (List.map ImportConf.print_extern s)
          in

          assert_equal ~printer [ expected ] result.externals );
    ( "parse_columns" >:: fun _ ->
      let toml = Otoml.Parser.from_file "configuration/simple.toml" in
      let toml = ImportConf.t_of_toml toml in

      match toml with
      | Error s -> raise (Failure s)
      | Ok result ->
          let open Path in
          let open Expression in
          let expected =
            [
              Function
                ( "function",
                  [
                    Path { alias = Some "target"; column = 1 };
                    Path { alias = None; column = 2 };
                    Literal "free' text";
                  ] );
              Window
                ( Counter,
                  [ Path { alias = Some "target"; column = 1 } ],
                  [ Path { alias = Some "target"; column = 1 } ] );
            ]
          in

          List.iter2
            (fun expected result ->
              assert_equal ~printer:ImportConf.print_path_expression expected
                result)
            expected result.columns );
    ( "parse_csv" >:: fun _ ->
      let toml = Otoml.Parser.from_file "configuration/example_csv.toml" in
      let toml = ImportConf.t_of_toml toml in
      ignore toml );
  ]

let tests = "configuration_toml" >::: test_suit