@mtkruto/node 0.0.971 → 0.0.973

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.
Files changed (135) hide show
  1. package/esm/constants.d.ts +1 -1
  2. package/esm/constants.js +1 -1
  3. package/esm/deps/deno.land/std@0.196.0/assert/_constants.d.ts +1 -0
  4. package/esm/deps/deno.land/std@0.196.0/assert/_constants.js +2 -0
  5. package/esm/deps/deno.land/std@0.196.0/assert/assert.d.ts +2 -0
  6. package/esm/deps/deno.land/std@0.196.0/assert/assert.js +8 -0
  7. package/esm/deps/deno.land/std@0.196.0/assert/assert_almost_equals.d.ts +18 -0
  8. package/esm/deps/deno.land/std@0.196.0/assert/assert_almost_equals.js +32 -0
  9. package/esm/deps/deno.land/std@0.196.0/assert/assert_array_includes.d.ts +14 -0
  10. package/esm/deps/deno.land/std@0.196.0/assert/assert_array_includes.js +38 -0
  11. package/esm/deps/deno.land/std@0.196.0/assert/assert_equals.d.ts +17 -0
  12. package/esm/deps/deno.land/std@0.196.0/assert/assert_equals.js +45 -0
  13. package/esm/deps/deno.land/std@0.196.0/assert/assert_exists.d.ts +5 -0
  14. package/esm/deps/deno.land/std@0.196.0/assert/assert_exists.js +14 -0
  15. package/esm/deps/deno.land/std@0.196.0/assert/assert_false.d.ts +4 -0
  16. package/esm/deps/deno.land/std@0.196.0/assert/assert_false.js +7 -0
  17. package/esm/deps/deno.land/std@0.196.0/assert/assert_instance_of.d.ts +8 -0
  18. package/esm/deps/deno.land/std@0.196.0/assert/assert_instance_of.js +38 -0
  19. package/esm/deps/deno.land/std@0.196.0/assert/assert_is_error.d.ts +7 -0
  20. package/esm/deps/deno.land/std@0.196.0/assert/assert_is_error.js +26 -0
  21. package/esm/deps/deno.land/std@0.196.0/assert/assert_match.d.ts +5 -0
  22. package/esm/deps/deno.land/std@0.196.0/assert/assert_match.js +13 -0
  23. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_equals.d.ts +14 -0
  24. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_equals.js +37 -0
  25. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_instance_of.d.ts +5 -0
  26. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_instance_of.js +14 -0
  27. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_match.d.ts +5 -0
  28. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_match.js +14 -0
  29. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_strict_equals.d.ts +11 -0
  30. package/esm/deps/deno.land/std@0.196.0/assert/assert_not_strict_equals.js +20 -0
  31. package/esm/deps/deno.land/std@0.196.0/assert/assert_object_match.d.ts +5 -0
  32. package/esm/deps/deno.land/std@0.196.0/assert/assert_object_match.js +78 -0
  33. package/esm/deps/deno.land/std@0.196.0/assert/assert_rejects.d.ts +64 -0
  34. package/esm/deps/deno.land/std@0.196.0/assert/assert_rejects.js +50 -0
  35. package/esm/deps/deno.land/std@0.196.0/assert/assert_strict_equals.d.ts +23 -0
  36. package/esm/deps/deno.land/std@0.196.0/assert/assert_strict_equals.js +60 -0
  37. package/esm/deps/deno.land/std@0.196.0/assert/assert_string_includes.d.ts +5 -0
  38. package/esm/deps/deno.land/std@0.196.0/assert/assert_string_includes.js +13 -0
  39. package/esm/deps/deno.land/std@0.196.0/assert/assert_throws.d.ts +54 -0
  40. package/esm/deps/deno.land/std@0.196.0/assert/assert_throws.js +44 -0
  41. package/esm/deps/deno.land/std@0.196.0/assert/assertion_error.d.ts +4 -0
  42. package/esm/deps/deno.land/std@0.196.0/assert/assertion_error.js +12 -0
  43. package/esm/deps/deno.land/std@0.196.0/assert/equal.d.ts +6 -0
  44. package/esm/deps/deno.land/std@0.196.0/assert/equal.js +102 -0
  45. package/esm/deps/deno.land/std@0.196.0/assert/fail.d.ts +4 -0
  46. package/esm/deps/deno.land/std@0.196.0/assert/fail.js +9 -0
  47. package/esm/deps/deno.land/std@0.196.0/assert/mod.d.ts +32 -0
  48. package/esm/deps/deno.land/std@0.196.0/assert/mod.js +33 -0
  49. package/esm/deps/deno.land/std@0.196.0/assert/unimplemented.d.ts +2 -0
  50. package/esm/deps/deno.land/std@0.196.0/assert/unimplemented.js +7 -0
  51. package/esm/deps/deno.land/std@0.196.0/assert/unreachable.d.ts +2 -0
  52. package/esm/deps/deno.land/std@0.196.0/assert/unreachable.js +6 -0
  53. package/esm/deps/deno.land/{std@0.190.0 → std@0.196.0}/fmt/colors.js +2 -2
  54. package/{script/deps/deno.land/std@0.190.0 → esm/deps/deno.land/std@0.196.0}/testing/asserts.d.ts +204 -159
  55. package/esm/deps/deno.land/std@0.196.0/testing/asserts.js +330 -0
  56. package/esm/deps.d.ts +2 -2
  57. package/esm/deps.js +2 -2
  58. package/esm/storage/0_storage.d.ts +1 -1
  59. package/esm/storage/0_storage.js +7 -2
  60. package/package.json +1 -1
  61. package/script/constants.d.ts +1 -1
  62. package/script/constants.js +1 -1
  63. package/script/deps/deno.land/std@0.196.0/assert/_constants.d.ts +1 -0
  64. package/script/deps/deno.land/std@0.196.0/assert/_constants.js +5 -0
  65. package/script/deps/deno.land/std@0.196.0/assert/assert.d.ts +2 -0
  66. package/script/deps/deno.land/std@0.196.0/assert/assert.js +12 -0
  67. package/script/deps/deno.land/std@0.196.0/assert/assert_almost_equals.d.ts +18 -0
  68. package/script/deps/deno.land/std@0.196.0/assert/assert_almost_equals.js +36 -0
  69. package/script/deps/deno.land/std@0.196.0/assert/assert_array_includes.d.ts +14 -0
  70. package/script/deps/deno.land/std@0.196.0/assert/assert_array_includes.js +42 -0
  71. package/script/deps/deno.land/std@0.196.0/assert/assert_equals.d.ts +17 -0
  72. package/script/deps/deno.land/std@0.196.0/assert/assert_equals.js +49 -0
  73. package/script/deps/deno.land/std@0.196.0/assert/assert_exists.d.ts +5 -0
  74. package/script/deps/deno.land/std@0.196.0/assert/assert_exists.js +18 -0
  75. package/script/deps/deno.land/std@0.196.0/assert/assert_false.d.ts +4 -0
  76. package/script/deps/deno.land/std@0.196.0/assert/assert_false.js +11 -0
  77. package/script/deps/deno.land/std@0.196.0/assert/assert_instance_of.d.ts +8 -0
  78. package/script/deps/deno.land/std@0.196.0/assert/assert_instance_of.js +42 -0
  79. package/script/deps/deno.land/std@0.196.0/assert/assert_is_error.d.ts +7 -0
  80. package/script/deps/deno.land/std@0.196.0/assert/assert_is_error.js +30 -0
  81. package/script/deps/deno.land/std@0.196.0/assert/assert_match.d.ts +5 -0
  82. package/script/deps/deno.land/std@0.196.0/assert/assert_match.js +17 -0
  83. package/script/deps/deno.land/std@0.196.0/assert/assert_not_equals.d.ts +14 -0
  84. package/script/deps/deno.land/std@0.196.0/assert/assert_not_equals.js +41 -0
  85. package/script/deps/deno.land/std@0.196.0/assert/assert_not_instance_of.d.ts +5 -0
  86. package/script/deps/deno.land/std@0.196.0/assert/assert_not_instance_of.js +18 -0
  87. package/script/deps/deno.land/std@0.196.0/assert/assert_not_match.d.ts +5 -0
  88. package/script/deps/deno.land/std@0.196.0/assert/assert_not_match.js +18 -0
  89. package/script/deps/deno.land/std@0.196.0/assert/assert_not_strict_equals.d.ts +11 -0
  90. package/script/deps/deno.land/std@0.196.0/assert/assert_not_strict_equals.js +24 -0
  91. package/script/deps/deno.land/std@0.196.0/assert/assert_object_match.d.ts +5 -0
  92. package/script/deps/deno.land/std@0.196.0/assert/assert_object_match.js +82 -0
  93. package/script/deps/deno.land/std@0.196.0/assert/assert_rejects.d.ts +64 -0
  94. package/script/deps/deno.land/std@0.196.0/assert/assert_rejects.js +54 -0
  95. package/script/deps/deno.land/std@0.196.0/assert/assert_strict_equals.d.ts +23 -0
  96. package/script/deps/deno.land/std@0.196.0/assert/assert_strict_equals.js +64 -0
  97. package/script/deps/deno.land/std@0.196.0/assert/assert_string_includes.d.ts +5 -0
  98. package/script/deps/deno.land/std@0.196.0/assert/assert_string_includes.js +17 -0
  99. package/script/deps/deno.land/std@0.196.0/assert/assert_throws.d.ts +54 -0
  100. package/script/deps/deno.land/std@0.196.0/assert/assert_throws.js +48 -0
  101. package/script/deps/deno.land/std@0.196.0/assert/assertion_error.d.ts +4 -0
  102. package/script/deps/deno.land/std@0.196.0/assert/assertion_error.js +16 -0
  103. package/script/deps/deno.land/std@0.196.0/assert/equal.d.ts +6 -0
  104. package/script/deps/deno.land/std@0.196.0/assert/equal.js +106 -0
  105. package/script/deps/deno.land/std@0.196.0/assert/fail.d.ts +4 -0
  106. package/script/deps/deno.land/std@0.196.0/assert/fail.js +13 -0
  107. package/script/deps/deno.land/std@0.196.0/assert/mod.d.ts +32 -0
  108. package/script/deps/deno.land/std@0.196.0/assert/mod.js +49 -0
  109. package/script/deps/deno.land/std@0.196.0/assert/unimplemented.d.ts +2 -0
  110. package/script/deps/deno.land/std@0.196.0/assert/unimplemented.js +11 -0
  111. package/script/deps/deno.land/std@0.196.0/assert/unreachable.d.ts +2 -0
  112. package/script/deps/deno.land/std@0.196.0/assert/unreachable.js +10 -0
  113. package/script/deps/deno.land/{std@0.190.0 → std@0.196.0}/fmt/colors.js +2 -2
  114. package/{esm/deps/deno.land/std@0.190.0 → script/deps/deno.land/std@0.196.0}/testing/asserts.d.ts +204 -159
  115. package/script/deps/deno.land/std@0.196.0/testing/asserts.js +333 -0
  116. package/script/deps.d.ts +2 -2
  117. package/script/deps.js +2 -2
  118. package/script/storage/0_storage.d.ts +1 -1
  119. package/script/storage/0_storage.js +7 -2
  120. package/esm/deps/deno.land/std@0.190.0/testing/asserts.js +0 -633
  121. package/script/deps/deno.land/std@0.190.0/testing/asserts.js +0 -659
  122. /package/esm/deps/deno.land/{std@0.190.0/testing/_diff.d.ts → std@0.196.0/_util/diff.d.ts} +0 -0
  123. /package/esm/deps/deno.land/{std@0.190.0/testing/_diff.js → std@0.196.0/_util/diff.js} +0 -0
  124. /package/esm/deps/deno.land/{std@0.190.0/testing → std@0.196.0/assert}/_format.d.ts +0 -0
  125. /package/esm/deps/deno.land/{std@0.190.0/testing → std@0.196.0/assert}/_format.js +0 -0
  126. /package/esm/deps/deno.land/{std@0.190.0 → std@0.196.0}/encoding/base64.d.ts +0 -0
  127. /package/esm/deps/deno.land/{std@0.190.0 → std@0.196.0}/encoding/base64.js +0 -0
  128. /package/esm/deps/deno.land/{std@0.190.0 → std@0.196.0}/fmt/colors.d.ts +0 -0
  129. /package/script/deps/deno.land/{std@0.190.0/testing/_diff.d.ts → std@0.196.0/_util/diff.d.ts} +0 -0
  130. /package/script/deps/deno.land/{std@0.190.0/testing/_diff.js → std@0.196.0/_util/diff.js} +0 -0
  131. /package/script/deps/deno.land/{std@0.190.0/testing → std@0.196.0/assert}/_format.d.ts +0 -0
  132. /package/script/deps/deno.land/{std@0.190.0/testing → std@0.196.0/assert}/_format.js +0 -0
  133. /package/script/deps/deno.land/{std@0.190.0 → std@0.196.0}/encoding/base64.d.ts +0 -0
  134. /package/script/deps/deno.land/{std@0.190.0 → std@0.196.0}/encoding/base64.js +0 -0
  135. /package/script/deps/deno.land/{std@0.190.0 → std@0.196.0}/fmt/colors.d.ts +0 -0
