diff options
author | Marc Coquand <marc@mccd.space> | 2023-12-26 16:22:42 -0600 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2023-12-26 16:22:42 -0600 |
commit | 5994b98069cec82f0b18a6a1629cc9973fc9e0bf (patch) | |
tree | 1b5b093f0fb9a4f4194f9d5f20f1d1069ffe29b7 /lib/fixture.ml | |
parent | 35d5620add93feaa0db394cb1db87821031f23ef (diff) | |
download | fixgen-5994b98069cec82f0b18a6a1629cc9973fc9e0bf.tar.gz fixgen-5994b98069cec82f0b18a6a1629cc9973fc9e0bf.tar.bz2 fixgen-5994b98069cec82f0b18a6a1629cc9973fc9e0bf.zip |
Add support for email
Diffstat (limited to '')
-rw-r--r-- | lib/fixture.ml | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/fixture.ml b/lib/fixture.ml index 4985624..dbd6297 100644 --- a/lib/fixture.ml +++ b/lib/fixture.ml @@ -19,6 +19,37 @@ let names = ] +let email_handles = + [ "alice" + ; "bob" + ; "charlie" + ; "dave" + ; "eve" + ; "frank" + ; "grace" + ; "heidi" + ; "ivan" + ; "judy" + ; "mallory" + ; "oscar" + ; "peggy" + ; "sybil" + ; "trent" + ; "victor" + ; "walter" + ] + + +let email_hosts = + [ "gmail.com" + ; "yahoo.com" + ; "hotmail.com" + ; "fastmail.fr" + ; "mccd.space" + ; "protonmail.com" + ] + + let random_value_in_list values = List.nth values (Random.int (List.length values)) type compiled = @@ -36,6 +67,10 @@ let show_compiled_csv fixture = | Float f -> string_of_float f +let random_email () = + random_value_in_list email_handles ^ "@" ^ random_value_in_list email_hosts + + let random_name () = List.nth names (Random.int (List.length names)) let%test "random_name" = List.mem (random_name ()) names @@ -62,6 +97,7 @@ type t = | Int of string * int * int | Increment of string | Const of string * string + | Email of string | List of string * string list (* (Name, foreign ids to pick from) *) @@ -72,6 +108,7 @@ let generate_fixture index fixture = | Foreign (_, reference) -> random_value_in_list reference | Increment _ -> Int (index + 1) | Const (_, value) -> String value + | Email _ -> String (random_email ()) | Int (_, min, max) -> Int (Random.int (max - min) + min) | List (_, values) -> String (random_value_in_list values) @@ -111,6 +148,7 @@ let id_of_fixture fixture = | Const (id, _) -> id | Int (id, _, _) -> id | List (id, _) -> id + | Email id -> id in String id |