diff options
author | Marc Coquand <marc@mccd.space> | 2023-12-26 10:51:13 -0600 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2023-12-26 10:51:13 -0600 |
commit | fc077e16adf2860af3d32a60cabd67f57bab0803 (patch) | |
tree | b636d3a57f65c3fa8bf5cfd0aaaef044ba9e2948 /lib | |
parent | 2a664a47c73e232b6ff0d261833e2561d4abc4d0 (diff) | |
download | fixgen-fc077e16adf2860af3d32a60cabd67f57bab0803.tar.gz fixgen-fc077e16adf2860af3d32a60cabd67f57bab0803.tar.bz2 fixgen-fc077e16adf2860af3d32a60cabd67f57bab0803.zip |
Support json output
Diffstat (limited to '')
-rw-r--r-- | lib/fixture.ml | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/fixture.ml b/lib/fixture.ml index d5c77fa..d28d4b3 100644 --- a/lib/fixture.ml +++ b/lib/fixture.ml @@ -67,6 +67,10 @@ let id_of_fixture fixture = (* TODO: Support email *) +(* TODO: Support arbitrary string *) +(* TODO: Support "hashed" password *) +(* TODO: Support variables using @ *) +(* TODO: Support JSON export *) let rec replicate element n = match n with @@ -118,3 +122,19 @@ let csv_of_generated_fixtures fixtures = let%test "csv_of_generated_fixtures" = let result = [ [ "id"; "name" ]; [ "1234"; "John" ] ] |> csv_of_generated_fixtures in result = "id,name\n1234,John" + + +let json_of_generated_fixtures fixtures = + let headers = List.hd fixtures in + let rows = List.tl fixtures in + let json_of_row row = + let pairs = List.combine headers row in + let json_of_pair (key, value) = "\"" ^ key ^ "\": \"" ^ value ^ "\"" in + "{" ^ String.concat ", " (List.map json_of_pair pairs) ^ "}" + in + "[" ^ String.concat ", " (List.map json_of_row rows) ^ "]" + + +let%test "json_of_generated_fixtures" = + let result = [ [ "id"; "name" ]; [ "1234"; "John" ] ] |> json_of_generated_fixtures in + result = "[{\"id\": \"1234\", \"name\": \"John\"}]" |