-
Notifications
You must be signed in to change notification settings - Fork 1
/
variant.ml
69 lines (57 loc) · 1.39 KB
/
variant.ml
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
57
58
59
60
61
62
63
64
65
66
67
68
TYPE_CONV_PATH "Variant"
type s =
|Foo
|Bar of int
|Xyz of string
|Blah of (int * char)
and x = {
foo: s;
bar: s;
} with orm
open OUnit
open Test_utils
let string_of_s = function
|Foo -> "Foo"
|Bar i -> "Bar " ^ (string_of_int i)
|Xyz z -> "Xyz " ^ z
|_ -> "??"
let name = "variant.db"
let x1 = { foo=Foo; bar=(Bar 1) }
let x2 = { foo=(Xyz "hello"); bar=Foo }
let test_init () =
ignore(open_db s_init name);
ignore(open_db ~rm:false x_init name);
ignore(open_db ~rm:false x_init name)
let test_save () =
let db = open_db x_init name in
x_save db x1;
x_save db x2
let test_update () =
let db = open_db x_init name in
x_save db x1;
x_save db x2;
x_save db x1;
x_save db x2
let test_get () =
let db = open_db ~rm:false x_init name in
let i = x_get db in
"2 in db" @? (List.length i = 2);
match i with
| [a1;a2] ->
"x1 values match" @? (a1.foo = x1.foo && (a1.bar = x1.bar));
"x2 values match" @? (a2.foo = x2.foo && (a2.bar = x2.bar))
| _ -> assert false
let test_save_get () =
let db = open_db x_init name in
x_save db x1;
match x_get db with
[i] -> "structurally equal after get" @? ( x1 == i)
|_ -> assert false
let suite = [
"variant_init" >:: test_init;
"variant_save" >:: test_save;
"variant_update" >:: test_update;
"variant_update" >:: test_update;
"variant_get" >:: test_get;
"variant_save_get" >:: test_save_get;
]