aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2023-12-26 16:22:42 -0600
committerMarc Coquand <marc@mccd.space>2023-12-26 16:22:42 -0600
commit5994b98069cec82f0b18a6a1629cc9973fc9e0bf (patch)
tree1b5b093f0fb9a4f4194f9d5f20f1d1069ffe29b7 /lib
parent35d5620add93feaa0db394cb1db87821031f23ef (diff)
downloadfixgen-5994b98069cec82f0b18a6a1629cc9973fc9e0bf.tar.gz
fixgen-5994b98069cec82f0b18a6a1629cc9973fc9e0bf.tar.bz2
fixgen-5994b98069cec82f0b18a6a1629cc9973fc9e0bf.zip
Add support for email
Diffstat (limited to 'lib')
-rw-r--r--lib/ast_types.ml5
-rw-r--r--lib/fixture.ml38
-rw-r--r--lib/lexer.mll1
-rw-r--r--lib/parser.mly5
4 files changed, 49 insertions, 0 deletions
diff --git a/lib/ast_types.ml b/lib/ast_types.ml
index fdcafd2..0cbdb4f 100644
--- a/lib/ast_types.ml
+++ b/lib/ast_types.ml
@@ -6,6 +6,7 @@ type ast_row =
| Name of string * ast_row
| Int of string * int * int * ast_row
| Increment of string * ast_row
+ | Email of string * ast_row
| Const of string * string * ast_row
| List of string * string list * ast_row
| Foreign of string * string * string * ast_row
@@ -43,6 +44,9 @@ let rec print_row = function
| Name (s, r) ->
printf "Name(%s)," s;
print_row r
+ | Email (s, r) ->
+ printf "Email(%s)," s;
+ print_row r
| End -> printf "\n"
@@ -79,6 +83,7 @@ let rec ast_row_to_fixtures = function
| Const (s, v, r) -> PColumn (Fixture.Const (s, v)) :: ast_row_to_fixtures r
| List (s, l, r) -> PColumn (Fixture.List (s, l)) :: ast_row_to_fixtures r
| Increment (s, r) -> PColumn (Fixture.Increment s) :: ast_row_to_fixtures r
+ | Email (s, r) -> PColumn (Fixture.Email s) :: ast_row_to_fixtures r
| End -> []
let extend_table_with_row table row =
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
diff --git a/lib/lexer.mll b/lib/lexer.mll
index 0fb7f7c..ad3be3c 100644
--- a/lib/lexer.mll
+++ b/lib/lexer.mll
@@ -18,6 +18,7 @@ let many_newline = newline+
rule read =
parse
| "uuidv4" { UUIDV4 }
+ | "email" { EMAIL }
| "name" { NAME }
| "increment" { INCREMENT }
| "int" { INTSYMBOL }
diff --git a/lib/parser.mly b/lib/parser.mly
index 6172963..e6bcb6d 100644
--- a/lib/parser.mly
+++ b/lib/parser.mly
@@ -15,6 +15,7 @@
%token <int> INT
%token LBRACE
%token RBRACE
+%token EMAIL
%token <string> STRING
%start <ast_table option > prog
%%
@@ -28,6 +29,7 @@ id_or_other:
| NAME { "name" }
| UUIDV4 { "uuidv4" }
| INCREMENT { "increment" }
+ | EMAIL { "email" }
expr:
@@ -49,6 +51,9 @@ row:
| row_title = id_or_other; NAME; COMMA; r = row { Name (row_title, r) }
| row_title = id_or_other; NAME { Name (row_title, End) }
+ | row_title = id_or_other; EMAIL; COMMA; r = row { Email (row_title, r) }
+ | row_title = id_or_other; EMAIL { Email (row_title, End) }
+
| row_title = id_or_other; INCREMENT; COMMA; r = row { Increment (row_title, r) }
| row_title = id_or_other; INCREMENT { Increment (row_title, End) }