@plugjs/expect5 0.4.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.
Files changed (90) hide show
  1. package/README.md +7 -0
  2. package/dist/cli.d.mts +2 -0
  3. package/dist/cli.mjs +96 -0
  4. package/dist/cli.mjs.map +6 -0
  5. package/dist/execution/executable.cjs +299 -0
  6. package/dist/execution/executable.cjs.map +6 -0
  7. package/dist/execution/executable.d.ts +87 -0
  8. package/dist/execution/executable.mjs +260 -0
  9. package/dist/execution/executable.mjs.map +6 -0
  10. package/dist/execution/executor.cjs +125 -0
  11. package/dist/execution/executor.cjs.map +6 -0
  12. package/dist/execution/executor.d.ts +35 -0
  13. package/dist/execution/executor.mjs +90 -0
  14. package/dist/execution/executor.mjs.map +6 -0
  15. package/dist/execution/setup.cjs +127 -0
  16. package/dist/execution/setup.cjs.map +6 -0
  17. package/dist/execution/setup.d.ts +31 -0
  18. package/dist/execution/setup.mjs +87 -0
  19. package/dist/execution/setup.mjs.map +6 -0
  20. package/dist/expectation/basic.cjs +216 -0
  21. package/dist/expectation/basic.cjs.map +6 -0
  22. package/dist/expectation/basic.d.ts +47 -0
  23. package/dist/expectation/basic.mjs +177 -0
  24. package/dist/expectation/basic.mjs.map +6 -0
  25. package/dist/expectation/diff.cjs +253 -0
  26. package/dist/expectation/diff.cjs.map +6 -0
  27. package/dist/expectation/diff.d.ts +27 -0
  28. package/dist/expectation/diff.mjs +228 -0
  29. package/dist/expectation/diff.mjs.map +6 -0
  30. package/dist/expectation/expect.cjs +211 -0
  31. package/dist/expectation/expect.cjs.map +6 -0
  32. package/dist/expectation/expect.d.ts +140 -0
  33. package/dist/expectation/expect.mjs +219 -0
  34. package/dist/expectation/expect.mjs.map +6 -0
  35. package/dist/expectation/include.cjs +187 -0
  36. package/dist/expectation/include.cjs.map +6 -0
  37. package/dist/expectation/include.d.ts +10 -0
  38. package/dist/expectation/include.mjs +158 -0
  39. package/dist/expectation/include.mjs.map +6 -0
  40. package/dist/expectation/print.cjs +281 -0
  41. package/dist/expectation/print.cjs.map +6 -0
  42. package/dist/expectation/print.d.ts +4 -0
  43. package/dist/expectation/print.mjs +256 -0
  44. package/dist/expectation/print.mjs.map +6 -0
  45. package/dist/expectation/throwing.cjs +58 -0
  46. package/dist/expectation/throwing.cjs.map +6 -0
  47. package/dist/expectation/throwing.d.ts +8 -0
  48. package/dist/expectation/throwing.mjs +32 -0
  49. package/dist/expectation/throwing.mjs.map +6 -0
  50. package/dist/expectation/types.cjs +212 -0
  51. package/dist/expectation/types.cjs.map +6 -0
  52. package/dist/expectation/types.d.ts +57 -0
  53. package/dist/expectation/types.mjs +178 -0
  54. package/dist/expectation/types.mjs.map +6 -0
  55. package/dist/expectation/void.cjs +111 -0
  56. package/dist/expectation/void.cjs.map +6 -0
  57. package/dist/expectation/void.d.ts +39 -0
  58. package/dist/expectation/void.mjs +77 -0
  59. package/dist/expectation/void.mjs.map +6 -0
  60. package/dist/globals.cjs +2 -0
  61. package/dist/globals.cjs.map +6 -0
  62. package/dist/globals.d.ts +23 -0
  63. package/dist/globals.mjs +1 -0
  64. package/dist/globals.mjs.map +6 -0
  65. package/dist/index.cjs +66 -0
  66. package/dist/index.cjs.map +6 -0
  67. package/dist/index.d.ts +29 -0
  68. package/dist/index.mjs +41 -0
  69. package/dist/index.mjs.map +6 -0
  70. package/dist/test.cjs +229 -0
  71. package/dist/test.cjs.map +6 -0
  72. package/dist/test.d.ts +9 -0
  73. package/dist/test.mjs +194 -0
  74. package/dist/test.mjs.map +6 -0
  75. package/package.json +57 -0
  76. package/src/cli.mts +122 -0
  77. package/src/execution/executable.ts +364 -0
  78. package/src/execution/executor.ts +146 -0
  79. package/src/execution/setup.ts +108 -0
  80. package/src/expectation/basic.ts +209 -0
  81. package/src/expectation/diff.ts +445 -0
  82. package/src/expectation/expect.ts +401 -0
  83. package/src/expectation/include.ts +184 -0
  84. package/src/expectation/print.ts +386 -0
  85. package/src/expectation/throwing.ts +45 -0
  86. package/src/expectation/types.ts +263 -0
  87. package/src/expectation/void.ts +80 -0
  88. package/src/globals.ts +30 -0
  89. package/src/index.ts +54 -0
  90. package/src/test.ts +239 -0
