aboutsummaryrefslogtreecommitdiff
path: root/lib/fixture.ml
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/fixture.ml12
1 files changed, 9 insertions, 3 deletions
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