1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
open Alcotest
open Fixgen
let parse (s : string) =
let lexbuf = Lexing.from_string s in
let ast = Parser.prog Lexer.read lexbuf in
ast
let test_parse s () =
let ast = parse s in
check bool "Parses" (Option.is_some ast) true
let rows_suite =
[ "Can parse uuidv4", `Quick, test_parse "user (1): id uuidv4"
; ( "Can parse multiple tables"
, `Quick
, test_parse "user (1): id uuidv4\npurchases (1): id uuidv4" )
; "Supports names", `Quick, test_parse "purchases (1): name name"
; "Supports const", `Quick, test_parse "purchases (1): name \"_helloarsent1!@#4\""
; "Supports ints with min/max", `Quick, test_parse "purchases (1): name int(1,20)"
; ( "Supports a list of potential values"
, `Quick
, test_parse "purchases (1): name (\"a\",\"b\",\"c\")" )
; ( "Supports setting amount of fixture to generate"
, `Quick
, test_parse "purchases (5): name int(1,20)" )
; "Supports underscore tables", `Quick, test_parse "purchases_new (5): name int(1,20)"
; "Supports incremental index", `Quick, test_parse "purchases_new (5): id increment"
]
let relations_suite =
[ ( "Can reference other tables"
, `Quick
, test_parse "user (2): id uuidv4\npurchases (3): id uuidv4, userid user.id" )
; ( "Can use ; as a separator"
, `Quick
, test_parse "user (2): id uuidv4; purchases (5): id uuidv4" )
; ( "Supports nested relations"
, `Quick
, test_parse
"user (2): id uuidv4; purchases (5): id uuidv4; receipts (5): id purchases.id" )
; ( "Supports multiple relations"
, `Quick
, test_parse
"buyer (2): id uuidv4; seller (5): id uuidv4; purchases (5): buyer buyer.id, \
seller seller.id" )
; ( "Supports multiple newlines"
, `Quick
, test_parse "user (2): id uuidv4\n\n\n\n\npurchases (5): id uuidv4" )
]
let () = Alcotest.run "Parsing" [ "Rows", rows_suite; "Relations", relations_suite ]
|