forked from a1967629423/puerts-react-umg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyAssert.ts
33 lines (29 loc) · 1016 Bytes
/
MyAssert.ts
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
class AssertionError extends Error {
actual: any;
expected: any;
operator: string;
code: string;
constructor(message: string, actual?: any, expected?: any, operator?: string) {
super(message);
this.actual = actual;
this.expected = expected;
this.operator = operator;
this.code = 'ERR_TGAMEJS_ASSERT';
this.name = 'AssertionError';
}
}
export function equal(actual: any, expected: any, message?: string): void {
if (actual != expected) {
throw new AssertionError(message || `${actual} == ${expected}`, actual, expected, '==');
}
}
export function notEqual(actual: any, expected: any, message?: string): void {
if (actual == expected) {
throw new AssertionError(message || `${actual} != ${expected}`, actual, expected, '!=');
}
}
export function ok(actual: any, message?: string): void {
if (!!actual == false) {
throw new AssertionError(message || `${actual} != true`, actual, true, '==');
}
}