aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/ast_types.ml21
1 files changed, 3 insertions, 18 deletions
diff --git a/lib/ast_types.ml b/lib/ast_types.ml
index c192c60..7638d3b 100644
--- a/lib/ast_types.ml
+++ b/lib/ast_types.ml
@@ -59,6 +59,8 @@ type ast_table_relation =
| PTable of string * int * Fixture.t list
| CTable of string * string * string * int * (string list -> Fixture.t list)
(** parent, row, child_name, row *)
+ (* TODO: Support multiple relations *)
+
let table_name = function
| PTable (n,_,_) -> n
@@ -99,7 +101,6 @@ let rec ast_table_to_tables ast =
it can be used as input for the next entry *)
match ast with
| Table (name, amount, r, t) ->
- print_endline ("Converting table: " ^ name);
ast_table_to_table name amount (ast_row_to_fixtures r) :: ast_table_to_tables t
| End -> []
@@ -110,6 +111,7 @@ let%test "ast_table_to_tables" =
List.length tables == 2
let generated_fixtures = ref (Hashtbl.create 10)
+(** Used to not regenerate a different fixture for the same table. Also theoretically speeds up the compilation process by not generating the same fixture twice. I do not know what kind of monstrosity of a fixture you'd need for it to matter, but neat regardless. *)
let rec resolve_fixtures tables name =
(* Verify if we have already generated fixtures for this table *)
@@ -129,12 +131,7 @@ let rec resolve_fixtures tables name =
let (_, parent_fixtures) = resolve_fixtures tables p in
(* store the generated fixtures for this table *)
Hashtbl.add !generated_fixtures name parent_fixtures;
- print_endline ("Resolving fixtures for " ^ c);
- for i = 0 to List.length parent_fixtures - 1 do
- print_endline ("Parent fixture: " ^ Fixture.csv_of_string_list (List.nth parent_fixtures i));
- done;
let generated_ids = Fixture.find_entries_for_header parent_fixtures pr in
- print_endline ("Generated ids: " ^ String.concat ", " (Result.get_ok generated_ids));
match generated_ids with
| Ok ids -> (c, Fixture.compile ~amount (create_fixtures ids))
| Error e -> failwith e
@@ -148,12 +145,6 @@ let%test "resolve_fixtures" =
] in
let (_, user_fixtures) = resolve_fixtures tables "user" in
let (_, purchase_fixtures) = resolve_fixtures tables "posts" in
- for i = 0 to List.length user_fixtures - 1 do
- print_endline ("User fixture: " ^ Fixture.csv_of_string_list (List.nth user_fixtures i));
- done;
- for i = 0 to List.length purchase_fixtures - 1 do
- print_endline ("Purchase fixture: " ^ Fixture.csv_of_string_list (List.nth purchase_fixtures i));
- done;
match (user_fixtures,purchase_fixtures) with
| ([["id";_];[u;_]], [["user_id"]; [v]]) -> v = u
| _ ->
@@ -170,26 +161,20 @@ let show_tables tables =
let compile ast =
let tables = ast_table_to_tables ast in
- print_endline ("Table length: " ^ string_of_int (List.length tables));
- print_endline (show_tables tables);
let resolve_fixtures' = function
| PTable (n, amount, l) ->
let (n,_,resolved) = (n, amount, Fixture.compile l ~amount) in
- (* store the generated fixtures for this table *)
Hashtbl.add !generated_fixtures n resolved;
(n,resolved)
| CTable (p,pr,c, amount, create_fixtures) ->
let (_, parent_fixtures) = resolve_fixtures tables p in
- (* store the generated fixtures for this table *)
Hashtbl.add !generated_fixtures c parent_fixtures;
- print_endline ("Resolving fixtures for " ^ c);
let generated_ids = Fixture.find_entries_for_header parent_fixtures pr in
match generated_ids with
| Ok ids -> (c, Fixture.compile ~amount (create_fixtures ids))
| Error e -> failwith e
in
let result = List.map resolve_fixtures' tables in
- print_endline ("Result names: " ^ String.concat ", " (List.map fst result));
result