module Expression = ImportExpression.T
module Path = ImportDataTypes.Path
open Test_migration

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 expected =
            ImportConf.Syntax.Extern.
              {
                target = { file = ""; tab = 1; name = "target" };
                extern_key = Literal "_B";
                intern_key =
                  Function
                    ( "concat",
                      [
                        Path { alias = None; column = 1 };
                        Path { alias = None; column = 2 };
                      ] );
                match_rule = None;
                allow_missing = true;
              }
          in

          ignore
          @@ Alcotest.check
               (Alcotest.list Test_migration.extern_testable)
               "" [ 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
                ( "if",
                  [
                    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

          Alcotest.check
            (Alcotest.list Test_migration.expression_testable)
            "" 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