@@ -0,0 +1,256 @@
1
+ // expectation/print.ts
2
+ import { $grn, $gry, $red, $und, $wht, $ylw } from "@plugjs/plug/logging";
3
+ import { textDiff } from "@plugjs/plug/utils";
4
+ import { stringifyValue } from "./types.mjs";
5
+ var _opnPar = $gry("(");
6
+ var _clsPar = $gry(")");
7
+ var _opnCrl = $gry("{");
8
+ var _clsCrl = $gry("}");
9
+ var _curls = $gry("{}");
10
+ var _opnSqr = $gry("[");
11
+ var _clsSqr = $gry("]");
12
+ var _squares = $gry("[]");
13
+ var _slash = $gry("/");
14
+ var _tilde = $gry("~");
15
+ var _hellip = $gry("\u2026");
16
+ var _error = `${_opnPar}${$gry($und("error"))}${_clsPar}`;
17
+ var _string = `${_opnPar}${$gry($und("string"))}${_clsPar}`;
18
+ var _extraProps = $gry("\u2026 extra props \u2026");
19
+ var _diffHeader = `${$wht("Differences")} ${_opnPar}${$red("actual")}${_slash}${$grn("expected")}${_slash}${$ylw("errors")}${_clsPar}:`;
20
+ function printBaseDiff(log, diff, prop, mapping, comma) {
21
+ if ("props" in diff)
22
+ return printObjectDiff(log, diff, prop, mapping, comma);
23
+ if ("values" in diff)
24
+ return printObjectDiff(log, diff, prop, mapping, comma);
25
+ if ("mappings" in diff)
26
+ return printObjectDiff(log, diff, prop, mapping, comma);
27
+ if ("expected" in diff)
28
+ return printExpectedDiff(log, diff, prop, mapping, comma);
29
+ if ("missing" in diff)
30
+ return printMissingDiff(log, diff, prop, mapping, comma);
31
+ if ("extra" in diff)
32
+ return printExtraDiff(log, diff, prop, mapping, comma);
33
+ const { prefix, suffix } = diff.error ? (
34
+ // default style if error is the only property
35
+ fixups(prop, mapping, comma, diff.error)
36
+ ) : diff.diff ? (
37
+ // label as "differs" if no error was found
38
+ fixups(prop, mapping, comma, diff.error, $red, "differs")
39
+ ) : fixups(prop, mapping, comma, diff.error);
40
+ dump(log, diff.value, prefix, suffix, diff.diff ? $red : $wht);
41
+ }
42
+ function printExpectedDiff(log, diff, prop, mapping, comma) {
43
+ if (typeof diff.value === "string" && typeof diff.expected === "string") {
44
+ const { prefix, suffix } = fixups(prop, mapping, false, diff.error);
45
+ log.warn(`${prefix}${_string}${suffix}`);
46
+ textDiff(diff.value, diff.expected).split("\n").forEach((line) => {
47
+ log.warn(` ${_hellip} ${line}`);
48
+ });
49
+ } else if (diff.value === null || typeof diff.value !== "object") {
50
+ const { prefix, suffix } = fixups(prop, mapping, comma, diff.error);
51
+ const joined = `${prefix}${$red(stringify(diff.value))} ${_tilde} `;
52
+ dump(log, diff.expected, joined, suffix, $grn);
53
+ } else if (diff.expected === null || typeof diff.expected !== "object") {
54
+ const { prefix, suffix } = fixups(prop, mapping, comma, diff.error);
55
+ const joined = ` ${_tilde} ${$grn(stringify(diff.expected))}${suffix}`;
56
+ dump(log, diff.value, prefix, joined, $red);
57
+ } else {
58
+ const { prefix, suffix: suffix1 } = fixups(prop, mapping, false, "");
59
+ const { suffix: suffix2 } = fixups(prop, mapping, comma, diff.error);
60
+ const lastLine = dumpAndContinue(log, diff.expected, prefix, suffix1, $red);
61
+ dump(log, diff.value, `${lastLine} ${_tilde} `, suffix2, $grn);
62
+ }
63
+ }
64
+ function printMissingDiff(log, diff, prop, mapping, comma) {
65
+ const { prefix, suffix } = fixups(prop, mapping, comma, diff.error, $red, "missing");
66
+ dump(log, diff.missing, prefix, suffix, $red);
67
+ }
68
+ function printExtraDiff(log, diff, prop, mapping, comma) {
69
+ const { prefix, suffix } = fixups(prop, mapping, comma, diff.error, $red, "extra");
70
+ dump(log, diff.extra, prefix, suffix, $red);
71
+ }
72
+ function printObjectDiff(log, diff, prop, mapping, comma) {
73
+ const { prefix, suffix } = fixups(prop, mapping, comma, diff.error);
74
+ const value = diff.value;
75
+ const ctor = Object.getPrototypeOf(value)?.constructor;
76
+ const string = ctor === Object || ctor === Array ? "" : stringifyValue(value);
77
+ let line = string ? `${prefix}${$wht(string)} ` : prefix;
78
+ let marked = false;
79
+ if (diff.values) {
80
+ if (diff.values.length === 0) {
81
+ line = `${line}${_squares}`;
82
+ } else {
83
+ log.warn(`${line}${_opnSqr}`);
84
+ log.enter();
85
+ try {
86
+ for (const subdiff of diff.values) {
87
+ printBaseDiff(log, subdiff, "", false, true);
88
+ }
89
+ } finally {
90
+ log.leave();
91
+ }
92
+ line = _clsSqr;
93
+ }
94
+ marked = true;
95
+ } else if (diff.mappings) {
96
+ if (Object.keys(diff.mappings).length === 0) {
97
+ line = `${line}${_curls}`;
98
+ } else {
99
+ log.warn(`${line}${_opnCrl}`);
100
+ log.enter();
101
+ try {
102
+ for (const [key, subdiff] of diff.mappings) {
103
+ printBaseDiff(log, subdiff, stringifyValue(key), true, true);
104
+ }
105
+ } finally {
106
+ log.leave();
107
+ }
108
+ line = _clsCrl;
109
+ }
110
+ marked = true;
111
+ }
112
+ if (diff.props) {
113
+ if (marked)
114
+ line = `${line} ${_extraProps} `;
115
+ if (Object.keys(diff.props).length === 0) {
116
+ line = `${line}${_curls}`;
117
+ } else {
118
+ log.warn(`${line}${_opnCrl}`);
119
+ log.enter();
120
+ try {
121
+ for (const [prop2, subdiff] of Object.entries(diff.props)) {
122
+ printBaseDiff(log, subdiff, stringifyValue(prop2), false, true);
123
+ }
124
+ } finally {
125
+ log.leave();
126
+ }
127
+ line = _clsCrl;
128
+ }
129
+ marked = true;
130
+ }
131
+ log.warn(`${line}${suffix}`);
132
+ }
133
+ function stringify(value) {
134
+ if (typeof value === "string")
135
+ return JSON.stringify(value);
136
+ return stringifyValue(value);
137
+ }
138
+ function fixups(prop, mapping, comma, error, color, label) {
139
+ if (error)
140
+ color = color || $ylw;
141
+ const lbl = label ? `${_opnPar}${$gry($und(label))}${_clsPar} ` : "";
142
+ const sep = mapping ? " => " : ": ";
143
+ const prefix = prop ? color ? `${$gry(lbl)}${color(prop)}${$gry(sep)}` : `${$gry(lbl)}${prop}${$gry(sep)}` : label ? `${$gry(lbl)}` : "";
144
+ error = error ? ` ${_error} ${$ylw(error)}` : "";
145
+ const suffix = `${comma ? $gry(",") : ""}${error}`;
146
+ return { prefix, suffix };
147
+ }
148
+ function dump(log, value, prefix, suffix, color, stack = []) {
149
+ log.warn(dumpAndContinue(log, value, prefix, suffix, color, stack));
150
+ }
151
+ function dumpAndContinue(log, value, prefix, suffix, color, stack = []) {
152
+ if (value === null || typeof value !== "object") {
153
+ return `${prefix}${color(stringify(value))}${suffix}`;
154
+ }
155
+ const circular = stack.indexOf(value);
156
+ if (circular >= 0) {
157
+ return `${prefix}${$gry($und(`<circular ${circular}>`))}${suffix}`;
158
+ }
159
+ const ctor = Object.getPrototypeOf(value)?.constructor;
160
+ const string = ctor === Object || ctor === Array ? "" : stringifyValue(value);
161
+ const keys = new Set(Object.keys(value));
162
+ let line = string ? `${prefix}${$wht(string)} ` : prefix;
163
+ let marked = false;
164
+ if (Array.isArray(value)) {
165
+ if (value.length === 0) {
166
+ line = `${line}${_squares}`;
167
+ } else {
168
+ log.warn(`${line}${_opnSqr}`);
169
+ log.enter();
170
+ try {
171
+ for (let i = 0; i < value.length; i++) {
172
+ const { prefix: prefix2, suffix: suffix2 } = fixups("", false, true, void 0, color);
173
+ dump(log, value[i], prefix2, suffix2, color, [...stack, value]);
174
+ keys.delete(String(i));
175
+ }
176
+ } finally {
177
+ log.leave();
178
+ }
179
+ line = _clsSqr;
180
+ }
181
+ marked = true;
182
+ } else if (value instanceof Set) {
183
+ if (value.size === 0) {
184
+ line = `${line}${_squares}`;
185
+ } else {
186
+ log.warn(`${line}${_opnSqr}`);
187
+ log.enter();
188
+ try {
189
+ const { prefix: prefix2, suffix: suffix2 } = fixups("", false, true, void 0, color);
190
+ value.forEach((v) => dump(log, v, prefix2, suffix2, color, [...stack, value]));
191
+ } finally {
192
+ log.leave();
193
+ }
194
+ line = _clsSqr;
195
+ }
196
+ marked = true;
197
+ } else if (value instanceof Map) {
198
+ if (value.size === 0) {
199
+ line = `${line}${_curls}`;
200
+ } else {
201
+ log.warn(`${line}${_opnCrl}`);
202
+ log.enter();
203
+ try {
204
+ for (const [key, subvalue] of value) {
205
+ const { prefix: prefix2, suffix: suffix2 } = fixups(stringifyValue(key), true, true, void 0, color);
206
+ dump(log, subvalue, prefix2, suffix2, color, [...stack, value]);
207
+ }
208
+ } finally {
209
+ log.leave();
210
+ }
211
+ line = _clsCrl;
212
+ }
213
+ marked = true;
214
+ }
215
+ if (value instanceof String) {
216
+ const length = value.valueOf().length;
217
+ for (let i = 0; i < length; i++)
218
+ keys.delete(String(i));
219
+ }
220
+ if (keys.size) {
221
+ if (marked)
222
+ line = `${line} ${_extraProps} `;
223
+ log.warn(`${line}${_opnCrl}`);
224
+ log.enter();
225
+ try {
226
+ for (const key of keys) {
227
+ const { prefix: prefix2, suffix: suffix2 } = fixups(stringifyValue(key), false, true, void 0, color);
228
+ dump(log, value[key], prefix2, suffix2, color, [...stack, value]);
229
+ }
230
+ } finally {
231
+ log.leave();
232
+ }
233
+ line = _clsCrl;
234
+ marked = true;
235
+ }
236
+ if (marked) {
237
+ return `${line}${suffix}`;
238
+ } else {
239
+ return `${line}${_curls}${suffix}`;
240
+ }
241
+ }
242
+ function printDiff(log, diff, header = true) {
243
+ if (!header)
244
+ return printBaseDiff(log, diff, "", false, false);
245
+ log.warn(_diffHeader);
246
+ log.enter();
247
+ try {
248
+ printBaseDiff(log, diff, "", false, false);
249
+ } finally {
250
+ log.leave();
251
+ }
252
+ }
253
+ export {
254
+ printDiff
255
+ };
256
+ //# sourceMappingURL=print.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/expectation/print.ts"],
4
+ "mappings": ";AAAA,SAAS,MAAM,MAAM,MAAM,MAAM,MAAM,YAAY;AACnD,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;AAS/B,IAAM,UAAU,KAAK,GAAG;AACxB,IAAM,UAAU,KAAK,GA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AC5B,QAAI,MAAM;AACV,QAAI;AACF,iBAAW,OAAO,MAAM;AACtB,cAAM,EAAE,QAAAD,SAAQ,QAAAC,QAAO,IAAI,OAAO,eAAe,GAAG,GAAG,OAAO,MAAM,QAAW,KAAK;AACpF,aAAK,KAAK,MAAM,GAAG,GAAGD,SAAQC,SAAQ,OAAO,CAAE,GAAG,OAAO,KAAM,CAAC;AAAA,MAClE;AAAA,IACF,UAAE;AACA,UAAI,MAAM;AAAA,IACZ;AACA,WAAO;AACP,aAAS;AAAA,EACX;AAEA,MAAI,QAAQ;AACV,WAAO,GAAG,OAAO;AAAA,EACnB,OAAO;AACL,WAAO,GAAG,OAAO,SAAS;AAAA,EAC5B;AACF;AAOO,SAAS,UAAU,KAAa,MAAY,SAAS,MAAY;AACtE,MAAI,CAAE;AAAQ,WAAO,cAAc,KAAK,MAAM,IAAI,OAAO,KAAK;AAE9D,MAAI,KAAK,WAAW;AACpB,MAAI,MAAM;AACV,MAAI;AACF,kBAAc,KAAK,MAAM,IAAI,OAAO,KAAK;AAAA,EAC3C,UAAE;AACA,QAAI,MAAM;AAAA,EACZ;AACF;",
5
+ "names": ["prop", "prefix", "suffix"]
6
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // expectation/throwing.ts
21
+ var throwing_exports = {};
22
+ __export(throwing_exports, {
23
+ ToThrow: () => ToThrow,
24
+ ToThrowError: () => ToThrowError
25
+ });
26
+ module.exports = __toCommonJS(throwing_exports);
27
+ var import_types = require("./types.cjs");
28
+ var ToThrow = class {
29
+ expect(context, negative, assert) {
30
+ (0, import_types.assertType)(context, "function");
31
+ let thrown;
32
+ let error;
33
+ try {
34
+ context.value();
35
+ thrown = false;
36
+ error = void 0;
37
+ } catch (caught) {
38
+ thrown = true;
39
+ error = caught;
40
+ }
41
+ if (thrown === negative) {
42
+ throw new import_types.ExpectationError(context, negative, "to throw");
43
+ } else if (thrown && assert) {
44
+ assert(context.forValue(error));
45
+ }
46
+ }
47
+ };
48
+ var ToThrowError = class {
49
+ expect(context, negative, ...args) {
50
+ context.negated(negative).toThrow((assert) => assert.toBeError(...args));
51
+ }
52
+ };
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ ToThrow,
56
+ ToThrowError
57
+ });
58
+ //# sourceMappingURL=throwing.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/expectation/throwing.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6C;AAKtC,IAAM,UAAN,MAAqC;AAAA,EAC1C,OACI,SACA,UACA,QACI;AACN,iCAAW,SAAS,UAAU;AAE9B,QAAI;AACJ,QAAI;AACJ,QAAI;AACF,cAAQ,MAAM;AACd,eAAS;AACT,cAAQ;AAAA,IACV,SAAS,QAAP;AACA,eAAS;AACT,cAAQ;AAAA,IACV;AAEA,QAAI,WAAW,UAAU;AACvB,YAAM,IAAI,8BAAiB,SAAS,UAAU,UAAU;AAAA,IAC1D,WAAW,UAAU,QAAQ;AAC3B,aAAO,QAAQ,SAAS,KAAK,CAAC;AAAA,IAChC;AAAA,EACF;AACF;AAEO,IAAM,eAAN,MAA0C;AAAA,EAC/C,OACI,SACA,aACG,MAKC;AACN,YAAQ,QAAQ,QAAQ,EAAE,QAAQ,CAAC,WAAW,OAAO,UAAU,GAAG,IAAI,CAAC;AAAA,EACzE;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,8 @@
1
+ import type { Expectation, Expectations } from './expect';
2
+ import type { Constructor, StringMatcher } from './types';
3
+ export declare class ToThrow implements Expectation {
4
+ expect(context: Expectations, negative: boolean, assert?: (errorExpectations: Expectations) => void): void;
5
+ }
6
+ export declare class ToThrowError implements Expectation {
7
+ expect(context: Expectations, negative: boolean, ...args: [] | [message: StringMatcher] | [constructor: Constructor<Error>] | [constructor: Constructor<Error>, message: StringMatcher]): void;
8
+ }
@@ -0,0 +1,32 @@
1
+ // expectation/throwing.ts
2
+ import { ExpectationError, assertType } from "./types.mjs";
3
+ var ToThrow = class {
4
+ expect(context, negative, assert) {
5
+ assertType(context, "function");
6
+ let thrown;
7
+ let error;
8
+ try {
9
+ context.value();
10
+ thrown = false;
11
+ error = void 0;
12
+ } catch (caught) {
13
+ thrown = true;
14
+ error = caught;
15
+ }
16
+ if (thrown === negative) {
17
+ throw new ExpectationError(context, negative, "to throw");
18
+ } else if (thrown && assert) {
19
+ assert(context.forValue(error));
20
+ }
21
+ }
22
+ };
23
+ var ToThrowError = class {
24
+ expect(context, negative, ...args) {
25
+ context.negated(negative).toThrow((assert) => assert.toBeError(...args));
26
+ }
27
+ };
28
+ export {
29
+ ToThrow,
30
+ ToThrowError
31
+ };
32
+ //# sourceMappingURL=throwing.mjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/expectation/throwing.ts"],
4
+ "mappings": ";AAAA,SAAS,kBAAkB,kBAAkB;AAKtC,IAAM,UAAN,MAAqC;AAAA,EAC1C,OACI,SACA,UACA,QACI;AACN,eAAW,SAAS,UAAU;AAE9B,QAAI;AACJ,QAAI;AACJ,QAAI;AACF,cAAQ,MAAM;AACd,eAAS;AACT,cAAQ;AAAA,IACV,SAAS,QAAP;AACA,eAAS;AACT,cAAQ;AAAA,IACV;AAEA,QAAI,WAAW,UAAU;AACvB,YAAM,IAAI,iBAAiB,SAAS,UAAU,UAAU;AAAA,IAC1D,WAAW,UAAU,QAAQ;AAC3B,aAAO,QAAQ,SAAS,KAAK,CAAC;AAAA,IAChC;AAAA,EACF;AACF;AAEO,IAAM,eAAN,MAA0C;AAAA,EAC/C,OACI,SACA,aACG,MAKC;AACN,YAAQ,QAAQ,QAAQ,EAAE,QAAQ,CAAC,WAAW,OAAO,UAAU,GAAG,IAAI,CAAC;AAAA,EACzE;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // expectation/types.ts
21
+ var types_exports = {};
22
+ __export(types_exports, {
23
+ ExpectationError: () => ExpectationError,
24
+ assertType: () => assertType,
25
+ isMatcher: () => isMatcher,
26
+ isType: () => isType,
27
+ matcherMarker: () => matcherMarker,
28
+ prefixType: () => prefixType,
29
+ stringifyConstructor: () => stringifyConstructor,
30
+ stringifyObjectType: () => stringifyObjectType,
31
+ stringifyValue: () => stringifyValue,
32
+ typeOf: () => typeOf
33
+ });
34
+ module.exports = __toCommonJS(types_exports);
35
+ function typeOf(value) {
36
+ if (value === null)
37
+ return "null";
38
+ const type = typeof value;
39
+ switch (type) {
40
+ case "bigint":
41
+ case "boolean":
42
+ case "function":
43
+ case "number":
44
+ case "string":
45
+ case "symbol":
46
+ case "undefined":
47
+ return type;
48
+ }
49
+ if (Array.isArray(value))
50
+ return "array";
51
+ if (value instanceof Promise)
52
+ return "promise";
53
+ if (typeof value["then"] === "function")
54
+ return "promise";
55
+ if (value instanceof Buffer)
56
+ return "buffer";
57
+ if (value instanceof RegExp)
58
+ return "regexp";
59
+ if (value instanceof Map)
60
+ return "map";
61
+ if (value instanceof Set)
62
+ return "set";
63
+ return "object";
64
+ }
65
+ function isType(context, type) {
66
+ return typeOf(context.value) === type;
67
+ }
68
+ function assertType(context, type) {
69
+ const { value } = context;
70
+ if (typeOf(value) === type)
71
+ return;
72
+ throw new ExpectationError(context, false, `to be ${prefixType(type)}`);
73
+ }
74
+ function constructorName(value) {
75
+ return Object.getPrototypeOf(value)?.constructor?.name;
76
+ }
77
+ function formatBinaryData(value, buffer) {
78
+ const binary = buffer.length > 20 ? `${buffer.toString("hex", 0, 20)}\u2026, length=${value.length}` : buffer.toString("hex");
79
+ return binary ? `[${constructorName(value)}: ${binary}]` : `[${constructorName(value)}: empty]`;
80
+ }
81
+ function stringifyObjectType(value) {
82
+ const proto = Object.getPrototypeOf(value);
83
+ if (!proto)
84
+ return "[Object: null prototype]";
85
+ return stringifyConstructor(proto.constructor);
86
+ }
87
+ function stringifyConstructor(ctor) {
88
+ if (!ctor)
89
+ return "[Object: no constructor]";
90
+ if (!ctor.name)
91
+ return "[Object: anonymous]";
92
+ return `[${ctor.name}]`;
93
+ }
94
+ function stringifyValue(value) {
95
+ if (value === null)
96
+ return "<null>";
97
+ if (value === void 0)
98
+ return "<undefined>";
99
+ switch (typeof value) {
100
+ case "string":
101
+ if (value.length > 40)
102
+ value = `${value.substring(0, 40)}\u2026, length=${value.length}`;
103
+ return JSON.stringify(value);
104
+ case "number":
105
+ if (value === Number.POSITIVE_INFINITY)
106
+ return "+Infinity";
107
+ if (value === Number.NEGATIVE_INFINITY)
108
+ return "-Infinity";
109
+ return String(value);
110
+ case "boolean":
111
+ return String(value);
112
+ case "bigint":
113
+ return `${value}n`;
114
+ case "function":
115
+ return value.name ? `<function ${value.name}>` : "<function>";
116
+ case "symbol":
117
+ return value.description ? `<symbol ${value.description}>` : "<symbol>";
118
+ }
119
+ if (isMatcher(value))
120
+ return "<matcher>";
121
+ if (value instanceof RegExp)
122
+ return String(value);
123
+ if (value instanceof Date)
124
+ return `[${constructorName(value)}: ${value.toISOString()}]`;
125
+ if (value instanceof Boolean)
126
+ return `[${constructorName(value)}: ${value.valueOf()}]`;
127
+ if (value instanceof Number)
128
+ return `[${constructorName(value)}: ${stringifyValue(value.valueOf())}]`;
129
+ if (value instanceof String)
130
+ return `[${constructorName(value)}: ${stringifyValue(value.valueOf())}]`;
131
+ if (Array.isArray(value))
132
+ return `[${constructorName(value)} (${value.length})]`;
133
+ if (value instanceof Set)
134
+ return `[${constructorName(value)} (${value.size})]`;
135
+ if (value instanceof Map)
136
+ return `[${constructorName(value)} (${value.size})]`;
137
+ if (value instanceof Buffer)
138
+ return formatBinaryData(value, value);
139
+ if (value instanceof Uint8Array)
140
+ return formatBinaryData(value, Buffer.from(value));
141
+ if (value instanceof ArrayBuffer)
142
+ return formatBinaryData(value, Buffer.from(value));
143
+ if (value instanceof SharedArrayBuffer)
144
+ return formatBinaryData(value, Buffer.from(value));
145
+ return stringifyObjectType(value);
146
+ }
147
+ function prefixType(type) {
148
+ switch (type) {
149
+ case "bigint":
150
+ case "boolean":
151
+ case "buffer":
152
+ case "function":
153
+ case "map":
154
+ case "number":
155
+ case "promise":
156
+ case "regexp":
157
+ case "set":
158
+ case "string":
159
+ case "symbol":
160
+ return `a <${type}>`;
161
+ case "array":
162
+ case "object":
163
+ return `an <${type}>`;
164
+ case "null":
165
+ case "undefined":
166
+ return `<${type}>`;
167
+ default:
168
+ return `of unknown type <${type}>`;
169
+ }
170
+ }
171
+ var matcherMarker = Symbol.for("expect5.matcher");
172
+ function isMatcher(what) {
173
+ return what && what[matcherMarker] === matcherMarker;
174
+ }
175
+ var ExpectationError = class extends Error {
176
+ diff;
177
+ constructor(context, negative, details, diff) {
178
+ const { value } = context;
179
+ const not = negative ? " not" : "";
180
+ let preamble = stringifyValue(value);
181
+ if (context.parent) {
182
+ const properties = [];
183
+ while (context.parent) {
184
+ properties.push(`[${stringifyValue(context.parent.prop)}]`);
185
+ context = context.parent.context;
186
+ }
187
+ preamble = properties.reverse().join("");
188
+ const type = typeof context.value === "object" ? stringifyObjectType(context.value) : (
189
+ // parent values can not be null!
190
+ stringifyValue(context.value)
191
+ );
192
+ preamble = `property ${preamble} of ${type} (${stringifyValue(value)})`;
193
+ }
194
+ super(`Expected ${preamble}${not} ${details}`);
195
+ if (diff)
196
+ this.diff = diff;
197
+ }
198
+ };
199
+ // Annotate the CommonJS export names for ESM import in node:
200
+ 0 && (module.exports = {
201
+ ExpectationError,
202
+ assertType,
203
+ isMatcher,
204
+ isType,
205
+ matcherMarker,
206
+ prefixType,
207
+ stringifyConstructor,
208
+ stringifyObjectType,
209
+ stringifyValue,
210
+ typeOf
211
+ });
212
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/expectation/types.ts"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDO,SAAS,OAAO,OAA0B;AAC/C,MAAI,UAAU;AAAM,WAAO;AAG3B,QAAM,OAAO,OAAO;AACpB,UAAQ,MAAM;AAAA,IACZ,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAA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AI;AAAM,WAAK,OAAO;AAAA,EACxB;AACF;",
5
+ "names": []
6
+ }
@@ -0,0 +1,57 @@
1
+ /// <reference types="node" />
2
+ import type { Diff } from './diff';
3
+ import type { Expectations, ExpectationsMatcher } from './expect';
4
+ /** A type identifying any constructor */
5
+ export type Constructor<T = any> = new (...args: any[]) => T;
6
+ /** A type identifying any function */
7
+ export type Callable<T = any> = (...args: readonly any[]) => T;
8
+ /** A simple _record_ indicating an `object` but never an `array` */
9
+ export type NonArrayObject<T = any> = {
10
+ [a: string]: T;
11
+ [b: symbol]: T;
12
+ [c: number]: never;
13
+ };
14
+ /** A type identifying the parameter of `string.match(...)` */
15
+ export type StringMatcher = string | RegExp | {
16
+ [Symbol.match](string: string): RegExpMatchArray | null;
17
+ };
18
+ /** Mappings for our _expanded_ {@link typeOf} implementation */
19
+ export type TypeMappings = {
20
+ bigint: bigint;
21
+ boolean: boolean;
22
+ function: Callable;
23
+ number: number;
24
+ string: string;
25
+ symbol: symbol;
26
+ undefined: undefined;
27
+ array: readonly any[];
28
+ buffer: Buffer;
29
+ map: Map<any, any>;
30
+ promise: PromiseLike<any>;
31
+ regexp: RegExp;
32
+ set: Set<any>;
33
+ object: NonArrayObject<any>;
34
+ null: null;
35
+ };
36
+ /** Values returned by our own _expanded_ `{@link typeOf}` */
37
+ export type TypeName = keyof TypeMappings;
38
+ /** Expanded `typeof` implementation returning some extra types */
39
+ export declare function typeOf(value: unknown): TypeName;
40
+ /** Determines if the specified `value` is of the specified _expanded_ `type` */
41
+ export declare function isType<T extends keyof TypeMappings>(context: Expectations, type: T): context is Expectations<TypeMappings[T]>;
42
+ /** Asserts that the specified `value` is of the specified _expanded_ `type` */
43
+ export declare function assertType<T extends keyof TypeMappings>(context: Expectations, type: T): asserts context is Expectations<TypeMappings[T]>;
44
+ /** Stringify the type of an object (its constructor name) */
45
+ export declare function stringifyObjectType(value: object): string;
46
+ /** Stringify a constructor */
47
+ export declare function stringifyConstructor(ctor: Constructor): string;
48
+ /** Pretty print the value (strings, numbers, booleans) or return the type */
49
+ export declare function stringifyValue(value: unknown): string;
50
+ /** Add the `a`/`an`/... prefix to the type name */
51
+ export declare function prefixType(type: TypeName): string;
52
+ export declare const matcherMarker: unique symbol;
53
+ export declare function isMatcher(what: any): what is ExpectationsMatcher;
54
+ export declare class ExpectationError extends Error {
55
+ diff?: Diff | undefined;
56
+ constructor(context: Expectations, negative: boolean, details: string, diff?: Diff);
57
+ }