From c75ab6042f40f9101e88d41c1d41b5e41c3f12ef Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Tue, 26 Dec 2023 15:46:04 -0600 Subject: Add increment type --- lib/fixture.ml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/fixture.ml') diff --git a/lib/fixture.ml b/lib/fixture.ml index 6080fd9..21d77cf 100644 --- a/lib/fixture.ml +++ b/lib/fixture.ml @@ -60,15 +60,17 @@ type t = | Uuidv4 of string | Foreign of string * compiled list | Int of string * int * int + | Increment of string | Const of string * string | List of string * string list (* (Name, foreign ids to pick from) *) -let generate_fixture fixture = +let generate_fixture index fixture = match fixture with | Name _ -> String (random_name ()) | Uuidv4 _ -> String (Uuidm.v `V4 |> Uuidm.to_string) | Foreign (_, reference) -> random_value_in_list reference + | Increment _ -> Int (index + 1) | Const (_, value) -> String value | Int (_, min, max) -> Int (Random.int (max - min) + min) | List (_, values) -> String (random_value_in_list values) @@ -95,7 +97,7 @@ let rec replicate element n = let%test "generate_uuid" = - generate_fixture (Uuidv4 "some_id") != generate_fixture (Uuidv4 "some_id") + generate_fixture 1 (Uuidv4 "some_id") != generate_fixture 1 (Uuidv4 "some_id") let id_of_fixture fixture = @@ -103,6 +105,7 @@ let id_of_fixture fixture = match fixture with | Name id -> id | Uuidv4 id -> id + | Increment id -> id | Foreign (id, _) -> id | Const (id, _) -> id | Int (id, _, _) -> id @@ -113,7 +116,10 @@ let id_of_fixture fixture = let compile fixtures ~amount = let identifiers = List.map id_of_fixture fixtures in - let values = replicate fixtures amount |> List.map (List.map generate_fixture) in + let values = + replicate fixtures amount + |> List.mapi (fun index -> List.map (generate_fixture index)) + in identifiers :: values -- cgit v1.2.3