aboutsummaryrefslogtreecommitdiff
path: root/lib/fixture.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fixture.ml')
-rw-r--r--lib/fixture.ml17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/fixture.ml b/lib/fixture.ml
index 18e2ff6..d127405 100644
--- a/lib/fixture.ml
+++ b/lib/fixture.ml
@@ -50,7 +50,7 @@ let email_hosts =
]
-let random_value_in_list values = List.nth values (Random.int (List.length values))
+let random_value_in_list values () = List.nth values (Random.int (List.length values))
type compiled =
| Int of int
@@ -68,7 +68,10 @@ let show_compiled_csv fixture =
let random_email index () =
- random_value_in_list email_handles ^ index ^ "@" ^ random_value_in_list email_hosts
+ random_value_in_list email_handles ()
+ ^ index
+ ^ "@"
+ ^ random_value_in_list email_hosts ()
let random_name () = List.nth names (Random.int (List.length names))
@@ -92,6 +95,7 @@ let key_of_compiled key =
type t =
| Name of string
+ | Username of string
| Uuidv4 of string
| Foreign of string * compiled list
| Int of string * int * int
@@ -105,13 +109,14 @@ let generate_fixture index fixture =
let str_index = string_of_int index in
match fixture with
| Name _ -> String (random_name () ^ str_index)
+ | Username _ -> String (random_value_in_list email_handles () ^ str_index)
| Uuidv4 _ -> String (Uuidm.v `V4 |> Uuidm.to_string)
- | Foreign (_, reference) -> random_value_in_list reference
+ | Foreign (_, reference) -> random_value_in_list reference ()
| Increment _ -> Int (index + 1)
| Const (_, value) -> String value
| Email _ -> String (random_email str_index ())
| Int (_, min, max) -> Int (Random.int (max - min) + min)
- | List (_, values) -> String (random_value_in_list values)
+ | List (_, values) -> String (random_value_in_list values ())
let add_name name fixtures = Name name :: fixtures
@@ -120,13 +125,14 @@ let add_foreign id values fixtures = Foreign (id, values) :: fixtures
let%test "random_value_in_list" =
let values = [ "a"; "b"; "c" ] in
- let result = random_value_in_list values in
+ let result = random_value_in_list values () in
List.mem result values
(* TODO: Support "hashed" password *)
(* TODO: Support dates *)
(* TODO: Support variables using @ *)
+(* TODO: Support username *)
let rec replicate element n =
match n with
@@ -143,6 +149,7 @@ let id_of_fixture fixture =
match fixture with
| Name id -> id
| Uuidv4 id -> id
+ | Username id -> id
| Increment id -> id
| Foreign (id, _) -> id
| Const (id, _) -> id