-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBsOspec.re
105 lines (89 loc) · 3.14 KB
/
BsOspec.re
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
module Common = {
[@bs.module "ospec"]
external describe : (string, (unit => unit)) => unit = "spec";
[@bs.module "ospec"]
external testOnly : (string, (unit => unit)) => unit = "only";
[@bs.module "ospec"]
external testAsyncOnly : (string, (unit => unit) => 'a) => unit = "only";
[@bs.module "ospec"]
external testAsyncLongOnly : (string, (unit => unit, int => unit) => 'a) => unit = "only";
[@bs.module "ospec"]
external before : (unit => 'a) => unit = "";
[@bs.module "ospec"]
external after : (unit => 'a) => unit = "";
[@bs.module "ospec"]
external beforeAsync : (('a => unit) => 'b) => unit = "before";
[@bs.module "ospec"]
external afterAsync : (('a => unit) => 'b) => unit = "after";
[@bs.module "ospec"]
external beforeEach : (unit => 'a) => unit = "";
[@bs.module "ospec"]
external afterEach : (unit => 'a) => unit = "";
[@bs.module "ospec"]
external beforeEachAsync : (('a => unit) => 'b) => unit = "beforeEach";
[@bs.module "ospec"]
external afterEachAsync : (('a => unit) => 'b) => unit = "afterEach";
};
type desc_fn = [@bs] (string) => unit;
type checker('a) = {
.
"equals": [@bs.meth] ('a) => desc_fn,
"deepEquals": [@bs.meth] ('a) => desc_fn,
"notEquals": [@bs.meth] ('a) => desc_fn,
"notDeepEquals": [@bs.meth] ('a) => desc_fn,
};
module type Checker = {
let make : ('a) => checker('b);
};
module Assertions = (Checker : Checker) => {
let equals = (actual, ~m=?, expected) => switch(m) {
| Some(message) =>
let desc = Checker.make(actual)##equals(expected);
desc(. message)
| None => Checker.make(actual)##equals(expected) |> ignore
};
let deepEquals = (actual, ~m=?, expected) => switch(m) {
| Some(message) =>
let desc = Checker.make(actual)##deepEquals(expected);
desc(. message)
| None => Checker.make(actual)##deepEquals(expected) |> ignore
};
let notEquals = (actual, ~m=?, expected) => switch(m) {
| Some(message) =>
let desc = Checker.make(actual)##notEquals(expected);
desc(. message)
| None => Checker.make(actual)##notEquals(expected) |> ignore
};
let notDeepEquals = (actual, ~m=?, expected) => switch(m) {
| Some(message) =>
let desc = Checker.make(actual)##notDeepEquals(expected);
desc(. message)
| None => Checker.make(actual)##notDeepEquals(expected) |> ignore
};
};
module Cjs = {
include Common;
include Assertions({
[@bs.module]
external make : ('a) => checker('b) = "ospec";
});
[@bs.module]
external test : (string, (unit => 'a)) => unit = "ospec";
[@bs.module]
external testAsync : (string, (unit => unit) => 'a) => unit = "ospec";
[@bs.module]
external testAsyncLong : (string, (unit => unit, int => unit) => 'a) => unit = "ospec";
};
module Esm = {
include Common;
include Assertions({
[@bs.module "ospec"]
external make : ('a) => checker('b) = "default";
});
[@bs.module "ospec"]
external test : (string, (unit => 'a)) => unit = "default";
[@bs.module "ospec"]
external testAsync : (string, (unit => unit) => 'a) => unit = "default";
[@bs.module "ospec"]
external testAsyncLong : (string, (unit => unit, int => unit) => 'a) => unit = "default";
};