forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathounit_bsb_pkg_tests.ml
115 lines (96 loc) · 2.8 KB
/
ounit_bsb_pkg_tests.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
let ((>::),
(>:::)) = OUnit.((>::),(>:::))
let printer_string = fun x -> x
let (=~) = OUnit.assert_equal ~printer:printer_string
let scope_test s (a,b,c)=
match Bsb_pkg_types.extract_pkg_name_and_file s with
| Scope(a0,b0),c0 ->
a =~ a0 ; b =~ b0 ; c =~ c0
| Global _,_ -> OUnit.assert_failure __LOC__
let global_test s (a,b) =
match Bsb_pkg_types.extract_pkg_name_and_file s with
| Scope _, _ ->
OUnit.assert_failure __LOC__
| Global a0, b0->
a=~a0; b=~b0
let s_test0 s (a,b)=
match Bsb_pkg_types.string_as_package s with
| Scope(name,scope) ->
a =~ name ; b =~scope
| _ -> OUnit.assert_failure __LOC__
let s_test1 s a =
match Bsb_pkg_types.string_as_package s with
| Global x ->
a =~ x
| _ -> OUnit.assert_failure __LOC__
let group0 = Map_string.of_list [
"Liba",
{Bsb_db.info = Impl_intf; dir= "a";syntax_kind=Ml;case = false;
name_sans_extension = "liba"}
]
let group1 = Map_string.of_list [
"Ciba",
{Bsb_db.info = Impl_intf; dir= "b";syntax_kind=Ml;case = false;
name_sans_extension = "liba"}
]
let parse_db db : Bsb_db_decode.t =
let buf = Ext_buffer.create 10_000 in
Bsb_db_encode.encode db buf;
let s = Ext_buffer.contents buf in
Bsb_db_decode.decode s
let suites =
__FILE__ >::: [
__LOC__ >:: begin fun _ ->
scope_test "@hello/hi"
("hi", "@hello","");
scope_test "@hello/hi/x"
("hi", "@hello","x");
scope_test "@hello/hi/x/y"
("hi", "@hello","x/y");
end ;
__LOC__ >:: begin fun _ ->
global_test "hello"
("hello","");
global_test "hello/x"
("hello","x");
global_test "hello/x/y"
("hello","x/y")
end ;
__LOC__ >:: begin fun _ ->
s_test0 "@x/y" ("y","@x");
s_test0 "@x/y/z" ("y/z","@x");
s_test1 "xx" "xx";
s_test1 "xx/yy/zz" "xx/yy/zz"
end;
__LOC__ >:: begin fun _ ->
match parse_db {lib= group0; dev = group1}with
| {lib = Group {modules = [|"Liba"|]};
dev = Group {modules = [|"Ciba"|]}}
-> OUnit.assert_bool __LOC__ true
| _ ->
OUnit.assert_failure __LOC__
end ;
__LOC__ >:: begin fun _ ->
match parse_db {lib = group0;dev = Map_string.empty } with
| {lib = Group {modules = [|"Liba"|]};
dev = Dummy}
-> OUnit.assert_bool __LOC__ true
| _ ->
OUnit.assert_failure __LOC__
end ;
__LOC__ >:: begin fun _ ->
match parse_db {lib = Map_string.empty ; dev = group1} with
| {lib = Dummy;
dev = Group {modules = [|"Ciba"|]}
}
-> OUnit.assert_bool __LOC__ true
| _ ->
OUnit.assert_failure __LOC__
end
(* __LOC__ >:: begin fun _ ->
OUnit.assert_equal parse_data_one data_one
end ;
__LOC__ >:: begin fun _ ->
OUnit.assert_equal parse_data_two data_two
end *)
]