as-test 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/{nodejs.yml → as-test.yml} +10 -9
- package/.prettierrc +3 -0
- package/CHANGELOG.md +3 -1
- package/README.md +18 -65
- package/as-test.config.json +22 -0
- package/asconfig.json +30 -33
- package/assembly/__tests__/example.spec.ts +70 -0
- package/assembly/coverage.ts +15 -15
- package/assembly/index.ts +195 -132
- package/assembly/reporters/tap.ts +30 -0
- package/assembly/src/expectation.ts +302 -277
- package/assembly/src/group.ts +33 -33
- package/assembly/src/node.ts +7 -7
- package/assembly/test.ts +43 -46
- package/assembly/tsconfig.json +96 -98
- package/assembly/util.ts +90 -87
- package/bin/build.js +119 -0
- package/bin/index.js +159 -0
- package/bin/init.js +40 -0
- package/bin/package.json +3 -0
- package/bin/run.js +53 -0
- package/bin/types.js +41 -0
- package/bin/util.js +23 -0
- package/cli/build.ts +154 -0
- package/cli/index.ts +201 -0
- package/cli/init.ts +47 -0
- package/cli/run.ts +68 -0
- package/cli/tsconfig.json +8 -0
- package/cli/types.ts +34 -0
- package/cli/util.ts +30 -0
- package/index.ts +1 -1
- package/jest.test.js +44 -5
- package/package.json +18 -15
- package/tests/test.tap +14 -0
- package/transform/lib/index.js +391 -397
- package/transform/package.json +4 -4
- package/transform/src/index.ts +474 -506
- package/transform/tsconfig.json +2 -2
- package/assembly/example.spec.ts +0 -5
- package/src/cli.ts +0 -0
|
@@ -4,337 +4,362 @@ import { Node } from "./node";
|
|
|
4
4
|
import { Verdict, after_each_callback, before_each_callback } from "..";
|
|
5
5
|
|
|
6
6
|
export class Expectation<T> extends Node {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
public verdict: Verdict = Verdict.Unreachable;
|
|
8
|
+
private left: T;
|
|
9
|
+
private _left: string | null = null;
|
|
10
|
+
private right: u64 = 0;
|
|
11
|
+
private _right: string | null = null;
|
|
12
|
+
private _not: boolean = false;
|
|
13
|
+
private op: string = "=";
|
|
14
|
+
constructor(left: T) {
|
|
15
|
+
super();
|
|
16
|
+
this.left = left;
|
|
17
|
+
}
|
|
18
|
+
get not(): Expectation<T> {
|
|
19
|
+
this._not = true;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Tests if a == null
|
|
25
|
+
* @returns - void
|
|
26
|
+
*/
|
|
27
|
+
toBeNull(): void {
|
|
28
|
+
this.verdict =
|
|
29
|
+
isNullable<T>() && changetype<usize>(this.left)
|
|
30
|
+
? Verdict.Ok
|
|
31
|
+
: Verdict.Fail;
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @returns - void
|
|
26
|
-
*/
|
|
27
|
-
toBeNull(): void {
|
|
28
|
-
this.verdict = (isNullable<T>() && changetype<usize>(this.left)) ? Verdict.Ok : Verdict.Fail;
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
store<T>(changetype<usize>(this), null, offsetof<Expectation<T>>("right"));
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
store<T>(changetype<usize>(this), null, offsetof<Expectation<T>>("right"));
|
|
36
|
+
this.op = "=";
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
if (after_each_callback) after_each_callback();
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
if (before_each_callback) before_each_callback();
|
|
42
|
+
}
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Tests if a > b
|
|
46
|
+
* @param number equals - The value to test
|
|
47
|
+
* @returns - void
|
|
48
|
+
*/
|
|
49
|
+
toBeGreaterThan(value: T): void {
|
|
50
|
+
if (!isInteger<T>() && !isFloat<T>())
|
|
51
|
+
ERROR("toBeGreaterThan() can only be used on number types!");
|
|
40
52
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* @param number equals - The value to test
|
|
44
|
-
* @returns - void
|
|
45
|
-
*/
|
|
46
|
-
toBeGreaterThan(value: T): void {
|
|
47
|
-
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeGreaterThan() can only be used on number types!");
|
|
53
|
+
this.verdict = this.left > value ? Verdict.Ok : Verdict.Fail;
|
|
54
|
+
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
56
|
+
this.op = ">";
|
|
51
57
|
|
|
52
|
-
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
if (after_each_callback) after_each_callback();
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
if (before_each_callback) before_each_callback();
|
|
62
|
+
}
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Tests if a >= b
|
|
66
|
+
* @param number equals - The value to test
|
|
67
|
+
* @returns - void
|
|
68
|
+
*/
|
|
69
|
+
toBeGreaterOrEqualTo(value: T): void {
|
|
70
|
+
if (!isInteger<T>() && !isFloat<T>())
|
|
71
|
+
ERROR("toBeGreaterOrEqualTo() can only be used on number types!");
|
|
59
72
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* @param number equals - The value to test
|
|
63
|
-
* @returns - void
|
|
64
|
-
*/
|
|
65
|
-
toBeGreaterOrEqualTo(value: T): void {
|
|
66
|
-
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeGreaterOrEqualTo() can only be used on number types!");
|
|
73
|
+
this.verdict = this.left >= value ? Verdict.Ok : Verdict.Fail;
|
|
74
|
+
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
67
75
|
|
|
68
|
-
|
|
69
|
-
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
76
|
+
this.op = ">=";
|
|
70
77
|
|
|
71
|
-
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
if (after_each_callback) after_each_callback();
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
if (before_each_callback) before_each_callback();
|
|
82
|
+
}
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Tests if a < b
|
|
86
|
+
* @param number equals - The value to test
|
|
87
|
+
* @returns - void
|
|
88
|
+
*/
|
|
89
|
+
toBeLessThan(value: T): void {
|
|
90
|
+
if (!isInteger<T>() && !isFloat<T>())
|
|
91
|
+
ERROR("toBeLessThan() can only be used on number types!");
|
|
78
92
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* @param number equals - The value to test
|
|
82
|
-
* @returns - void
|
|
83
|
-
*/
|
|
84
|
-
toBeLessThan(value: T): void {
|
|
85
|
-
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeLessThan() can only be used on number types!");
|
|
93
|
+
this.verdict = this.left < value ? Verdict.Ok : Verdict.Fail;
|
|
94
|
+
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
86
95
|
|
|
87
|
-
|
|
88
|
-
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
96
|
+
this.op = "<";
|
|
89
97
|
|
|
90
|
-
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
if (after_each_callback) after_each_callback();
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
if (before_each_callback) before_each_callback();
|
|
102
|
+
}
|
|
91
103
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Tests if a <= b
|
|
106
|
+
* @param number equals - The value to test
|
|
107
|
+
* @returns - void
|
|
108
|
+
*/
|
|
109
|
+
toBeLessThanOrEqualTo(value: T): void {
|
|
110
|
+
if (!isInteger<T>() && !isFloat<T>())
|
|
111
|
+
ERROR("toBeLessThanOrEqualTo() can only be used on number types!");
|
|
97
112
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
* @param number equals - The value to test
|
|
101
|
-
* @returns - void
|
|
102
|
-
*/
|
|
103
|
-
toBeLessThanOrEqualTo(value: T): void {
|
|
104
|
-
if (!isInteger<T>() && !isFloat<T>()) ERROR("toBeLessThanOrEqualTo() can only be used on number types!");
|
|
113
|
+
this.verdict = this.left <= value ? Verdict.Ok : Verdict.Fail;
|
|
114
|
+
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
105
115
|
|
|
106
|
-
|
|
107
|
-
store<T>(changetype<usize>(this), value, offsetof<Expectation<T>>("right"));
|
|
116
|
+
this.op = "<=";
|
|
108
117
|
|
|
109
|
-
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
if (after_each_callback) after_each_callback();
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
if (before_each_callback) before_each_callback();
|
|
122
|
+
}
|
|
110
123
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Tests if a is string
|
|
126
|
+
* @returns - void
|
|
127
|
+
*/
|
|
128
|
+
toBeString(): void {
|
|
129
|
+
this.verdict = isString<T>() ? Verdict.Ok : Verdict.Fail;
|
|
116
130
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
* @returns - void
|
|
120
|
-
*/
|
|
121
|
-
toBeString(): void {
|
|
122
|
-
this.verdict = isString<T>() ? Verdict.Ok : Verdict.Fail;
|
|
131
|
+
this._left = nameof<T>();
|
|
132
|
+
this._right = "string";
|
|
123
133
|
|
|
124
|
-
|
|
125
|
-
this._right = "string";
|
|
134
|
+
this.op = "type";
|
|
126
135
|
|
|
127
|
-
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
if (after_each_callback) after_each_callback();
|
|
138
|
+
// @ts-ignore
|
|
139
|
+
if (before_each_callback) before_each_callback();
|
|
140
|
+
}
|
|
128
141
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Tests if a is boolean
|
|
144
|
+
* @returns - void
|
|
145
|
+
*/
|
|
146
|
+
toBeBoolean(): void {
|
|
147
|
+
this.verdict = isBoolean<T>() ? Verdict.Ok : Verdict.Fail;
|
|
134
148
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
* @returns - void
|
|
138
|
-
*/
|
|
139
|
-
toBeBoolean(): void {
|
|
140
|
-
this.verdict = isBoolean<T>() ? Verdict.Ok : Verdict.Fail;
|
|
149
|
+
this._left = nameof<T>();
|
|
150
|
+
this._right = "boolean";
|
|
141
151
|
|
|
142
|
-
|
|
143
|
-
this._right = "boolean";
|
|
152
|
+
this.op = "type";
|
|
144
153
|
|
|
145
|
-
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
if (after_each_callback) after_each_callback();
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
if (before_each_callback) before_each_callback();
|
|
158
|
+
}
|
|
146
159
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Tests if a is array
|
|
162
|
+
* @returns - void
|
|
163
|
+
*/
|
|
164
|
+
toBeArray(): void {
|
|
165
|
+
this.verdict = isArray<T>() ? Verdict.Ok : Verdict.Fail;
|
|
152
166
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
* @returns - void
|
|
156
|
-
*/
|
|
157
|
-
toBeArray(): void {
|
|
158
|
-
this.verdict = isArray<T>() ? Verdict.Ok : Verdict.Fail;
|
|
167
|
+
this._left = nameof<T>();
|
|
168
|
+
this._right = "Array<any>";
|
|
159
169
|
|
|
160
|
-
|
|
161
|
-
this._right = "Array<any>";
|
|
170
|
+
this.op = "type";
|
|
162
171
|
|
|
163
|
-
|
|
172
|
+
// @ts-ignore
|
|
173
|
+
if (after_each_callback) after_each_callback();
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
if (before_each_callback) before_each_callback();
|
|
176
|
+
}
|
|
164
177
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Tests if a is number
|
|
180
|
+
* @returns - void
|
|
181
|
+
*/
|
|
182
|
+
toBeNumber(): void {
|
|
183
|
+
this.verdict = isFloat<T>() || isInteger<T>() ? Verdict.Ok : Verdict.Fail;
|
|
170
184
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
* @returns - void
|
|
174
|
-
*/
|
|
175
|
-
toBeNumber(): void {
|
|
176
|
-
this.verdict = (isFloat<T>() || isInteger<T>()) ? Verdict.Ok : Verdict.Fail;
|
|
185
|
+
this._left = nameof<T>();
|
|
186
|
+
this._right = "number";
|
|
177
187
|
|
|
178
|
-
|
|
179
|
-
this._right = "number";
|
|
188
|
+
this.op = "type";
|
|
180
189
|
|
|
181
|
-
|
|
190
|
+
// @ts-ignore
|
|
191
|
+
if (after_each_callback) after_each_callback();
|
|
192
|
+
// @ts-ignore
|
|
193
|
+
if (before_each_callback) before_each_callback();
|
|
194
|
+
}
|
|
182
195
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Tests if a is integer
|
|
198
|
+
* @returns - void
|
|
199
|
+
*/
|
|
200
|
+
toBeInteger(): void {
|
|
201
|
+
this.verdict = isInteger<T>() ? Verdict.Ok : Verdict.Fail;
|
|
188
202
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
* @returns - void
|
|
192
|
-
*/
|
|
193
|
-
toBeInteger(): void {
|
|
194
|
-
this.verdict = isInteger<T>() ? Verdict.Ok : Verdict.Fail;
|
|
203
|
+
this._left = nameof<T>();
|
|
204
|
+
this._right = "float";
|
|
195
205
|
|
|
196
|
-
|
|
197
|
-
this._right = "float";
|
|
206
|
+
this.op = "type";
|
|
198
207
|
|
|
199
|
-
|
|
208
|
+
// @ts-ignore
|
|
209
|
+
if (after_each_callback) after_each_callback();
|
|
210
|
+
// @ts-ignore
|
|
211
|
+
if (before_each_callback) before_each_callback();
|
|
212
|
+
}
|
|
200
213
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Tests if a is float
|
|
216
|
+
* @returns - void
|
|
217
|
+
*/
|
|
218
|
+
toBeFloat(): void {
|
|
219
|
+
this.verdict = isFloat<T>() ? Verdict.Ok : Verdict.Fail;
|
|
206
220
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
* @returns - void
|
|
210
|
-
*/
|
|
211
|
-
toBeFloat(): void {
|
|
212
|
-
this.verdict = isFloat<T>() ? Verdict.Ok : Verdict.Fail;
|
|
221
|
+
this._left = nameof<T>();
|
|
222
|
+
this._right = "integer";
|
|
213
223
|
|
|
214
|
-
|
|
215
|
-
this._right = "integer";
|
|
224
|
+
this.op = "type";
|
|
216
225
|
|
|
217
|
-
|
|
226
|
+
// @ts-ignore
|
|
227
|
+
if (after_each_callback) after_each_callback();
|
|
228
|
+
// @ts-ignore
|
|
229
|
+
if (before_each_callback) before_each_callback();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Tests if a is finite
|
|
234
|
+
* @returns - void
|
|
235
|
+
*/
|
|
236
|
+
toBeFinite(): void {
|
|
237
|
+
// @ts-ignore
|
|
238
|
+
this.verdict =
|
|
239
|
+
(isFloat<T>() || isInteger<T>()) && isFinite(this.left)
|
|
240
|
+
? Verdict.Ok
|
|
241
|
+
: Verdict.Fail;
|
|
218
242
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// @ts-ignore
|
|
222
|
-
if (before_each_callback) before_each_callback();
|
|
223
|
-
}
|
|
243
|
+
this._left = "Infinity";
|
|
244
|
+
this._right = "Finite";
|
|
224
245
|
|
|
225
|
-
|
|
226
|
-
* Tests if a is finite
|
|
227
|
-
* @returns - void
|
|
228
|
-
*/
|
|
229
|
-
toBeFinite(): void {
|
|
230
|
-
// @ts-ignore
|
|
231
|
-
this.verdict = ((isFloat<T>() || isInteger<T>()) && isFinite(this.left)) ? Verdict.Ok : Verdict.Fail;
|
|
246
|
+
this.op = "=";
|
|
232
247
|
|
|
233
|
-
|
|
234
|
-
|
|
248
|
+
// @ts-ignore
|
|
249
|
+
if (after_each_callback) after_each_callback();
|
|
250
|
+
// @ts-ignore
|
|
251
|
+
if (before_each_callback) before_each_callback();
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Tests if an array has length x
|
|
256
|
+
*
|
|
257
|
+
* @param {i32} value - The value to check
|
|
258
|
+
* @returns - void
|
|
259
|
+
*/
|
|
260
|
+
toHaveLength(value: i32): void {
|
|
261
|
+
// @ts-ignore
|
|
262
|
+
this.verdict =
|
|
263
|
+
isArray<T>() && this.left.length == value ? Verdict.Ok : Verdict.Fail;
|
|
235
264
|
|
|
236
|
-
|
|
265
|
+
// @ts-ignore
|
|
266
|
+
this._left = this.left.length.toString();
|
|
267
|
+
this._right = value.toString();
|
|
237
268
|
|
|
238
|
-
|
|
239
|
-
if (after_each_callback) after_each_callback();
|
|
240
|
-
// @ts-ignore
|
|
241
|
-
if (before_each_callback) before_each_callback();
|
|
242
|
-
}
|
|
269
|
+
this.op = "length";
|
|
243
270
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (after_each_callback) after_each_callback();
|
|
262
|
-
// @ts-ignore
|
|
263
|
-
if (before_each_callback) before_each_callback();
|
|
264
|
-
}
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
if (after_each_callback) after_each_callback();
|
|
273
|
+
// @ts-ignore
|
|
274
|
+
if (before_each_callback) before_each_callback();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Tests if an array contains an element
|
|
279
|
+
*
|
|
280
|
+
* @param { valueof<T> } value - The value to check
|
|
281
|
+
* @returns - void
|
|
282
|
+
*/
|
|
283
|
+
// @ts-ignore
|
|
284
|
+
toContain(value: valueof<T>): void {
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
this.verdict =
|
|
287
|
+
isArray<T>() && this.left.includes(value) ? Verdict.Ok : Verdict.Fail;
|
|
265
288
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
* @returns - void
|
|
271
|
-
*/
|
|
272
|
-
// @ts-ignore
|
|
273
|
-
toContain(value: valueof<T>): void {
|
|
274
|
-
// @ts-ignore
|
|
275
|
-
this.verdict = (isArray<T>() && this.left.includes(value)) ? Verdict.Ok : Verdict.Fail;
|
|
276
|
-
|
|
277
|
-
// @ts-ignore
|
|
278
|
-
this._left = "includes value";
|
|
279
|
-
this._right = "does not include value";
|
|
280
|
-
this.op = "=";
|
|
281
|
-
|
|
282
|
-
// @ts-ignore
|
|
283
|
-
if (after_each_callback) after_each_callback();
|
|
284
|
-
// @ts-ignore
|
|
285
|
-
if (before_each_callback) before_each_callback();
|
|
286
|
-
}
|
|
289
|
+
// @ts-ignore
|
|
290
|
+
this._left = "includes value";
|
|
291
|
+
this._right = "does not include value";
|
|
292
|
+
this.op = "=";
|
|
287
293
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// @ts-ignore
|
|
317
|
-
if (after_each_callback) after_each_callback();
|
|
318
|
-
// @ts-ignore
|
|
319
|
-
if (before_each_callback) before_each_callback();
|
|
294
|
+
// @ts-ignore
|
|
295
|
+
if (after_each_callback) after_each_callback();
|
|
296
|
+
// @ts-ignore
|
|
297
|
+
if (before_each_callback) before_each_callback();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Tests for equality
|
|
302
|
+
* @param {T} equals - The value to test
|
|
303
|
+
* @returns - void
|
|
304
|
+
*/
|
|
305
|
+
toBe(equals: T): void {
|
|
306
|
+
store<T>(
|
|
307
|
+
changetype<usize>(this),
|
|
308
|
+
equals,
|
|
309
|
+
offsetof<Expectation<T>>("right"),
|
|
310
|
+
);
|
|
311
|
+
if (isBoolean<T>()) {
|
|
312
|
+
this.verdict = this.left === equals ? Verdict.Ok : Verdict.Fail;
|
|
313
|
+
} else if (isString<T>()) {
|
|
314
|
+
this.verdict = this.left === equals ? Verdict.Ok : Verdict.Fail;
|
|
315
|
+
} else if (isInteger<T>() || isFloat<T>()) {
|
|
316
|
+
this.verdict = this.left === equals ? Verdict.Ok : Verdict.Fail;
|
|
317
|
+
} else if (isArray<T>()) {
|
|
318
|
+
// getArrayDepth<T>();
|
|
319
|
+
} else {
|
|
320
|
+
this.verdict = Verdict.Unreachable;
|
|
320
321
|
}
|
|
321
322
|
|
|
322
|
-
|
|
323
|
-
if (!this._not && this.verdict === Verdict.Ok) return null;
|
|
324
|
-
|
|
325
|
-
const left = this._left || visualize(this.left);
|
|
326
|
-
const right = this._right || visualize(load<T>(changetype<usize>(this), offsetof<Expectation<T>>("right")));
|
|
323
|
+
this.op = "=";
|
|
327
324
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
325
|
+
// @ts-ignore
|
|
326
|
+
if (after_each_callback) after_each_callback();
|
|
327
|
+
// @ts-ignore
|
|
328
|
+
if (before_each_callback) before_each_callback();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
report(): string | null {
|
|
332
|
+
if (!this._not && this.verdict === Verdict.Ok) return null;
|
|
333
|
+
|
|
334
|
+
const left = this._left || visualize(this.left);
|
|
335
|
+
const right =
|
|
336
|
+
this._right ||
|
|
337
|
+
visualize(
|
|
338
|
+
load<T>(changetype<usize>(this), offsetof<Expectation<T>>("right")),
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
if (this._not) {
|
|
342
|
+
if (this.verdict === Verdict.Fail) return null;
|
|
343
|
+
const dif = diff(left, right, true);
|
|
344
|
+
return (
|
|
345
|
+
rainbow.red(" - Test failed") +
|
|
346
|
+
"\n" +
|
|
347
|
+
rainbow.italicMk(
|
|
348
|
+
` ${rainbow.dimMk("(expected) ->")} ${dif.left.toString()}\n ${rainbow.dimMk("[ !" + this.op + " ]")}\n ${rainbow.dimMk("(recieved) ->")} ${dif.right.toString()}`,
|
|
349
|
+
)
|
|
350
|
+
);
|
|
351
|
+
}
|
|
333
352
|
|
|
334
|
-
|
|
353
|
+
if (left == right) return null;
|
|
335
354
|
|
|
336
|
-
|
|
355
|
+
const dif = diff(left, right);
|
|
337
356
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
357
|
+
return (
|
|
358
|
+
rainbow.red(" - Test failed") +
|
|
359
|
+
"\n" +
|
|
360
|
+
rainbow.italicMk(
|
|
361
|
+
` ${rainbow.dimMk("(expected) ->")} ${dif.left.toString()}\n ${rainbow.dimMk("[ " + this.op + " ]")}\n ${rainbow.dimMk("(recieved) ->")} ${dif.right.toString()}`,
|
|
362
|
+
)
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|