@gjsify/util 0.0.3 → 0.1.0

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/src/index.spec.ts CHANGED
@@ -1,256 +1,440 @@
1
1
  import { describe, it, expect } from '@gjsify/unit';
2
- import * as util from 'util';
2
+ import * as util from 'node:util';
3
3
 
4
- // https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
4
+ // Ported from refs/node/test/parallel/test-util-format.js,
5
+ // test-util-promisify.js, test-util-inherits.js, test-util-types.js
6
+ // Original: MIT license, Node.js contributors
7
+
8
+ // Helper to strip ANSI colors
5
9
  const ANSI_PATTERN = new RegExp(
6
10
  [
7
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
8
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
11
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
12
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
9
13
  ].join("|"),
10
14
  "g",
11
15
  );
12
-
13
- // TODO build deno_std/fmt for this method
16
+
14
17
  function stripColor(string: string): string {
15
18
  return string.replace(ANSI_PATTERN, "");
16
19
  }
17
-
18
20
 
19
21
  export default async () => {
20
- // See packages/deno/deno_std/original/node/util_test.ts
21
- await describe('[util] format', async () => {
22
- await it('should return the right result', async () => {
23
- expect(util.format("%o", [10, 11])).toBe("[ 10, 11, [length]: 2 ]");
22
+ // ==================== format — no args / single values ====================
23
+
24
+ await describe('util.format: basic', async () => {
25
+ await it('should return empty string with no args', async () => {
26
+ expect(util.format()).toBe('');
24
27
  });
25
- });
26
28
 
29
+ await it('should format empty string', async () => {
30
+ expect(util.format('')).toBe('');
31
+ });
27
32
 
28
- await describe("[util] inspect.custom", async () => {
29
- await it('should be the symbol for nodejs.util.inspect.custom', async () => {
30
- expect(util.inspect.custom.description).toEqual("nodejs.util.inspect.custom");
33
+ await it('should format object', async () => {
34
+ expect(util.format({})).toBe('{}');
31
35
  });
32
- });
33
36
 
34
- await describe("[util] inspect", async () => {
37
+ await it('should format null', async () => {
38
+ expect(util.format(null)).toBe('null');
39
+ });
35
40
 
36
- await it('should return the right results', async () => {
37
- expect(stripColor(util.inspect({ foo: 123 }))).toBe("{ foo: 123 }");
38
- expect(stripColor(util.inspect("Deno's logo is so cute."))).toBe(`"Deno's logo is so cute."`);
39
- expect(stripColor(util.inspect([1, 2, 3, 4, 5, 6, 7]))).toBe(`[
40
- 1, 2, 3, 4,
41
- 5, 6, 7
42
- ]`
43
- );
41
+ await it('should format true/false', async () => {
42
+ expect(util.format(true)).toBe('true');
43
+ expect(util.format(false)).toBe('false');
44
+ });
45
+
46
+ await it('should format plain string', async () => {
47
+ expect(util.format('test')).toBe('test');
44
48
  });
45
- });
46
49
 
47
- await describe("[util] isBoolean", async () => {
50
+ await it('should join multiple args with space', async () => {
51
+ expect(util.format('foo', 'bar', 'baz')).toBe('foo bar baz');
52
+ });
48
53
 
49
- await it('should return the right results', async () => {
50
- expect(util.isBoolean(true)).toBeTruthy();
51
- // TODO: this is true in Gjs / Deno but false in Node.js
52
- // expect(util.isBoolean(new Boolean())).toBeTruthy();
53
- // expect(util.isBoolean(new Boolean(true))).toBeTruthy();
54
- expect(util.isBoolean(false)).toBeTruthy();
55
- expect(util.isBoolean("deno")).toBeFalsy();
56
- expect(util.isBoolean("true")).toBeFalsy();
54
+ await it('should format Symbol', async () => {
55
+ expect(util.format(Symbol('foo'))).toBe('Symbol(foo)');
57
56
  });
58
57
  });
59
58
 
60
- await describe("[util] isNull", async () => {
61
- await it('should return the right results', async () => {
62
- let n;
63
- expect(util.isNull(null)).toBeTruthy();
64
- expect(util.isNull(n)).toBeFalsy();
65
- expect(util.isNull(0)).toBeFalsy();
66
- expect(util.isNull({})).toBeFalsy();
59
+ // ==================== format %% (literal percent) ====================
60
+
61
+ await describe('util.format: %%', async () => {
62
+ await it('should handle %% with args', async () => {
63
+ expect(util.format('%% %s', 'foo')).toBe('% foo');
64
+ expect(util.format('%%', 'x')).toBe('% x');
67
65
  });
68
66
  });
69
67
 
70
- await describe("[util] isNullOrUndefined", async () => {
71
- await it('should return the right results', async () => {
72
- let n;
73
- expect(util.isNullOrUndefined(null)).toBeTruthy();
74
- expect(util.isNullOrUndefined(n)).toBeTruthy();
75
- expect(util.isNullOrUndefined({})).toBeFalsy();
76
- expect(util.isNullOrUndefined("undefined")).toBeFalsy();
68
+ // ==================== format %d (number) ====================
69
+
70
+ await describe('util.format: %d', async () => {
71
+ await it('should format integers', async () => {
72
+ expect(util.format('%d', 42.0)).toBe('42');
73
+ expect(util.format('%d', 42)).toBe('42');
77
74
  });
78
- });
79
75
 
80
- await describe("[util] isNumber", async () => {
81
- await it('should return the right results', async () => {
82
- expect(util.isNumber(666)).toBeTruthy();
83
- // TODO: this is true in Gjs / Deno but false in Node.js
84
- // expect(util.isNumber(new Number(666))).toBeTruthy();
85
- expect(util.isNumber("999")).toBeFalsy();
86
- expect(util.isNumber(null)).toBeFalsy();
76
+ await it('should format floats', async () => {
77
+ expect(util.format('%d', 1.5)).toBe('1.5');
78
+ expect(util.format('%d', -0.5)).toBe('-0.5');
87
79
  });
88
- });
89
80
 
90
- await describe("[util] isString", async () => {
91
- await it('should return the right results', async () => {
92
- expect(util.isString("deno")).toBeTruthy();
93
- // TODO: this is true in Gjs / Deno but false in Node.js
94
- // expect(util.isString(new String("DIO"))).toBeTruthy();
95
- expect(util.isString(1337)).toBeFalsy();
81
+ await it('should format -0', async () => {
82
+ expect(util.format('%d', -0.0)).toBe('-0');
96
83
  });
97
- });
98
84
 
99
- await describe("[util] isSymbol", async () => {
100
- await it('should return the right results', async () => {
101
- expect(util.isSymbol(Symbol())).toBeTruthy();
102
- expect(util.isSymbol(123)).toBeFalsy();
103
- expect(util.isSymbol("string")).toBeFalsy();
85
+ await it('should format Symbol as NaN', async () => {
86
+ expect(util.format('%d', Symbol())).toBe('NaN');
104
87
  });
105
- });
106
88
 
107
- await describe("[util] isUndefined", async () => {
108
- await it('should return the right results', async () => {
109
- let t;
110
- expect(util.isUndefined(t)).toBeTruthy();
111
- expect(util.isUndefined("undefined")).toBeFalsy();
112
- expect(util.isUndefined({})).toBeFalsy();
89
+ await it('should format BigInt', async () => {
90
+ expect(util.format('%d', 1180591620717411303424n)).toBe('1180591620717411303424n');
91
+ });
92
+
93
+ await it('should format Infinity', async () => {
94
+ expect(util.format('%d', Infinity)).toBe('Infinity');
95
+ expect(util.format('%d', -Infinity)).toBe('-Infinity');
96
+ });
97
+
98
+ await it('should handle multiple %d', async () => {
99
+ expect(util.format('%d %d', 42, 43)).toBe('42 43');
100
+ });
101
+
102
+ await it('should return %d with no args', async () => {
103
+ expect(util.format('%d')).toBe('%d');
113
104
  });
114
105
  });
115
106
 
116
- await describe("[util] isObject", async () => {
117
- await it('should return the right results', async () => {
118
- const dio = { stand: "Za Warudo" };
119
- expect(util.isObject(dio)).toBeTruthy();
120
- expect(util.isObject(new RegExp(/Toki Wo Tomare/))).toBeTruthy();
121
- expect(util.isObject("Jotaro")).toBeFalsy();
107
+ // ==================== format %i (integer) ====================
108
+
109
+ await describe('util.format: %i', async () => {
110
+ await it('should truncate to integer', async () => {
111
+ expect(util.format('%i', 42)).toBe('42');
112
+ expect(util.format('%i', 1.5)).toBe('1');
113
+ });
114
+
115
+ await it('should format -0.5 as -0', async () => {
116
+ expect(util.format('%i', -0.5)).toBe('-0');
117
+ });
118
+
119
+ await it('should format Infinity as NaN', async () => {
120
+ expect(util.format('%i', Infinity)).toBe('NaN');
121
+ });
122
+
123
+ await it('should format BigInt', async () => {
124
+ expect(util.format('%i', 1180591620717411303424n)).toBe('1180591620717411303424n');
122
125
  });
123
126
  });
124
127
 
125
- await describe("[util] isError", async () => {
126
- await it('should return the right results', async () => {
127
- const java = new Error();
128
- const nodejs = new TypeError();
129
- const deno = "Future";
130
- expect(util.isError(java)).toBeTruthy();
131
- expect(util.isError(nodejs)).toBeTruthy();
132
- expect(util.isError(deno)).toBeFalsy();
128
+ // ==================== format %f (float) ====================
129
+
130
+ await describe('util.format: %f', async () => {
131
+ await it('should format numbers', async () => {
132
+ expect(util.format('%f', 42)).toBe('42');
133
+ expect(util.format('%f', 1.5)).toBe('1.5');
134
+ });
135
+
136
+ await it('should format Symbol as NaN', async () => {
137
+ expect(util.format('%f', Symbol('foo'))).toBe('NaN');
138
+ });
139
+
140
+ await it('should format BigInt', async () => {
141
+ expect(util.format('%f', 5n)).toBe('5');
133
142
  });
134
143
  });
135
144
 
136
- await describe("[util] isFunction", async () => {
137
- await it('should return the right results', async () => {
138
- const f = function () { };
139
- expect(util.isFunction(f)).toBeTruthy();
140
- expect(util.isFunction({})).toBeFalsy();
141
- expect(util.isFunction(new RegExp(/f/))).toBeFalsy();
145
+ // ==================== format %s (string) ====================
146
+
147
+ await describe('util.format: %s', async () => {
148
+ await it('should format primitives', async () => {
149
+ expect(util.format('%s', undefined)).toBe('undefined');
150
+ expect(util.format('%s', null)).toBe('null');
151
+ expect(util.format('%s', 'foo')).toBe('foo');
152
+ expect(util.format('%s', 42)).toBe('42');
153
+ expect(util.format('%s', true)).toBe('true');
154
+ });
155
+
156
+ await it('should format -0', async () => {
157
+ expect(util.format('%s', -0)).toBe('-0');
158
+ });
159
+
160
+ await it('should format BigInt with n suffix', async () => {
161
+ expect(util.format('%s', 42n)).toBe('42n');
162
+ });
163
+
164
+ await it('should format Symbol', async () => {
165
+ expect(util.format('%s', Symbol('foo'))).toBe('Symbol(foo)');
166
+ });
167
+
168
+ await it('should format Infinity', async () => {
169
+ expect(util.format('%s', Infinity)).toBe('Infinity');
170
+ });
171
+
172
+ await it('should handle multiple %s', async () => {
173
+ expect(util.format('%s %s', 42, 43)).toBe('42 43');
142
174
  });
143
175
  });
144
176
 
145
- await describe("[util] isRegExp", async () => {
146
- await it('should return the right results', async () => {
147
- expect(util.isRegExp(new RegExp(/f/))).toBeTruthy();
148
- expect(util.isRegExp(/fuManchu/)).toBeTruthy();
149
- expect(util.isRegExp({ evil: "eye" })).toBeFalsy();
150
- expect(util.isRegExp(null)).toBeFalsy();
177
+ // ==================== format %j (JSON) ====================
178
+
179
+ await describe('util.format: %j', async () => {
180
+ await it('should format objects as JSON', async () => {
181
+ expect(util.format('%j', { foo: 'bar' })).toBe('{"foo":"bar"}');
182
+ });
183
+
184
+ await it('should handle circular references', async () => {
185
+ const obj: Record<string, unknown> = {};
186
+ obj.self = obj;
187
+ expect(util.format('%j', obj)).toBe('[Circular]');
151
188
  });
152
189
  });
153
190
 
154
- await describe("[util] isArray", async () => {
155
- await it('should return the right results', async () => {
156
- expect(util.isArray([])).toBeTruthy();
157
- expect(util.isArray({ yaNo: "array" })).toBeFalsy();
158
- expect(util.isArray(null)).toBeFalsy();
191
+ // ==================== inspect ====================
192
+
193
+ await describe('util.inspect', async () => {
194
+ await it('should inspect objects', async () => {
195
+ expect(stripColor(util.inspect({ foo: 123 }))).toBe('{ foo: 123 }');
196
+ });
197
+
198
+ await it('should inspect strings with quotes', async () => {
199
+ expect(stripColor(util.inspect("Deno's logo is so cute.")))
200
+ .toBe(`"Deno's logo is so cute."`);
201
+ });
202
+
203
+ await it('should have custom symbol', async () => {
204
+ expect(util.inspect.custom.description).toBe('nodejs.util.inspect.custom');
205
+ });
206
+
207
+ await it('should handle custom inspect', async () => {
208
+ const obj = {
209
+ [Symbol.for('nodejs.util.inspect.custom')]() {
210
+ return 'custom output';
211
+ }
212
+ };
213
+ expect(util.inspect(obj)).toBe('custom output');
159
214
  });
160
215
  });
161
216
 
162
- await describe("[util] isPrimitive", async () => {
163
- await it('should return the right results', async () => {
164
- const stringType = "hasti";
165
- const booleanType = true;
166
- const integerType = 2;
167
- const symbolType = Symbol("anything");
168
-
169
- const functionType = function doBest() { };
170
- const objectType = { name: "ali" };
171
- const arrayType = [1, 2, 3];
172
-
173
- expect(util.isPrimitive(stringType)).toBeTruthy();
174
- expect(util.isPrimitive(booleanType)).toBeTruthy();
175
- expect(util.isPrimitive(integerType)).toBeTruthy();
176
- expect(util.isPrimitive(symbolType)).toBeTruthy();
177
- expect(util.isPrimitive(null)).toBeTruthy();
178
- expect(util.isPrimitive(undefined)).toBeTruthy();
179
- expect(util.isPrimitive(functionType)).toBeFalsy();
180
- expect(util.isPrimitive(arrayType)).toBeFalsy();
181
- expect(util.isPrimitive(objectType)).toBeFalsy();
217
+ // ==================== promisify ====================
218
+
219
+ await describe('util.promisify', async () => {
220
+ await it('should promisify a callback function', async () => {
221
+ function callbackFn(val: string, cb: (err: Error | null, result?: string) => void) {
222
+ cb(null, val + ' done');
223
+ }
224
+ const promisified = util.promisify(callbackFn);
225
+ const result = await promisified('test');
226
+ expect(result).toBe('test done');
227
+ });
228
+
229
+ await it('should reject on error', async () => {
230
+ function callbackFn(cb: (err: Error | null) => void) {
231
+ cb(new Error('test error'));
232
+ }
233
+ const promisified = util.promisify(callbackFn);
234
+ try {
235
+ await promisified();
236
+ expect(false).toBeTruthy(); // should not reach
237
+ } catch (err: unknown) {
238
+ expect((err as Error).message).toBe('test error');
239
+ }
240
+ });
241
+
242
+ await it('should use custom promisify symbol', async () => {
243
+ function customFn() { /* noop */ }
244
+ (customFn as any)[util.promisify.custom] = () => Promise.resolve('custom');
245
+ const promisified = util.promisify(customFn);
246
+ const result = await promisified();
247
+ expect(result).toBe('custom');
248
+ });
249
+
250
+ await it('should throw on non-function', async () => {
251
+ expect(() => util.promisify('not a function' as any)).toThrow();
182
252
  });
183
253
  });
184
254
 
185
- await describe("[util] TextDecoder", async () => {
186
- await it('should return the right results', async () => {
187
- expect(util.TextDecoder === TextDecoder).toBeTruthy();
188
- const td: util.TextDecoder = new util.TextDecoder();
189
- expect(td instanceof TextDecoder).toBeTruthy();
255
+ // ==================== callbackify ====================
256
+
257
+ await describe('util.callbackify', async () => {
258
+ await it('should throw on non-function', async () => {
259
+ expect(() => util.callbackify('not a function' as any)).toThrow();
260
+ });
261
+
262
+ await it('should return a function', async () => {
263
+ async function asyncFn() { return 'resolved'; }
264
+ const callbacked = util.callbackify(asyncFn);
265
+ expect(typeof callbacked).toBe('function');
190
266
  });
191
267
  });
192
268
 
193
- await describe("[util] TextEncoder", async () => {
194
- await it('should return the right results', async () => {
195
- expect(util.TextEncoder === TextEncoder).toBeTruthy();
196
- const te: util.TextEncoder = new util.TextEncoder();
197
- expect(te instanceof TextEncoder).toBeTruthy();
269
+ // ==================== inherits ====================
270
+
271
+ await describe('util.inherits', async () => {
272
+ await it('should set up prototype chain', async () => {
273
+ function Parent() { /* noop */ }
274
+ Parent.prototype.hello = function () { return 'hello'; };
275
+ function Child() { /* noop */ }
276
+ util.inherits(Child, Parent);
277
+ expect(Object.getPrototypeOf(Child.prototype)).toBe(Parent.prototype);
278
+ });
279
+
280
+ await it('should set super_ property', async () => {
281
+ function Parent() { /* noop */ }
282
+ function Child() { /* noop */ }
283
+ util.inherits(Child, Parent);
284
+ expect((Child as any).super_).toBe(Parent);
285
+ });
286
+
287
+ await it('should throw on null constructor', async () => {
288
+ expect(() => util.inherits(null as any, function () { /* noop */ })).toThrow();
289
+ });
290
+
291
+ await it('should throw on null super constructor', async () => {
292
+ expect(() => util.inherits(function () { /* noop */ }, null as any)).toThrow();
293
+ });
294
+
295
+ await it('should throw on super without prototype', async () => {
296
+ const fn = function () { /* noop */ };
297
+ (fn as any).prototype = undefined;
298
+ expect(() => util.inherits(function () { /* noop */ }, fn)).toThrow();
198
299
  });
199
300
  });
200
301
 
201
- await describe("[util] isDate", async () => {
202
- await it('should return the right results', async () => {
203
- // Test verifies the method is exposed. See _util/_util_types_test for details
302
+ // ==================== types ====================
303
+
304
+ await describe('util.types', async () => {
305
+ await it('isDate', async () => {
204
306
  expect(util.types.isDate(new Date())).toBeTruthy();
307
+ expect(util.types.isDate(Date.now())).toBeFalsy();
308
+ expect(util.types.isDate('2024-01-01')).toBeFalsy();
309
+ });
310
+
311
+ await it('isRegExp', async () => {
312
+ expect(util.types.isRegExp(/abc/)).toBeTruthy();
313
+ expect(util.types.isRegExp(new RegExp('abc'))).toBeTruthy();
314
+ expect(util.types.isRegExp('abc')).toBeFalsy();
315
+ });
316
+
317
+ await it('isMap', async () => {
318
+ expect(util.types.isMap(new Map())).toBeTruthy();
319
+ expect(util.types.isMap({})).toBeFalsy();
320
+ });
321
+
322
+ await it('isSet', async () => {
323
+ expect(util.types.isSet(new Set())).toBeTruthy();
324
+ expect(util.types.isSet([])).toBeFalsy();
325
+ });
326
+
327
+ await it('isWeakMap', async () => {
328
+ expect(util.types.isWeakMap(new WeakMap())).toBeTruthy();
329
+ expect(util.types.isWeakMap(new Map())).toBeFalsy();
330
+ });
331
+
332
+ await it('isWeakSet', async () => {
333
+ expect(util.types.isWeakSet(new WeakSet())).toBeTruthy();
334
+ expect(util.types.isWeakSet(new Set())).toBeFalsy();
335
+ });
336
+
337
+ await it('isPromise', async () => {
338
+ expect(util.types.isPromise(Promise.resolve())).toBeTruthy();
339
+ expect(util.types.isPromise({})).toBeFalsy();
340
+ });
341
+
342
+ await it('isArrayBuffer', async () => {
343
+ expect(util.types.isArrayBuffer(new ArrayBuffer(8))).toBeTruthy();
344
+ expect(util.types.isArrayBuffer(new Uint8Array(8))).toBeFalsy();
345
+ });
346
+
347
+ await it('isTypedArray', async () => {
348
+ expect(util.types.isTypedArray(new Uint8Array())).toBeTruthy();
349
+ expect(util.types.isTypedArray(new Float64Array())).toBeTruthy();
350
+ expect(util.types.isTypedArray(new ArrayBuffer(8))).toBeFalsy();
351
+ });
352
+
353
+ await it('isUint8Array', async () => {
354
+ expect(util.types.isUint8Array(new Uint8Array())).toBeTruthy();
355
+ expect(util.types.isUint8Array(new Uint16Array())).toBeFalsy();
356
+ });
357
+
358
+ await it('isDataView', async () => {
359
+ const buf = new ArrayBuffer(8);
360
+ expect(util.types.isDataView(new DataView(buf))).toBeTruthy();
361
+ expect(util.types.isDataView(new Uint8Array(buf))).toBeFalsy();
362
+ });
363
+
364
+ await it('isAsyncFunction', async () => {
365
+ expect(util.types.isAsyncFunction(async function () { /* noop */ })).toBeTruthy();
366
+ expect(util.types.isAsyncFunction(function () { /* noop */ })).toBeFalsy();
367
+ });
368
+
369
+ await it('isGeneratorFunction', async () => {
370
+ expect(util.types.isGeneratorFunction(function* () { /* noop */ })).toBeTruthy();
371
+ expect(util.types.isGeneratorFunction(function () { /* noop */ })).toBeFalsy();
372
+ });
373
+
374
+ await it('isNativeError', async () => {
375
+ expect(util.types.isNativeError(new Error())).toBeTruthy();
376
+ expect(util.types.isNativeError(new TypeError())).toBeTruthy();
377
+ expect(util.types.isNativeError({ message: 'error' })).toBeFalsy();
205
378
  });
206
379
  });
207
380
 
208
- await describe("[util] getSystemErrorName()", async () => {
209
- await it('should return the right results', async () => {
210
- type FnTestInvalidArg = (code?: unknown) => void;
381
+ // ==================== isDeepStrictEqual ====================
211
382
 
212
- expect(
213
- () => (util.getSystemErrorName as FnTestInvalidArg)(),
214
- ).toThrow();
383
+ await describe('util.isDeepStrictEqual', async () => {
384
+ await it('should compare primitives', async () => {
385
+ expect(util.isDeepStrictEqual(1, 1)).toBeTruthy();
386
+ expect(util.isDeepStrictEqual('a', 'a')).toBeTruthy();
387
+ expect(util.isDeepStrictEqual(1, 2)).toBeFalsy();
388
+ expect(util.isDeepStrictEqual(1, '1')).toBeFalsy();
389
+ });
215
390
 
216
- try {
217
- (util.getSystemErrorName as FnTestInvalidArg)()
218
- } catch (error) {
219
- expect(error instanceof Error).toBeTruthy();
220
- expect(error instanceof TypeError).toBeTruthy();
221
- }
391
+ await it('should compare objects', async () => {
392
+ expect(util.isDeepStrictEqual({ a: 1 }, { a: 1 })).toBeTruthy();
393
+ expect(util.isDeepStrictEqual({ a: 1 }, { a: 2 })).toBeFalsy();
394
+ expect(util.isDeepStrictEqual({ a: 1 }, { b: 1 })).toBeFalsy();
395
+ });
222
396
 
223
- expect(
224
- () => (util.getSystemErrorName as FnTestInvalidArg)(1),
225
- ).toThrow();
397
+ await it('should compare arrays', async () => {
398
+ expect(util.isDeepStrictEqual([1, 2, 3], [1, 2, 3])).toBeTruthy();
399
+ expect(util.isDeepStrictEqual([1, 2], [1, 2, 3])).toBeFalsy();
400
+ });
226
401
 
227
- try {
228
- (util.getSystemErrorName as FnTestInvalidArg)(1)
229
- } catch (error) {
230
- expect(error instanceof Error).toBeTruthy();
231
- expect(error instanceof RangeError).toBeTruthy();
232
- }
233
-
234
- // FIXME: Returns undefined on Deno
235
- expect(util.getSystemErrorName(-424242)).toBe('Unknown system error -424242');
236
-
237
- // TODO
238
- const os = globalThis.process?.platform || (globalThis as any).Deno?.build?.os || 'linux';
239
-
240
- switch (os) {
241
- case "win32":
242
- case "windows" as any:
243
- expect(util.getSystemErrorName(-4091)).toBe("EADDRINUSE");
244
- break;
245
-
246
- case "darwin":
247
- expect(util.getSystemErrorName(-48)).toBe("EADDRINUSE");
248
- break;
249
-
250
- case "linux":
251
- expect(util.getSystemErrorName(-98)).toBe("EADDRINUSE");
252
- break;
253
- }
402
+ await it('should compare nested objects', async () => {
403
+ expect(util.isDeepStrictEqual({ a: { b: 1 } }, { a: { b: 1 } })).toBeTruthy();
404
+ expect(util.isDeepStrictEqual({ a: { b: 1 } }, { a: { b: 2 } })).toBeFalsy();
405
+ });
406
+
407
+ await it('should compare Date objects', async () => {
408
+ const d = new Date('2024-01-01');
409
+ expect(util.isDeepStrictEqual(d, new Date('2024-01-01'))).toBeTruthy();
410
+ expect(util.isDeepStrictEqual(d, new Date('2024-01-02'))).toBeFalsy();
411
+ });
412
+
413
+ await it('should compare RegExp objects', async () => {
414
+ expect(util.isDeepStrictEqual(/abc/g, /abc/g)).toBeTruthy();
415
+ expect(util.isDeepStrictEqual(/abc/g, /abc/i)).toBeFalsy();
254
416
  });
255
417
  });
256
- }
418
+
419
+ // ==================== TextEncoder / TextDecoder ====================
420
+
421
+ await describe('util.TextEncoder/TextDecoder', async () => {
422
+ await it('TextEncoder should be available', async () => {
423
+ expect(util.TextEncoder === TextEncoder).toBeTruthy();
424
+ });
425
+
426
+ await it('TextDecoder should be available', async () => {
427
+ expect(util.TextDecoder === TextDecoder).toBeTruthy();
428
+ });
429
+ });
430
+
431
+ // ==================== isArray ====================
432
+
433
+ await describe('util.isArray', async () => {
434
+ await it('should detect arrays', async () => {
435
+ expect(util.isArray([])).toBeTruthy();
436
+ expect(util.isArray({})).toBeFalsy();
437
+ expect(util.isArray(null)).toBeFalsy();
438
+ });
439
+ });
440
+ };