@@ -1,633 +0,0 @@
1
- // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
- /** A library of assertion functions.
3
- * If the assertion is false an `AssertionError` will be thrown which will
4
- * result in pretty-printed diff of failing assertion.
5
- *
6
- * This module is browser compatible, but do not rely on good formatting of
7
- * values for AssertionError messages in browsers.
8
- *
9
- * @module
10
- */
11
- import { red, stripColor } from "../fmt/colors.js";
12
- import { buildMessage, diff, diffstr } from "./_diff.js";
13
- import { format } from "./_format.js";
14
- const CAN_NOT_DISPLAY = "[Cannot display]";
15
- export class AssertionError extends Error {
16
- constructor(message) {
17
- super(message);
18
- Object.defineProperty(this, "name", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: "AssertionError"
23
- });
24
- }
25
- }
26
- function isKeyedCollection(x) {
27
- return [Symbol.iterator, "size"].every((k) => k in x);
28
- }
29
- /**
30
- * Deep equality comparison used in assertions
31
- * @param c actual value
32
- * @param d expected value
33
- */
34
- export function equal(c, d) {
35
- const seen = new Map();
36
- return (function compare(a, b) {
37
- // Have to render RegExp & Date for string comparison
38
- // unless it's mistreated as object
39
- if (a &&
40
- b &&
41
- ((a instanceof RegExp && b instanceof RegExp) ||
42
- (a instanceof URL && b instanceof URL))) {
43
- return String(a) === String(b);
44
- }
45
- if (a instanceof Date && b instanceof Date) {
46
- const aTime = a.getTime();
47
- const bTime = b.getTime();
48
- // Check for NaN equality manually since NaN is not
49
- // equal to itself.
50
- if (Number.isNaN(aTime) && Number.isNaN(bTime)) {
51
- return true;
52
- }
53
- return aTime === bTime;
54
- }
55
- if (typeof a === "number" && typeof b === "number") {
56
- return Number.isNaN(a) && Number.isNaN(b) || a === b;
57
- }
58
- if (Object.is(a, b)) {
59
- return true;
60
- }
61
- if (a && typeof a === "object" && b && typeof b === "object") {
62
- if (a && b && !constructorsEqual(a, b)) {
63
- return false;
64
- }
65
- if (a instanceof WeakMap || b instanceof WeakMap) {
66
- if (!(a instanceof WeakMap && b instanceof WeakMap))
67
- return false;
68
- throw new TypeError("cannot compare WeakMap instances");
69
- }
70
- if (a instanceof WeakSet || b instanceof WeakSet) {
71
- if (!(a instanceof WeakSet && b instanceof WeakSet))
72
- return false;
73
- throw new TypeError("cannot compare WeakSet instances");
74
- }
75
- if (seen.get(a) === b) {
76
- return true;
77
- }
78
- if (Object.keys(a || {}).length !== Object.keys(b || {}).length) {
79
- return false;
80
- }
81
- seen.set(a, b);
82
- if (isKeyedCollection(a) && isKeyedCollection(b)) {
83
- if (a.size !== b.size) {
84
- return false;
85
- }
86
- let unmatchedEntries = a.size;
87
- for (const [aKey, aValue] of a.entries()) {
88
- for (const [bKey, bValue] of b.entries()) {
89
- /* Given that Map keys can be references, we need
90
- * to ensure that they are also deeply equal */
91
- if ((aKey === aValue && bKey === bValue && compare(aKey, bKey)) ||
92
- (compare(aKey, bKey) && compare(aValue, bValue))) {
93
- unmatchedEntries--;
94
- break;
95
- }
96
- }
97
- }
98
- return unmatchedEntries === 0;
99
- }
100
- const merged = { ...a, ...b };
101
- for (const key of [
102
- ...Object.getOwnPropertyNames(merged),
103
- ...Object.getOwnPropertySymbols(merged),
104
- ]) {
105
- if (!compare(a && a[key], b && b[key])) {
106
- return false;
107
- }
108
- if (((key in a) && (!(key in b))) || ((key in b) && (!(key in a)))) {
109
- return false;
110
- }
111
- }
112
- if (a instanceof WeakRef || b instanceof WeakRef) {
113
- if (!(a instanceof WeakRef && b instanceof WeakRef))
114
- return false;
115
- return compare(a.deref(), b.deref());
116
- }
117
- return true;
118
- }
119
- return false;
120
- })(c, d);
121
- }
122
- // deno-lint-ignore ban-types
123
- function constructorsEqual(a, b) {
124
- return a.constructor === b.constructor ||
125
- a.constructor === Object && !b.constructor ||
126
- !a.constructor && b.constructor === Object;
127
- }
128
- /** Make an assertion, error will be thrown if `expr` does not have truthy value. */
129
- export function assert(expr, msg = "") {
130
- if (!expr) {
131
- throw new AssertionError(msg);
132
- }
133
- }
134
- export function assertFalse(expr, msg = "") {
135
- if (expr) {
136
- throw new AssertionError(msg);
137
- }
138
- }
139
- /**
140
- * Make an assertion that `actual` and `expected` are equal, deeply. If not
141
- * deeply equal, then throw.
142
- *
143
- * Type parameter can be specified to ensure values under comparison have the same type.
144
- *
145
- * @example
146
- * ```ts
147
- * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
148
- *
149
- * Deno.test("example", function (): void {
150
- * assertEquals("world", "world");
151
- * assertEquals({ hello: "world" }, { hello: "world" });
152
- * });
153
- * ```
154
- */
155
- export function assertEquals(actual, expected, msg) {
156
- if (equal(actual, expected)) {
157
- return;
158
- }
159
- const msgSuffix = msg ? `: ${msg}` : ".";
160
- let message = `Values are not equal${msgSuffix}`;
161
- const actualString = format(actual);
162
- const expectedString = format(expected);
163
- try {
164
- const stringDiff = (typeof actual === "string") &&
165
- (typeof expected === "string");
166
- const diffResult = stringDiff
167
- ? diffstr(actual, expected)
168
- : diff(actualString.split("\n"), expectedString.split("\n"));
169
- const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n");
170
- message = `${message}\n${diffMsg}`;
171
- }
172
- catch {
173
- message = `${message}\n${red(CAN_NOT_DISPLAY)} + \n\n`;
174
- }
175
- throw new AssertionError(message);
176
- }
177
- /**
178
- * Make an assertion that `actual` and `expected` are not equal, deeply.
179
- * If not then throw.
180
- *
181
- * Type parameter can be specified to ensure values under comparison have the same type.
182
- *
183
- * @example
184
- * ```ts
185
- * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
186
- *
187
- * assertNotEquals<number>(1, 2)
188
- * ```
189
- */
190
- export function assertNotEquals(actual, expected, msg) {
191
- if (!equal(actual, expected)) {
192
- return;
193
- }
194
- let actualString;
195
- let expectedString;
196
- try {
197
- actualString = String(actual);
198
- }
199
- catch {
200
- actualString = "[Cannot display]";
201
- }
202
- try {
203
- expectedString = String(expected);
204
- }
205
- catch {
206
- expectedString = "[Cannot display]";
207
- }
208
- const msgSuffix = msg ? `: ${msg}` : ".";
209
- throw new AssertionError(`Expected actual: ${actualString} not to be: ${expectedString}${msgSuffix}`);
210
- }
211
- /**
212
- * Make an assertion that `actual` and `expected` are strictly equal. If
213
- * not then throw.
214
- *
215
- * @example
216
- * ```ts
217
- * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
218
- *
219
- * Deno.test("isStrictlyEqual", function (): void {
220
- * const a = {};
221
- * const b = a;
222
- * assertStrictEquals(a, b);
223
- * });
224
- *
225
- * // This test fails
226
- * Deno.test("isNotStrictlyEqual", function (): void {
227
- * const a = {};
228
- * const b = {};
229
- * assertStrictEquals(a, b);
230
- * });
231
- * ```
232
- */
233
- export function assertStrictEquals(actual, expected, msg) {
234
- if (Object.is(actual, expected)) {
235
- return;
236
- }
237
- const msgSuffix = msg ? `: ${msg}` : ".";
238
- let message;
239
- const actualString = format(actual);
240
- const expectedString = format(expected);
241
- if (actualString === expectedString) {
242
- const withOffset = actualString
243
- .split("\n")
244
- .map((l) => ` ${l}`)
245
- .join("\n");
246
- message =
247
- `Values have the same structure but are not reference-equal${msgSuffix}\n\n${red(withOffset)}\n`;
248
- }
249
- else {
250
- try {
251
- const stringDiff = (typeof actual === "string") &&
252
- (typeof expected === "string");
253
- const diffResult = stringDiff
254
- ? diffstr(actual, expected)
255
- : diff(actualString.split("\n"), expectedString.split("\n"));
256
- const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n");
257
- message = `Values are not strictly equal${msgSuffix}\n${diffMsg}`;
258
- }
259
- catch {
260
- message = `\n${red(CAN_NOT_DISPLAY)} + \n\n`;
261
- }
262
- }
263
- throw new AssertionError(message);
264
- }
265
- /**
266
- * Make an assertion that `actual` and `expected` are not strictly equal.
267
- * If the values are strictly equal then throw.
268
- *
269
- * ```ts
270
- * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
271
- *
272
- * assertNotStrictEquals(1, 1)
273
- * ```
274
- */
275
- export function assertNotStrictEquals(actual, expected, msg) {
276
- if (!Object.is(actual, expected)) {
277
- return;
278
- }
279
- const msgSuffix = msg ? `: ${msg}` : ".";
280
- throw new AssertionError(`Expected "actual" to be strictly unequal to: ${format(actual)}${msgSuffix}\n`);
281
- }
282
- /**
283
- * Make an assertion that `actual` and `expected` are almost equal numbers through
284
- * a given tolerance. It can be used to take into account IEEE-754 double-precision
285
- * floating-point representation limitations.
286
- * If the values are not almost equal then throw.
287
- *
288
- * @example
289
- * ```ts
290
- * import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
291
- *
292
- * assertAlmostEquals(0.1, 0.2);
293
- *
294
- * // Using a custom tolerance value
295
- * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16);
296
- * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17));
297
- * ```
298
- */
299
- export function assertAlmostEquals(actual, expected, tolerance = 1e-7, msg) {
300
- if (Object.is(actual, expected)) {
301
- return;
302
- }
303
- const delta = Math.abs(expected - actual);
304
- if (delta <= tolerance) {
305
- return;
306
- }
307
- const msgSuffix = msg ? `: ${msg}` : ".";
308
- const f = (n) => Number.isInteger(n) ? n : n.toExponential();
309
- throw new AssertionError(`Expected actual: "${f(actual)}" to be close to "${f(expected)}": \
310
- delta "${f(delta)}" is greater than "${f(tolerance)}"${msgSuffix}`);
311
- }
312
- /**
313
- * Make an assertion that `obj` is an instance of `type`.
314
- * If not then throw.
315
- */
316
- export function assertInstanceOf(actual, expectedType, msg = "") {
317
- if (actual instanceof expectedType)
318
- return;
319
- const msgSuffix = msg ? `: ${msg}` : ".";
320
- const expectedTypeStr = expectedType.name;
321
- let actualTypeStr = "";
322
- if (actual === null) {
323
- actualTypeStr = "null";
324
- }
325
- else if (actual === undefined) {
326
- actualTypeStr = "undefined";
327
- }
328
- else if (typeof actual === "object") {
329
- actualTypeStr = actual.constructor?.name ?? "Object";
330
- }
331
- else {
332
- actualTypeStr = typeof actual;
333
- }
334
- if (expectedTypeStr == actualTypeStr) {
335
- msg =
336
- `Expected object to be an instance of "${expectedTypeStr}"${msgSuffix}`;
337
- }
338
- else if (actualTypeStr == "function") {
339
- msg =
340
- `Expected object to be an instance of "${expectedTypeStr}" but was not an instanced object${msgSuffix}`;
341
- }
342
- else {
343
- msg =
344
- `Expected object to be an instance of "${expectedTypeStr}" but was "${actualTypeStr}"${msgSuffix}`;
345
- }
346
- throw new AssertionError(msg);
347
- }
348
- /**
349
- * Make an assertion that `obj` is not an instance of `type`.
350
- * If so, then throw.
351
- */
352
- export function assertNotInstanceOf(actual,
353
- // deno-lint-ignore no-explicit-any
354
- unexpectedType, msg) {
355
- const msgSuffix = msg ? `: ${msg}` : ".";
356
- msg =
357
- `Expected object to not be an instance of "${typeof unexpectedType}"${msgSuffix}`;
358
- assertFalse(actual instanceof unexpectedType, msg);
359
- }
360
- /**
361
- * Make an assertion that actual is not null or undefined.
362
- * If not then throw.
363
- */
364
- export function assertExists(actual, msg) {
365
- if (actual === undefined || actual === null) {
366
- const msgSuffix = msg ? `: ${msg}` : ".";
367
- msg =
368
- `Expected actual: "${actual}" to not be null or undefined${msgSuffix}`;
369
- throw new AssertionError(msg);
370
- }
371
- }
372
- /**
373
- * Make an assertion that actual includes expected. If not
374
- * then throw.
375
- */
376
- export function assertStringIncludes(actual, expected, msg) {
377
- if (!actual.includes(expected)) {
378
- const msgSuffix = msg ? `: ${msg}` : ".";
379
- msg = `Expected actual: "${actual}" to contain: "${expected}"${msgSuffix}`;
380
- throw new AssertionError(msg);
381
- }
382
- }
383
- /**
384
- * Make an assertion that `actual` includes the `expected` values.
385
- * If not then an error will be thrown.
386
- *
387
- * Type parameter can be specified to ensure values under comparison have the same type.
388
- *
389
- * @example
390
- * ```ts
391
- * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
392
- *
393
- * assertArrayIncludes<number>([1, 2], [2])
394
- * ```
395
- */
396
- export function assertArrayIncludes(actual, expected, msg) {
397
- const missing = [];
398
- for (let i = 0; i < expected.length; i++) {
399
- let found = false;
400
- for (let j = 0; j < actual.length; j++) {
401
- if (equal(expected[i], actual[j])) {
402
- found = true;
403
- break;
404
- }
405
- }
406
- if (!found) {
407
- missing.push(expected[i]);
408
- }
409
- }
410
- if (missing.length === 0) {
411
- return;
412
- }
413
- const msgSuffix = msg ? `: ${msg}` : ".";
414
- msg = `Expected actual: "${format(actual)}" to include: "${format(expected)}"${msgSuffix}\nmissing: ${format(missing)}`;
415
- throw new AssertionError(msg);
416
- }
417
- /**
418
- * Make an assertion that `actual` match RegExp `expected`. If not
419
- * then throw.
420
- */
421
- export function assertMatch(actual, expected, msg) {
422
- if (!expected.test(actual)) {
423
- const msgSuffix = msg ? `: ${msg}` : ".";
424
- msg = `Expected actual: "${actual}" to match: "${expected}"${msgSuffix}`;
425
- throw new AssertionError(msg);
426
- }
427
- }
428
- /**
429
- * Make an assertion that `actual` not match RegExp `expected`. If match
430
- * then throw.
431
- */
432
- export function assertNotMatch(actual, expected, msg) {
433
- if (expected.test(actual)) {
434
- const msgSuffix = msg ? `: ${msg}` : ".";
435
- msg =
436
- `Expected actual: "${actual}" to not match: "${expected}"${msgSuffix}`;
437
- throw new AssertionError(msg);
438
- }
439
- }
440
- /**
441
- * Make an assertion that `actual` object is a subset of `expected` object, deeply.
442
- * If not, then throw.
443
- */
444
- export function assertObjectMatch(
445
- // deno-lint-ignore no-explicit-any
446
- actual, expected, msg) {
447
- function filter(a, b) {
448
- const seen = new WeakMap();
449
- return fn(a, b);
450
- function fn(a, b) {
451
- // Prevent infinite loop with circular references with same filter
452
- if ((seen.has(a)) && (seen.get(a) === b)) {
453
- return a;
454
- }
455
- seen.set(a, b);
456
- // Filter keys and symbols which are present in both actual and expected
457
- const filtered = {};
458
- const entries = [
459
- ...Object.getOwnPropertyNames(a),
460
- ...Object.getOwnPropertySymbols(a),
461
- ]
462
- .filter((key) => key in b)
463
- .map((key) => [key, a[key]]);
464
- for (const [key, value] of entries) {
465
- // On array references, build a filtered array and filter nested objects inside
466
- if (Array.isArray(value)) {
467
- const subset = b[key];
468
- if (Array.isArray(subset)) {
469
- filtered[key] = fn({ ...value }, { ...subset });
470
- continue;
471
- }
472
- } // On regexp references, keep value as it to avoid loosing pattern and flags
473
- else if (value instanceof RegExp) {
474
- filtered[key] = value;
475
- continue;
476
- } // On nested objects references, build a filtered object recursively
477
- else if (typeof value === "object") {
478
- const subset = b[key];
479
- if ((typeof subset === "object") && (subset)) {
480
- // When both operands are maps, build a filtered map with common keys and filter nested objects inside
481
- if ((value instanceof Map) && (subset instanceof Map)) {
482
- filtered[key] = new Map([...value].filter(([k]) => subset.has(k)).map(([k, v]) => [k, typeof v === "object" ? fn(v, subset.get(k)) : v]));
483
- continue;
484
- }
485
- // When both operands are set, build a filtered set with common values
486
- if ((value instanceof Set) && (subset instanceof Set)) {
487
- filtered[key] = new Set([...value].filter((v) => subset.has(v)));
488
- continue;
489
- }
490
- filtered[key] = fn(value, subset);
491
- continue;
492
- }
493
- }
494
- filtered[key] = value;
495
- }
496
- return filtered;
497
- }
498
- }
499
- return assertEquals(
500
- // get the intersection of "actual" and "expected"
501
- // side effect: all the instances' constructor field is "Object" now.
502
- filter(actual, expected),
503
- // set (nested) instances' constructor field to be "Object" without changing expected value.
504
- // see https://github.com/denoland/deno_std/pull/1419
505
- filter(expected, expected), msg);
506
- }
507
- /**
508
- * Forcefully throws a failed assertion
509
- */
510
- export function fail(msg) {
511
- const msgSuffix = msg ? `: ${msg}` : ".";
512
- assert(false, `Failed assertion${msgSuffix}`);
513
- }
514
- /**
515
- * Make an assertion that `error` is an `Error`.
516
- * If not then an error will be thrown.
517
- * An error class and a string that should be included in the
518
- * error message can also be asserted.
519
- */
520
- export function assertIsError(error,
521
- // deno-lint-ignore no-explicit-any
522
- ErrorClass, msgIncludes, msg) {
523
- const msgSuffix = msg ? `: ${msg}` : ".";
524
- if (error instanceof Error === false) {
525
- throw new AssertionError(`Expected "error" to be an Error object${msgSuffix}}`);
526
- }
527
- if (ErrorClass && !(error instanceof ErrorClass)) {
528
- msg = `Expected error to be instance of "${ErrorClass.name}", but was "${typeof error === "object" ? error?.constructor?.name : "[not an object]"}"${msgSuffix}`;
529
- throw new AssertionError(msg);
530
- }
531
- if (msgIncludes && (!(error instanceof Error) ||
532
- !stripColor(error.message).includes(stripColor(msgIncludes)))) {
533
- msg = `Expected error message to include "${msgIncludes}", but got "${error instanceof Error ? error.message : "[not an Error]"}"${msgSuffix}`;
534
- throw new AssertionError(msg);
535
- }
536
- }
537
- export function assertThrows(fn, errorClassOrMsg, msgIncludesOrMsg, msg) {
538
- // deno-lint-ignore no-explicit-any
539
- let ErrorClass = undefined;
540
- let msgIncludes = undefined;
541
- let err;
542
- if (typeof errorClassOrMsg !== "string") {
543
- if (errorClassOrMsg === undefined ||
544
- errorClassOrMsg.prototype instanceof Error ||
545
- errorClassOrMsg.prototype === Error.prototype) {
546
- // deno-lint-ignore no-explicit-any
547
- ErrorClass = errorClassOrMsg;
548
- msgIncludes = msgIncludesOrMsg;
549
- }
550
- else {
551
- msg = msgIncludesOrMsg;
552
- }
553
- }
554
- else {
555
- msg = errorClassOrMsg;
556
- }
557
- let doesThrow = false;
558
- const msgSuffix = msg ? `: ${msg}` : ".";
559
- try {
560
- fn();
561
- }
562
- catch (error) {
563
- if (ErrorClass) {
564
- if (error instanceof Error === false) {
565
- throw new AssertionError(`A non-Error object was thrown${msgSuffix}`);
566
- }
567
- assertIsError(error, ErrorClass, msgIncludes, msg);
568
- }
569
- err = error;
570
- doesThrow = true;
571
- }
572
- if (!doesThrow) {
573
- msg = `Expected function to throw${msgSuffix}`;
574
- throw new AssertionError(msg);
575
- }
576
- return err;
577
- }
578
- export async function assertRejects(fn, errorClassOrMsg, msgIncludesOrMsg, msg) {
579
- // deno-lint-ignore no-explicit-any
580
- let ErrorClass = undefined;
581
- let msgIncludes = undefined;
582
- let err;
583
- if (typeof errorClassOrMsg !== "string") {
584
- if (errorClassOrMsg === undefined ||
585
- errorClassOrMsg.prototype instanceof Error ||
586
- errorClassOrMsg.prototype === Error.prototype) {
587
- // deno-lint-ignore no-explicit-any
588
- ErrorClass = errorClassOrMsg;
589
- msgIncludes = msgIncludesOrMsg;
590
- }
591
- }
592
- else {
593
- msg = errorClassOrMsg;
594
- }
595
- let doesThrow = false;
596
- let isPromiseReturned = false;
597
- const msgSuffix = msg ? `: ${msg}` : ".";
598
- try {
599
- const possiblePromise = fn();
600
- if (possiblePromise &&
601
- typeof possiblePromise === "object" &&
602
- typeof possiblePromise.then === "function") {
603
- isPromiseReturned = true;
604
- await possiblePromise;
605
- }
606
- }
607
- catch (error) {
608
- if (!isPromiseReturned) {
609
- throw new AssertionError(`Function throws when expected to reject${msgSuffix}`);
610
- }
611
- if (ErrorClass) {
612
- if (error instanceof Error === false) {
613
- throw new AssertionError(`A non-Error object was rejected${msgSuffix}`);
614
- }
615
- assertIsError(error, ErrorClass, msgIncludes, msg);
616
- }
617
- err = error;
618
- doesThrow = true;
619
- }
620
- if (!doesThrow) {
621
- throw new AssertionError(`Expected function to reject${msgSuffix}`);
622
- }
623
- return err;
624
- }
625
- /** Use this to stub out methods that will throw when invoked. */
626
- export function unimplemented(msg) {
627
- const msgSuffix = msg ? `: ${msg}` : ".";
628
- throw new AssertionError(`Unimplemented${msgSuffix}`);
629
- }
630
- /** Use this to assert unreachable code. */
631
- export function unreachable() {
632
- throw new AssertionError("unreachable");
633
- }