-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (44 loc) · 1.11 KB
/
index.js
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
function assert(cond, msg) {
if (!cond) {
throw new Error(msg || 'Assertion failed');
}
}
assert.assert = assert;
assert.default = assert;
assert.unchecked = function() {};
assert.unreachable = function(_, msg) {
throw new Error(msg || 'Reached unreachable code');
};
assert.dev = function(cond, msg) {
if (process.env.NODE_ENV !== 'production') {
assert(cond, msg);
}
};
assert.eq = function(left, right) {
if (left !== right) {
throw new Error('Equality assertion failed\nleft: ' + left
+ '\nright: ' + right);
}
};
assert.ne = function(left, right) {
if (left === right) {
throw new Error('Inequality assertion failed\nleft: ' + left
+ '\nright: ' + right);
}
};
assert.throws = function(closure, msg) {
try {
closure();
throw new Error(msg ?? 'Expected closure to throw and it did not');
} catch(e) {
return e;
}
};
assert.ok = function(closure, msg) {
try {
return closure();
} catch(e) {
throw new Error(msg ?? 'Closure threw an exception');
}
};
module.exports = assert;