@mtkruto/node 0.0.971 → 0.0.972

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