hein 1.4.2 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/ESM_MIGRATION_NOTES.md +6 -0
- package/README.md +46 -7
- package/dist/assert-9EsvfQwn.d.cts +483 -0
- package/dist/assert-9EsvfQwn.d.cts.map +1 -0
- package/dist/assert-B_vcZS90.d.ts +481 -0
- package/dist/assert-B_vcZS90.d.ts.map +1 -0
- package/dist/assert-DZjgWjOw.cjs +1626 -0
- package/dist/assert-DZjgWjOw.cjs.map +1 -0
- package/dist/assert-kFXp7i_B.js +1260 -0
- package/dist/assert-kFXp7i_B.js.map +1 -0
- package/dist/assert.cjs +53 -0
- package/dist/assert.d.cts +3 -0
- package/dist/assert.d.ts +3 -27
- package/dist/assert.js +3 -84
- package/dist/chunk-CTAAG5j7.js +13 -0
- package/dist/expect.types-DPl6xY56.d.ts +99 -0
- package/dist/expect.types-DPl6xY56.d.ts.map +1 -0
- package/dist/expect.types-s8icgWp5.d.cts +99 -0
- package/dist/expect.types-s8icgWp5.d.cts.map +1 -0
- package/dist/expect.types.cjs +0 -0
- package/dist/expect.types.d.cts +3 -0
- package/dist/expect.types.d.ts +3 -66
- package/dist/expect.types.js +1 -4
- package/dist/index.cjs +596 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +16 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +573 -27
- package/dist/index.js.map +1 -1
- package/dist/throws-BrCCeBBl.d.ts +42 -0
- package/dist/throws-BrCCeBBl.d.ts.map +1 -0
- package/dist/throws-D7JsW4NM.d.cts +40 -0
- package/dist/throws-D7JsW4NM.d.cts.map +1 -0
- package/eslint.config.mjs +13 -0
- package/package.json +31 -18
- package/tsdown.config.ts +9 -0
- package/dist/assert/deep-equal.d.ts +0 -2
- package/dist/assert/deep-equal.d.ts.map +0 -1
- package/dist/assert/deep-equal.js +0 -26
- package/dist/assert/deep-equal.js.map +0 -1
- package/dist/assert/deep-has-property.d.ts +0 -20
- package/dist/assert/deep-has-property.d.ts.map +0 -1
- package/dist/assert/deep-has-property.js +0 -50
- package/dist/assert/deep-has-property.js.map +0 -1
- package/dist/assert/ends-with.d.ts +0 -11
- package/dist/assert/ends-with.d.ts.map +0 -1
- package/dist/assert/ends-with.js +0 -30
- package/dist/assert/ends-with.js.map +0 -1
- package/dist/assert/equal.d.ts +0 -9
- package/dist/assert/equal.d.ts.map +0 -1
- package/dist/assert/equal.js +0 -21
- package/dist/assert/equal.js.map +0 -1
- package/dist/assert/greater-than-equal.d.ts +0 -9
- package/dist/assert/greater-than-equal.d.ts.map +0 -1
- package/dist/assert/greater-than-equal.js +0 -20
- package/dist/assert/greater-than-equal.js.map +0 -1
- package/dist/assert/greater-than.d.ts +0 -9
- package/dist/assert/greater-than.d.ts.map +0 -1
- package/dist/assert/greater-than.js +0 -20
- package/dist/assert/greater-than.js.map +0 -1
- package/dist/assert/has-keys.d.ts +0 -14
- package/dist/assert/has-keys.d.ts.map +0 -1
- package/dist/assert/has-keys.js +0 -47
- package/dist/assert/has-keys.js.map +0 -1
- package/dist/assert/has-members.d.ts +0 -46
- package/dist/assert/has-members.d.ts.map +0 -1
- package/dist/assert/has-members.js +0 -58
- package/dist/assert/has-members.js.map +0 -1
- package/dist/assert/has-property.d.ts +0 -20
- package/dist/assert/has-property.d.ts.map +0 -1
- package/dist/assert/has-property.js +0 -47
- package/dist/assert/has-property.js.map +0 -1
- package/dist/assert/has-size.d.ts +0 -40
- package/dist/assert/has-size.d.ts.map +0 -1
- package/dist/assert/has-size.js +0 -68
- package/dist/assert/has-size.js.map +0 -1
- package/dist/assert/in-ballpark.d.ts +0 -14
- package/dist/assert/in-ballpark.d.ts.map +0 -1
- package/dist/assert/in-ballpark.js +0 -26
- package/dist/assert/in-ballpark.js.map +0 -1
- package/dist/assert/includes.d.ts +0 -22
- package/dist/assert/includes.d.ts.map +0 -1
- package/dist/assert/includes.js +0 -32
- package/dist/assert/includes.js.map +0 -1
- package/dist/assert/instance-of.d.ts +0 -13
- package/dist/assert/instance-of.d.ts.map +0 -1
- package/dist/assert/instance-of.js +0 -35
- package/dist/assert/instance-of.js.map +0 -1
- package/dist/assert/is-after.d.ts +0 -9
- package/dist/assert/is-after.d.ts.map +0 -1
- package/dist/assert/is-after.js +0 -27
- package/dist/assert/is-after.js.map +0 -1
- package/dist/assert/is-before.d.ts +0 -9
- package/dist/assert/is-before.d.ts.map +0 -1
- package/dist/assert/is-before.js +0 -27
- package/dist/assert/is-before.js.map +0 -1
- package/dist/assert/is-between.d.ts +0 -13
- package/dist/assert/is-between.d.ts.map +0 -1
- package/dist/assert/is-between.js +0 -38
- package/dist/assert/is-between.js.map +0 -1
- package/dist/assert/is-empty.d.ts +0 -29
- package/dist/assert/is-empty.d.ts.map +0 -1
- package/dist/assert/is-empty.js +0 -48
- package/dist/assert/is-empty.js.map +0 -1
- package/dist/assert/is-type.d.ts +0 -94
- package/dist/assert/is-type.d.ts.map +0 -1
- package/dist/assert/is-type.js +0 -32
- package/dist/assert/is-type.js.map +0 -1
- package/dist/assert/less-than-equal.d.ts +0 -9
- package/dist/assert/less-than-equal.d.ts.map +0 -1
- package/dist/assert/less-than-equal.js +0 -27
- package/dist/assert/less-than-equal.js.map +0 -1
- package/dist/assert/less-than.d.ts +0 -9
- package/dist/assert/less-than.d.ts.map +0 -1
- package/dist/assert/less-than.js +0 -20
- package/dist/assert/less-than.js.map +0 -1
- package/dist/assert/match.d.ts +0 -13
- package/dist/assert/match.d.ts.map +0 -1
- package/dist/assert/match.js +0 -29
- package/dist/assert/match.js.map +0 -1
- package/dist/assert/rejects.d.ts +0 -33
- package/dist/assert/rejects.d.ts.map +0 -1
- package/dist/assert/rejects.js +0 -48
- package/dist/assert/rejects.js.map +0 -1
- package/dist/assert/round-to.d.ts +0 -13
- package/dist/assert/round-to.d.ts.map +0 -1
- package/dist/assert/round-to.js +0 -43
- package/dist/assert/round-to.js.map +0 -1
- package/dist/assert/starts-with.d.ts +0 -12
- package/dist/assert/starts-with.d.ts.map +0 -1
- package/dist/assert/starts-with.js +0 -30
- package/dist/assert/starts-with.js.map +0 -1
- package/dist/assert/throws.d.ts +0 -33
- package/dist/assert/throws.d.ts.map +0 -1
- package/dist/assert/throws.js +0 -40
- package/dist/assert/throws.js.map +0 -1
- package/dist/assert.d.ts.map +0 -1
- package/dist/assert.js.map +0 -1
- package/dist/expect/after.d.ts +0 -11
- package/dist/expect/after.d.ts.map +0 -1
- package/dist/expect/after.js +0 -18
- package/dist/expect/after.js.map +0 -1
- package/dist/expect/ballpark.d.ts +0 -12
- package/dist/expect/ballpark.d.ts.map +0 -1
- package/dist/expect/ballpark.js +0 -18
- package/dist/expect/ballpark.js.map +0 -1
- package/dist/expect/before.d.ts +0 -11
- package/dist/expect/before.d.ts.map +0 -1
- package/dist/expect/before.js +0 -18
- package/dist/expect/before.js.map +0 -1
- package/dist/expect/between.d.ts +0 -21
- package/dist/expect/between.d.ts.map +0 -1
- package/dist/expect/between.js +0 -18
- package/dist/expect/between.js.map +0 -1
- package/dist/expect/empty.d.ts +0 -16
- package/dist/expect/empty.d.ts.map +0 -1
- package/dist/expect/empty.js +0 -18
- package/dist/expect/empty.js.map +0 -1
- package/dist/expect/end-with.d.ts +0 -12
- package/dist/expect/end-with.d.ts.map +0 -1
- package/dist/expect/end-with.js +0 -18
- package/dist/expect/end-with.js.map +0 -1
- package/dist/expect/eql.d.ts +0 -11
- package/dist/expect/eql.d.ts.map +0 -1
- package/dist/expect/eql.js +0 -22
- package/dist/expect/eql.js.map +0 -1
- package/dist/expect/equal-shorthand.d.ts +0 -14
- package/dist/expect/equal-shorthand.d.ts.map +0 -1
- package/dist/expect/equal-shorthand.js +0 -34
- package/dist/expect/equal-shorthand.js.map +0 -1
- package/dist/expect/equal.d.ts +0 -14
- package/dist/expect/equal.d.ts.map +0 -1
- package/dist/expect/equal.js +0 -28
- package/dist/expect/equal.js.map +0 -1
- package/dist/expect/excluding.d.ts +0 -11
- package/dist/expect/excluding.d.ts.map +0 -1
- package/dist/expect/excluding.js +0 -14
- package/dist/expect/excluding.js.map +0 -1
- package/dist/expect/greater-than-equal.d.ts +0 -32
- package/dist/expect/greater-than-equal.d.ts.map +0 -1
- package/dist/expect/greater-than-equal.js +0 -20
- package/dist/expect/greater-than-equal.js.map +0 -1
- package/dist/expect/greater-than.d.ts +0 -32
- package/dist/expect/greater-than.d.ts.map +0 -1
- package/dist/expect/greater-than.js +0 -20
- package/dist/expect/greater-than.js.map +0 -1
- package/dist/expect/has-property.d.ts +0 -36
- package/dist/expect/has-property.d.ts.map +0 -1
- package/dist/expect/has-property.js +0 -22
- package/dist/expect/has-property.js.map +0 -1
- package/dist/expect/include.d.ts +0 -25
- package/dist/expect/include.d.ts.map +0 -1
- package/dist/expect/include.js +0 -22
- package/dist/expect/include.js.map +0 -1
- package/dist/expect/instance-of-shorthand.d.ts +0 -34
- package/dist/expect/instance-of-shorthand.d.ts.map +0 -1
- package/dist/expect/instance-of-shorthand.js +0 -22
- package/dist/expect/instance-of-shorthand.js.map +0 -1
- package/dist/expect/instance-of.d.ts +0 -11
- package/dist/expect/instance-of.d.ts.map +0 -1
- package/dist/expect/instance-of.js +0 -18
- package/dist/expect/instance-of.js.map +0 -1
- package/dist/expect/keys.d.ts +0 -17
- package/dist/expect/keys.d.ts.map +0 -1
- package/dist/expect/keys.js +0 -18
- package/dist/expect/keys.js.map +0 -1
- package/dist/expect/length.d.ts +0 -28
- package/dist/expect/length.d.ts.map +0 -1
- package/dist/expect/length.js +0 -19
- package/dist/expect/length.js.map +0 -1
- package/dist/expect/less-than-equal.d.ts +0 -32
- package/dist/expect/less-than-equal.d.ts.map +0 -1
- package/dist/expect/less-than-equal.js +0 -20
- package/dist/expect/less-than-equal.js.map +0 -1
- package/dist/expect/less-than.d.ts +0 -32
- package/dist/expect/less-than.d.ts.map +0 -1
- package/dist/expect/less-than.js +0 -20
- package/dist/expect/less-than.js.map +0 -1
- package/dist/expect/match.d.ts +0 -10
- package/dist/expect/match.d.ts.map +0 -1
- package/dist/expect/match.js +0 -18
- package/dist/expect/match.js.map +0 -1
- package/dist/expect/members.d.ts +0 -20
- package/dist/expect/members.d.ts.map +0 -1
- package/dist/expect/members.js +0 -32
- package/dist/expect/members.js.map +0 -1
- package/dist/expect/reject.d.ts +0 -12
- package/dist/expect/reject.d.ts.map +0 -1
- package/dist/expect/reject.js +0 -13
- package/dist/expect/reject.js.map +0 -1
- package/dist/expect/round-to.d.ts +0 -12
- package/dist/expect/round-to.d.ts.map +0 -1
- package/dist/expect/round-to.js +0 -18
- package/dist/expect/round-to.js.map +0 -1
- package/dist/expect/start-with.d.ts +0 -12
- package/dist/expect/start-with.d.ts.map +0 -1
- package/dist/expect/start-with.js +0 -18
- package/dist/expect/start-with.js.map +0 -1
- package/dist/expect/throw.d.ts +0 -12
- package/dist/expect/throw.d.ts.map +0 -1
- package/dist/expect/throw.js +0 -13
- package/dist/expect/throw.js.map +0 -1
- package/dist/expect/type-shorthand.d.ts +0 -66
- package/dist/expect/type-shorthand.d.ts.map +0 -1
- package/dist/expect/type-shorthand.js +0 -34
- package/dist/expect/type-shorthand.js.map +0 -1
- package/dist/expect/type.d.ts +0 -10
- package/dist/expect/type.d.ts.map +0 -1
- package/dist/expect/type.js +0 -18
- package/dist/expect/type.js.map +0 -1
- package/dist/expect.d.ts +0 -33
- package/dist/expect.d.ts.map +0 -1
- package/dist/expect.js +0 -88
- package/dist/expect.js.map +0 -1
- package/dist/expect.types.d.ts.map +0 -1
- package/dist/expect.types.js.map +0 -1
- package/dist/mixins.d.ts +0 -26
- package/dist/mixins.d.ts.map +0 -1
- package/dist/mixins.js +0 -9
- package/dist/mixins.js.map +0 -1
- package/dist/utils/cast-array.d.ts +0 -2
- package/dist/utils/cast-array.d.ts.map +0 -1
- package/dist/utils/cast-array.js +0 -14
- package/dist/utils/cast-array.js.map +0 -1
- package/dist/utils/chain.d.ts +0 -3
- package/dist/utils/chain.d.ts.map +0 -1
- package/dist/utils/chain.js +0 -21
- package/dist/utils/chain.js.map +0 -1
- package/dist/utils/fail.d.ts +0 -6
- package/dist/utils/fail.d.ts.map +0 -1
- package/dist/utils/fail.js +0 -13
- package/dist/utils/fail.js.map +0 -1
- package/dist/utils/get-size.d.ts +0 -2
- package/dist/utils/get-size.d.ts.map +0 -1
- package/dist/utils/get-size.js +0 -24
- package/dist/utils/get-size.js.map +0 -1
- package/dist/utils/get-type.d.ts +0 -3
- package/dist/utils/get-type.d.ts.map +0 -1
- package/dist/utils/get-type.js +0 -17
- package/dist/utils/get-type.js.map +0 -1
- package/dist/utils/match.d.ts +0 -15
- package/dist/utils/match.d.ts.map +0 -1
- package/dist/utils/match.js +0 -150
- package/dist/utils/match.js.map +0 -1
- package/dist/utils/process-error.d.ts +0 -11
- package/dist/utils/process-error.d.ts.map +0 -1
- package/dist/utils/process-error.js +0 -98
- package/dist/utils/process-error.js.map +0 -1
- package/dist/utils/types.d.ts +0 -4
- package/dist/utils/types.d.ts.map +0 -1
- package/dist/utils/types.js +0 -3
- package/dist/utils/types.js.map +0 -1
- package/dist/utils/validate-numeric-and-dates.d.ts +0 -2
- package/dist/utils/validate-numeric-and-dates.d.ts.map +0 -1
- package/dist/utils/validate-numeric-and-dates.js +0 -15
- package/dist/utils/validate-numeric-and-dates.js.map +0 -1
- package/dist/utils/xor.d.ts +0 -2
- package/dist/utils/xor.d.ts.map +0 -1
- package/dist/utils/xor.js +0 -8
- package/dist/utils/xor.js.map +0 -1
|
@@ -0,0 +1,1626 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (all) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
18
|
+
key = keys[i];
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
20
|
+
get: ((k) => from[k]).bind(null, key),
|
|
21
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
27
|
+
value: mod,
|
|
28
|
+
enumerable: true
|
|
29
|
+
}) : target, mod));
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
let lodash_cloneDeep_js = require("lodash/cloneDeep.js");
|
|
33
|
+
lodash_cloneDeep_js = __toESM(lodash_cloneDeep_js);
|
|
34
|
+
let hein_assertion_utils = require("hein-assertion-utils");
|
|
35
|
+
hein_assertion_utils = __toESM(hein_assertion_utils);
|
|
36
|
+
let lodash_isObjectLike_js = require("lodash/isObjectLike.js");
|
|
37
|
+
lodash_isObjectLike_js = __toESM(lodash_isObjectLike_js);
|
|
38
|
+
let lodash_isPlainObject_js = require("lodash/isPlainObject.js");
|
|
39
|
+
lodash_isPlainObject_js = __toESM(lodash_isPlainObject_js);
|
|
40
|
+
let lodash_get_js = require("lodash/get.js");
|
|
41
|
+
lodash_get_js = __toESM(lodash_get_js);
|
|
42
|
+
let lodash_has_js = require("lodash/has.js");
|
|
43
|
+
lodash_has_js = __toESM(lodash_has_js);
|
|
44
|
+
let lodash_castArray_js = require("lodash/castArray.js");
|
|
45
|
+
lodash_castArray_js = __toESM(lodash_castArray_js);
|
|
46
|
+
|
|
47
|
+
//#region src/utils/xor.ts
|
|
48
|
+
const xor = (a, b) => {
|
|
49
|
+
return a && !b || !a && b;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/utils/match.ts
|
|
54
|
+
const evaluationSymbol = Symbol();
|
|
55
|
+
const createEvaluation = (callback) => {
|
|
56
|
+
const evaluation = (value) => {
|
|
57
|
+
return callback(value);
|
|
58
|
+
};
|
|
59
|
+
evaluation[evaluationSymbol] = true;
|
|
60
|
+
return evaluation;
|
|
61
|
+
};
|
|
62
|
+
const any = createEvaluation(() => true);
|
|
63
|
+
const isEvaluation = (value) => value && value[evaluationSymbol];
|
|
64
|
+
const match$1 = (actual, expected, { mutate = false, partial = false } = {}) => {
|
|
65
|
+
if (actual === expected) return true;
|
|
66
|
+
if (isEvaluation(expected)) return expected(actual);
|
|
67
|
+
if (actual == null || expected == null || !(0, lodash_isObjectLike_js.default)(actual) && !(0, lodash_isObjectLike_js.default)(expected)) return actual !== actual && expected !== expected;
|
|
68
|
+
let result = true;
|
|
69
|
+
if (actual instanceof Map || expected instanceof Map) {
|
|
70
|
+
if (!(actual instanceof Map && expected instanceof Map)) return false;
|
|
71
|
+
if (actual.size !== expected.size && !partial) result = false;
|
|
72
|
+
for (const [key, value] of expected.entries()) {
|
|
73
|
+
if (!actual.has(key)) {
|
|
74
|
+
result = false;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const actualValue = actual.get(key);
|
|
78
|
+
if (mutate && isEvaluation(value)) {
|
|
79
|
+
expected.set(key, actualValue);
|
|
80
|
+
result && (result = value(actualValue));
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
result = match$1(actualValue, value, {
|
|
84
|
+
mutate,
|
|
85
|
+
partial
|
|
86
|
+
}) && result;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
if (actual instanceof WeakMap || expected instanceof WeakMap) return false;
|
|
92
|
+
if (actual instanceof Set || expected instanceof Set) {
|
|
93
|
+
if (!(actual instanceof Set && expected instanceof Set)) return false;
|
|
94
|
+
if (actual.size !== expected.size && !partial) return false;
|
|
95
|
+
return [...expected.values()].every((value) => {
|
|
96
|
+
return actual.has(value);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (actual instanceof WeakSet || expected instanceof WeakSet) return false;
|
|
100
|
+
if (actual instanceof Date || expected instanceof Date) {
|
|
101
|
+
if (!(actual instanceof Date && expected instanceof Date)) {
|
|
102
|
+
const date1 = new Date(actual);
|
|
103
|
+
const date2 = new Date(expected);
|
|
104
|
+
return date1.getTime() === date2.getTime();
|
|
105
|
+
}
|
|
106
|
+
if (actual.getTime() !== expected.getTime()) return false;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
if (xor((0, lodash_isObjectLike_js.default)(actual), (0, lodash_isObjectLike_js.default)(expected))) return false;
|
|
110
|
+
if (Array.isArray(actual) || Array.isArray(expected)) {
|
|
111
|
+
if (!(Array.isArray(actual) && Array.isArray(expected))) return false;
|
|
112
|
+
if (actual.length !== expected.length && !partial) result = false;
|
|
113
|
+
if (partial && actual.length < expected.length) result = false;
|
|
114
|
+
for (const [index, value] of actual.entries()) {
|
|
115
|
+
if (index >= expected.length) continue;
|
|
116
|
+
const expectedValue = expected[index];
|
|
117
|
+
if (mutate && isEvaluation(expectedValue)) {
|
|
118
|
+
const matchesEvaluation = expectedValue(value);
|
|
119
|
+
if (matchesEvaluation) expected[index] = value;
|
|
120
|
+
result && (result = matchesEvaluation);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
result && (result = match$1(value, expectedValue, {
|
|
124
|
+
mutate,
|
|
125
|
+
partial
|
|
126
|
+
}));
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
if (Object.keys(actual).length !== Object.keys(expected).length && !partial) result = false;
|
|
132
|
+
if (globalThis.Buffer && actual instanceof globalThis.Buffer && expected instanceof globalThis.Buffer) return Buffer.compare(actual, expected) === 0;
|
|
133
|
+
for (const key in expected) if (!(key in actual)) {
|
|
134
|
+
result && (result = false);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
for (const index in actual) {
|
|
138
|
+
const expectedValue = expected[index];
|
|
139
|
+
const actualValue = actual[index];
|
|
140
|
+
if (!(index in expected)) {
|
|
141
|
+
if (partial) continue;
|
|
142
|
+
result && (result = false);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (isEvaluation(expectedValue)) {
|
|
146
|
+
if (!expectedValue(actualValue)) {
|
|
147
|
+
result && (result = false);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (mutate) expected[index] = actualValue;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!match$1(actual[index], expectedValue, {
|
|
154
|
+
mutate,
|
|
155
|
+
partial
|
|
156
|
+
})) result = false;
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/assert/deep-equal.ts
|
|
163
|
+
const [deepEqual, notDeepEqual] = (0, hein_assertion_utils.createAssertion)({
|
|
164
|
+
messages: {
|
|
165
|
+
notEql: "Expected {{= it.actual }} to deep equal {{= it.expected }}",
|
|
166
|
+
not: "Expected {{= it.actual }} to not deep equal {{= it.expected }}"
|
|
167
|
+
},
|
|
168
|
+
test: (report) => (actual, expected, partialOrMessage = false, message) => {
|
|
169
|
+
const partial = typeof partialOrMessage === "boolean" ? partialOrMessage : false;
|
|
170
|
+
message = typeof partialOrMessage === "string" ? partialOrMessage : message;
|
|
171
|
+
if (typeof expected !== "function") expected = (0, lodash_cloneDeep_js.default)(expected);
|
|
172
|
+
if (match$1(actual, expected, {
|
|
173
|
+
mutate: true,
|
|
174
|
+
partial
|
|
175
|
+
})) return report({
|
|
176
|
+
message,
|
|
177
|
+
status: "ok",
|
|
178
|
+
expected,
|
|
179
|
+
actual
|
|
180
|
+
});
|
|
181
|
+
return report({
|
|
182
|
+
message,
|
|
183
|
+
status: "notok",
|
|
184
|
+
messageId: "notEql",
|
|
185
|
+
expected,
|
|
186
|
+
actual
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/assert/equal.ts
|
|
193
|
+
const [equal, notEqual] = (0, hein_assertion_utils.createAssertion)({
|
|
194
|
+
messages: {
|
|
195
|
+
equal: "Expected {{= it.actual }} to equal {{= it.expected }}",
|
|
196
|
+
not: "Expected {{= it.actual }} to not equal {{= it.expected }}"
|
|
197
|
+
},
|
|
198
|
+
test: (report) => (a, b, message) => {
|
|
199
|
+
if (Number.isNaN(a) && Number.isNaN(b)) return report({
|
|
200
|
+
status: "ok",
|
|
201
|
+
expected: b,
|
|
202
|
+
actual: a,
|
|
203
|
+
message
|
|
204
|
+
});
|
|
205
|
+
if (a !== b) return report({
|
|
206
|
+
status: "notok",
|
|
207
|
+
messageId: "equal",
|
|
208
|
+
actual: a,
|
|
209
|
+
expected: b,
|
|
210
|
+
message
|
|
211
|
+
});
|
|
212
|
+
return report({
|
|
213
|
+
status: "ok",
|
|
214
|
+
expected: a,
|
|
215
|
+
actual: b,
|
|
216
|
+
message
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/utils/get-type.ts
|
|
223
|
+
const getType = (value) => {
|
|
224
|
+
if (value !== value) return "NaN";
|
|
225
|
+
if (Array.isArray(value)) return "array";
|
|
226
|
+
if (value === null) return "null";
|
|
227
|
+
return typeof value;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/utils/validate-numeric-and-dates.ts
|
|
232
|
+
const allowedTypes = [
|
|
233
|
+
"number",
|
|
234
|
+
"bigint",
|
|
235
|
+
"date"
|
|
236
|
+
];
|
|
237
|
+
const validateNumericsAndDates = (actual, expected) => {
|
|
238
|
+
const actualType = actual instanceof Date ? "date" : getType(actual);
|
|
239
|
+
const expectedType = expected instanceof Date ? "date" : getType(expected);
|
|
240
|
+
if (!allowedTypes.includes(actualType) || !allowedTypes.includes(expectedType)) throw new hein_assertion_utils.AssertionError(actualType, expectedType, `Expected arguments to be ${allowedTypes.join("/")}, received ${actualType}/${expectedType}`);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/assert/greater-than.ts
|
|
245
|
+
const [greaterThan, notGreaterThan] = (0, hein_assertion_utils.createAssertion)({
|
|
246
|
+
messages: {
|
|
247
|
+
smaller: "Expected {{= it.actual }} to be greater than {{= it.expected }}",
|
|
248
|
+
not: "Expected {{= it.actual }} to not be greater than {{= it.expected }}"
|
|
249
|
+
},
|
|
250
|
+
test: (report) => (actual, expected) => {
|
|
251
|
+
validateNumericsAndDates(actual, expected);
|
|
252
|
+
if (actual > expected) return report({
|
|
253
|
+
status: "ok",
|
|
254
|
+
messageId: "not",
|
|
255
|
+
expected,
|
|
256
|
+
actual
|
|
257
|
+
});
|
|
258
|
+
return report({
|
|
259
|
+
status: "notok",
|
|
260
|
+
messageId: "smaller",
|
|
261
|
+
actual,
|
|
262
|
+
expected,
|
|
263
|
+
noStringify: true
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/assert/greater-than-equal.ts
|
|
270
|
+
const [greaterThanEqual, notGreaterThanEqual] = (0, hein_assertion_utils.createAssertion)({
|
|
271
|
+
messages: {
|
|
272
|
+
notGreaterThanEqual: "Expected {{= it.actual }} to not be greater than or equal to {{= it.expected }}",
|
|
273
|
+
not: "Expected {{= it.actual }} to not be greater than or equal to {{= it.expected }}"
|
|
274
|
+
},
|
|
275
|
+
test: (report) => (a, b, message) => {
|
|
276
|
+
validateNumericsAndDates(a, b);
|
|
277
|
+
if (a < b) return report({
|
|
278
|
+
status: "notok",
|
|
279
|
+
messageId: "notGreaterThanEqual",
|
|
280
|
+
actual: a,
|
|
281
|
+
expected: b,
|
|
282
|
+
message
|
|
283
|
+
});
|
|
284
|
+
return report({
|
|
285
|
+
status: "ok",
|
|
286
|
+
expected: a,
|
|
287
|
+
actual: b
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/assert/has-property.ts
|
|
294
|
+
const [hasProperty, notHasProperty] = (0, hein_assertion_utils.createAssertion)({
|
|
295
|
+
messages: {
|
|
296
|
+
noProperty: "Expected {{= it.actual }} to have property {{= it.expected }}",
|
|
297
|
+
wrongValue: "Expected {{= it.obj }} to have property {{= it.expected }} with value {{= it.value }}",
|
|
298
|
+
not: "Expected {{= it.actual }} to not have property {{= it.expected }}",
|
|
299
|
+
notWrongValue: "Expected {{= it.obj }} to not have property {{= it.expected }} with value {{= it.value }}"
|
|
300
|
+
},
|
|
301
|
+
test: (report) => (...args) => {
|
|
302
|
+
const [actual, expected, value] = args;
|
|
303
|
+
const actualStringified = (0, hein_assertion_utils.stringify)(actual);
|
|
304
|
+
if (expected in actual) {
|
|
305
|
+
if (args.length === 3) {
|
|
306
|
+
if (actual[expected] === value) return report({
|
|
307
|
+
status: "ok",
|
|
308
|
+
messageId: "notWrongValue",
|
|
309
|
+
expected,
|
|
310
|
+
actual: actualStringified,
|
|
311
|
+
data: {
|
|
312
|
+
value,
|
|
313
|
+
expected,
|
|
314
|
+
obj: actual
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
return report({
|
|
318
|
+
status: "notok",
|
|
319
|
+
messageId: "wrongValue",
|
|
320
|
+
expected,
|
|
321
|
+
actual: actualStringified,
|
|
322
|
+
data: {
|
|
323
|
+
value,
|
|
324
|
+
obj: actualStringified
|
|
325
|
+
},
|
|
326
|
+
noStringify: true
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
return report({
|
|
330
|
+
status: "ok",
|
|
331
|
+
noStringify: true,
|
|
332
|
+
expected,
|
|
333
|
+
actual: actualStringified
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
return report({
|
|
337
|
+
status: "notok",
|
|
338
|
+
messageId: "noProperty",
|
|
339
|
+
expected,
|
|
340
|
+
actual: actualStringified,
|
|
341
|
+
noStringify: true
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/assert/has-size.ts
|
|
348
|
+
const [hasSize, notHasSize] = (0, hein_assertion_utils.createAssertion)({
|
|
349
|
+
messages: {
|
|
350
|
+
array: "Expected array to have length of {{= it.expected }}",
|
|
351
|
+
object: "Expected object to have size of {{= it.expected }}",
|
|
352
|
+
map: "Expected Map to have size of {{= it.expected }}",
|
|
353
|
+
set: "Expected Set to have size of {{= it.expected }}",
|
|
354
|
+
string: "Expected string to have length of {{= it.expected }}",
|
|
355
|
+
not: "Expected array to not have length of {{= it.expected }}",
|
|
356
|
+
notObject: "Expected object to not have size of {{= it.expected }}",
|
|
357
|
+
notMap: "Expected Map to not have size of {{= it.expected }}",
|
|
358
|
+
notSet: "Expected Set to not have size of {{= it.expected }}",
|
|
359
|
+
notString: "Expected string to not have length of {{= it.expected }}",
|
|
360
|
+
invalidValue: "Expected {{= it.actual }} to be an array, object, Map, Set or string"
|
|
361
|
+
},
|
|
362
|
+
test: (report) => (actual, expected, message) => {
|
|
363
|
+
if (Array.isArray(actual)) {
|
|
364
|
+
if (actual.length === expected) return report({
|
|
365
|
+
message,
|
|
366
|
+
status: "ok",
|
|
367
|
+
expected,
|
|
368
|
+
actual: actual.length
|
|
369
|
+
});
|
|
370
|
+
return report({
|
|
371
|
+
message,
|
|
372
|
+
status: "notok",
|
|
373
|
+
messageId: "array",
|
|
374
|
+
expected,
|
|
375
|
+
actual: actual.length
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
if ((0, lodash_isPlainObject_js.default)(actual)) {
|
|
379
|
+
if (Object.keys(actual).length === expected) return report({
|
|
380
|
+
message,
|
|
381
|
+
status: "ok",
|
|
382
|
+
messageId: "notObject",
|
|
383
|
+
expected,
|
|
384
|
+
actual: Object.keys(actual).length
|
|
385
|
+
});
|
|
386
|
+
return report({
|
|
387
|
+
message,
|
|
388
|
+
status: "notok",
|
|
389
|
+
messageId: "object",
|
|
390
|
+
expected,
|
|
391
|
+
actual: Object.keys(actual).length
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
if (actual instanceof Map) {
|
|
395
|
+
if (actual.size === expected) return report({
|
|
396
|
+
message,
|
|
397
|
+
status: "ok",
|
|
398
|
+
messageId: "notMap",
|
|
399
|
+
expected,
|
|
400
|
+
actual: actual.size
|
|
401
|
+
});
|
|
402
|
+
return report({
|
|
403
|
+
message,
|
|
404
|
+
status: "notok",
|
|
405
|
+
messageId: "map",
|
|
406
|
+
expected,
|
|
407
|
+
actual: actual.size
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
if (actual instanceof Set) {
|
|
411
|
+
if (actual.size === expected) return report({
|
|
412
|
+
message,
|
|
413
|
+
status: "ok",
|
|
414
|
+
messageId: "notSet",
|
|
415
|
+
expected,
|
|
416
|
+
actual: actual.size
|
|
417
|
+
});
|
|
418
|
+
return report({
|
|
419
|
+
message,
|
|
420
|
+
status: "notok",
|
|
421
|
+
messageId: "set",
|
|
422
|
+
expected,
|
|
423
|
+
actual: actual.size
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
if (typeof actual === "string") {
|
|
427
|
+
if (actual.length === expected) return report({
|
|
428
|
+
message,
|
|
429
|
+
status: "ok",
|
|
430
|
+
messageId: "notString",
|
|
431
|
+
expected,
|
|
432
|
+
actual: actual.length
|
|
433
|
+
});
|
|
434
|
+
return report({
|
|
435
|
+
message,
|
|
436
|
+
status: "notok",
|
|
437
|
+
messageId: "string",
|
|
438
|
+
expected,
|
|
439
|
+
actual: actual.length
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
report({
|
|
443
|
+
message,
|
|
444
|
+
status: "notok",
|
|
445
|
+
messageId: "invalidValue",
|
|
446
|
+
actual: typeof actual,
|
|
447
|
+
noStringify: true
|
|
448
|
+
});
|
|
449
|
+
report({
|
|
450
|
+
message,
|
|
451
|
+
status: "ok",
|
|
452
|
+
messageId: "invalidValue",
|
|
453
|
+
actual: typeof actual,
|
|
454
|
+
noStringify: true
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/assert/includes.ts
|
|
461
|
+
const [includes, notIncludes] = (0, hein_assertion_utils.createAssertion)({
|
|
462
|
+
messages: {
|
|
463
|
+
arrayMisses: "Expected {{= it.actual }} to include {{= it.expected }}",
|
|
464
|
+
not: "Expected {{= it.actual }} to not include {{= it.expected }}"
|
|
465
|
+
},
|
|
466
|
+
test: (report) => (actual, ...elements) => {
|
|
467
|
+
for (const element of elements) if (actual.includes(element)) report({
|
|
468
|
+
messageId: "not",
|
|
469
|
+
status: "ok",
|
|
470
|
+
actual,
|
|
471
|
+
expected: element
|
|
472
|
+
});
|
|
473
|
+
else report({
|
|
474
|
+
messageId: "arrayMisses",
|
|
475
|
+
status: "notok",
|
|
476
|
+
actual,
|
|
477
|
+
expected: element
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region src/assert/instance-of.ts
|
|
484
|
+
const [instanceOf, notInstanceOf] = (0, hein_assertion_utils.createAssertion)({
|
|
485
|
+
messages: {
|
|
486
|
+
notInstanceOf: "Expected {{= it.actual }} to be an instance of {{= it.expected }}",
|
|
487
|
+
not: "Expected {{= it.actual }} to not be an instance of {{= it.expected }}"
|
|
488
|
+
},
|
|
489
|
+
test: (report) => (actual, expected) => {
|
|
490
|
+
if (!(0, lodash_isObjectLike_js.default)(actual)) throw new hein_assertion_utils.AssertionError(getType(actual), "object", "Expected value to be an object");
|
|
491
|
+
if (!(actual instanceof expected)) return report({
|
|
492
|
+
status: "notok",
|
|
493
|
+
messageId: "notInstanceOf",
|
|
494
|
+
expected: expected.name,
|
|
495
|
+
actual: actual.constructor.name,
|
|
496
|
+
noStringify: true
|
|
497
|
+
});
|
|
498
|
+
return report({
|
|
499
|
+
status: "ok",
|
|
500
|
+
expected: expected.name,
|
|
501
|
+
actual: actual.constructor.name,
|
|
502
|
+
messageId: "not",
|
|
503
|
+
noStringify: true
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/assert/is-empty.ts
|
|
510
|
+
const [isEmpty, notIsEmpty] = (0, hein_assertion_utils.createAssertion)({
|
|
511
|
+
messages: {
|
|
512
|
+
array: "Expected array to be empty",
|
|
513
|
+
object: "Expected object to be empty",
|
|
514
|
+
map: "Expected Map to be empty",
|
|
515
|
+
set: "Expected Set to be empty",
|
|
516
|
+
not: "Expected array to not be empty",
|
|
517
|
+
notObject: "Expected object to not be empty",
|
|
518
|
+
notMap: "Expected Map to not be empty",
|
|
519
|
+
notSet: "Expected Set to not be empty",
|
|
520
|
+
invalidArgument: "Expected {{= it.actual }} to be an array, object, Map, or Set"
|
|
521
|
+
},
|
|
522
|
+
test: (report) => (actual, message) => {
|
|
523
|
+
if (Array.isArray(actual)) {
|
|
524
|
+
if (actual.length === 0) return report({
|
|
525
|
+
message,
|
|
526
|
+
status: "ok",
|
|
527
|
+
actual,
|
|
528
|
+
expected: []
|
|
529
|
+
});
|
|
530
|
+
return report({
|
|
531
|
+
message,
|
|
532
|
+
status: "notok",
|
|
533
|
+
messageId: "array",
|
|
534
|
+
actual,
|
|
535
|
+
expected: []
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
if ((0, lodash_isPlainObject_js.default)(actual)) {
|
|
539
|
+
if (Object.keys(actual).length === 0) return report({
|
|
540
|
+
message,
|
|
541
|
+
status: "ok",
|
|
542
|
+
messageId: "notObject",
|
|
543
|
+
actual
|
|
544
|
+
});
|
|
545
|
+
return report({
|
|
546
|
+
message,
|
|
547
|
+
status: "notok",
|
|
548
|
+
messageId: "object",
|
|
549
|
+
actual,
|
|
550
|
+
expected: {}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
if (actual instanceof Map) {
|
|
554
|
+
if (actual.size === 0) return report({
|
|
555
|
+
message,
|
|
556
|
+
status: "ok",
|
|
557
|
+
messageId: "notMap",
|
|
558
|
+
actual
|
|
559
|
+
});
|
|
560
|
+
return report({
|
|
561
|
+
message,
|
|
562
|
+
status: "notok",
|
|
563
|
+
messageId: "map",
|
|
564
|
+
actual,
|
|
565
|
+
expected: /* @__PURE__ */ new Map()
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
if (actual instanceof Set) {
|
|
569
|
+
if (actual.size === 0) return report({
|
|
570
|
+
message,
|
|
571
|
+
status: "ok",
|
|
572
|
+
messageId: "notSet",
|
|
573
|
+
actual
|
|
574
|
+
});
|
|
575
|
+
return report({
|
|
576
|
+
message,
|
|
577
|
+
status: "notok",
|
|
578
|
+
messageId: "set",
|
|
579
|
+
actual
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
report({
|
|
583
|
+
message,
|
|
584
|
+
status: "notok",
|
|
585
|
+
messageId: "invalidArgument",
|
|
586
|
+
actual
|
|
587
|
+
});
|
|
588
|
+
report({
|
|
589
|
+
message,
|
|
590
|
+
status: "ok",
|
|
591
|
+
messageId: "invalidArgument",
|
|
592
|
+
actual
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region src/assert/is-type.ts
|
|
599
|
+
const [isType, notIsType] = (0, hein_assertion_utils.createAssertion)({
|
|
600
|
+
messages: {
|
|
601
|
+
wrongType: "Expected {{= it.actual }} to be a(n) {{= it.expected }}",
|
|
602
|
+
not: `Expected {{= it.actual }} to not be a(n) {{= it.expected }}`
|
|
603
|
+
},
|
|
604
|
+
test: (report) => (value, expectedType) => {
|
|
605
|
+
const actualType = getType(value);
|
|
606
|
+
if (actualType !== expectedType) return report({
|
|
607
|
+
status: "notok",
|
|
608
|
+
messageId: "wrongType",
|
|
609
|
+
actual: actualType,
|
|
610
|
+
expected: expectedType,
|
|
611
|
+
noStringify: true
|
|
612
|
+
});
|
|
613
|
+
return report({
|
|
614
|
+
status: "ok",
|
|
615
|
+
messageId: "not",
|
|
616
|
+
actual: actualType,
|
|
617
|
+
expected: expectedType,
|
|
618
|
+
noStringify: true
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
//#endregion
|
|
624
|
+
//#region src/assert/less-than.ts
|
|
625
|
+
const [lessThan, notLessThan] = (0, hein_assertion_utils.createAssertion)({
|
|
626
|
+
messages: {
|
|
627
|
+
lesserThan: "Expected {{= it.actual }} to be less than {{= it.expected }}",
|
|
628
|
+
not: "Expected {{= it.actual }} to not be less than {{= it.expected }}"
|
|
629
|
+
},
|
|
630
|
+
test: (report) => (actual, expected, message) => {
|
|
631
|
+
validateNumericsAndDates(actual, expected);
|
|
632
|
+
if (actual >= expected) return report({
|
|
633
|
+
status: "notok",
|
|
634
|
+
messageId: "lesserThan",
|
|
635
|
+
actual,
|
|
636
|
+
expected,
|
|
637
|
+
message
|
|
638
|
+
});
|
|
639
|
+
return report({
|
|
640
|
+
status: "ok",
|
|
641
|
+
actual,
|
|
642
|
+
expected,
|
|
643
|
+
message,
|
|
644
|
+
messageId: "not"
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
//#endregion
|
|
650
|
+
//#region src/assert/less-than-equal.ts
|
|
651
|
+
const [lessThanEqual, notLessThanEqual] = (0, hein_assertion_utils.createAssertion)({
|
|
652
|
+
messages: {
|
|
653
|
+
lesserThanEqual: "Expected {{= it.actual }} to be less than or equal to {{= it.expected }}",
|
|
654
|
+
not: "Expected {{= it.actual }} to not be less than or equal to {{= it.expected }}"
|
|
655
|
+
},
|
|
656
|
+
test: (report) => (actual, expected, message) => {
|
|
657
|
+
validateNumericsAndDates(actual, expected);
|
|
658
|
+
if (actual > expected) return report({
|
|
659
|
+
status: "notok",
|
|
660
|
+
messageId: "lesserThanEqual",
|
|
661
|
+
actual,
|
|
662
|
+
expected,
|
|
663
|
+
message,
|
|
664
|
+
noStringify: true
|
|
665
|
+
});
|
|
666
|
+
return report({
|
|
667
|
+
status: "ok",
|
|
668
|
+
actual,
|
|
669
|
+
expected,
|
|
670
|
+
message,
|
|
671
|
+
messageId: "not",
|
|
672
|
+
noStringify: true
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
//#endregion
|
|
678
|
+
//#region src/assert/match.ts
|
|
679
|
+
const [match, notMatch] = (0, hein_assertion_utils.createAssertion)({
|
|
680
|
+
messages: {
|
|
681
|
+
noMatch: "Expected {{= it.actual }} to match {{= it.expected }}",
|
|
682
|
+
not: "Expected {{= it.actual }} to not match {{= it.expected }}"
|
|
683
|
+
},
|
|
684
|
+
test: (report) => (actual, regex) => {
|
|
685
|
+
if (!regex.test(actual)) return report({
|
|
686
|
+
messageId: "noMatch",
|
|
687
|
+
status: "notok",
|
|
688
|
+
actual,
|
|
689
|
+
noStringify: true,
|
|
690
|
+
expected: regex.toString()
|
|
691
|
+
});
|
|
692
|
+
report({
|
|
693
|
+
status: "ok",
|
|
694
|
+
actual,
|
|
695
|
+
expected: regex.toString(),
|
|
696
|
+
noStringify: true
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region src/utils/process-error.ts
|
|
703
|
+
const isConstructor = (value) => {
|
|
704
|
+
return typeof value === "function" && value.prototype && value.prototype.isPrototypeOf;
|
|
705
|
+
};
|
|
706
|
+
const processError = (report, error, narrowerOrMessage, message) => {
|
|
707
|
+
message = (typeof narrowerOrMessage === "string" ? narrowerOrMessage : message) ?? null;
|
|
708
|
+
if (!(error instanceof Error)) return report({
|
|
709
|
+
noStringify: true,
|
|
710
|
+
status: "notok",
|
|
711
|
+
messageId: "nonError",
|
|
712
|
+
actual: typeof error,
|
|
713
|
+
expected: "Error"
|
|
714
|
+
});
|
|
715
|
+
if (narrowerOrMessage) {
|
|
716
|
+
if (isConstructor(narrowerOrMessage)) {
|
|
717
|
+
if (!(error instanceof narrowerOrMessage)) return report({
|
|
718
|
+
noStringify: true,
|
|
719
|
+
status: "notok",
|
|
720
|
+
messageId: "invalidConstructor",
|
|
721
|
+
actual: error.name,
|
|
722
|
+
expected: narrowerOrMessage.name,
|
|
723
|
+
message
|
|
724
|
+
});
|
|
725
|
+
return report({
|
|
726
|
+
noStringify: true,
|
|
727
|
+
status: "ok",
|
|
728
|
+
messageId: "notConstructor",
|
|
729
|
+
actual: error.name,
|
|
730
|
+
expected: narrowerOrMessage.name,
|
|
731
|
+
message
|
|
732
|
+
});
|
|
733
|
+
} else if (typeof narrowerOrMessage === "function") {
|
|
734
|
+
if (!narrowerOrMessage(error)) return report({
|
|
735
|
+
noStringify: true,
|
|
736
|
+
status: "notok",
|
|
737
|
+
messageId: "predicate",
|
|
738
|
+
actual: error,
|
|
739
|
+
expected: null,
|
|
740
|
+
message
|
|
741
|
+
});
|
|
742
|
+
return report({
|
|
743
|
+
noStringify: true,
|
|
744
|
+
status: "ok",
|
|
745
|
+
messageId: "notPredicate",
|
|
746
|
+
actual: error,
|
|
747
|
+
expected: null,
|
|
748
|
+
message
|
|
749
|
+
});
|
|
750
|
+
} else if (typeof narrowerOrMessage === "string") return report({
|
|
751
|
+
noStringify: true,
|
|
752
|
+
status: "ok",
|
|
753
|
+
messageId: "throws",
|
|
754
|
+
actual: error,
|
|
755
|
+
message: narrowerOrMessage
|
|
756
|
+
});
|
|
757
|
+
else if (narrowerOrMessage instanceof RegExp) {
|
|
758
|
+
if (!narrowerOrMessage.test(error.message)) return report({
|
|
759
|
+
noStringify: true,
|
|
760
|
+
status: "notok",
|
|
761
|
+
messageId: "regex",
|
|
762
|
+
actual: error.message,
|
|
763
|
+
expected: narrowerOrMessage.toString(),
|
|
764
|
+
message
|
|
765
|
+
});
|
|
766
|
+
return report({
|
|
767
|
+
noStringify: true,
|
|
768
|
+
status: "ok",
|
|
769
|
+
messageId: "notRegex",
|
|
770
|
+
actual: error.message,
|
|
771
|
+
expected: narrowerOrMessage.toString(),
|
|
772
|
+
message
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
return report({
|
|
777
|
+
noStringify: true,
|
|
778
|
+
status: "ok",
|
|
779
|
+
actual: error,
|
|
780
|
+
message
|
|
781
|
+
});
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
//#endregion
|
|
785
|
+
//#region src/assert/rejects.ts
|
|
786
|
+
const [rejects, notRejects] = (0, hein_assertion_utils.createAssertion)({
|
|
787
|
+
messages: {
|
|
788
|
+
invalidArgument: "Expected {{= it.actual }} to be a Promise",
|
|
789
|
+
nonError: "Expected Promise to reject with an instance of Error",
|
|
790
|
+
throws: "Expected Promise to reject",
|
|
791
|
+
invalidConstructor: "Expected Promise to reject with {{= it.expected }}",
|
|
792
|
+
predicate: "Expected {{= it.actual }} to match predicate function",
|
|
793
|
+
regex: "Expected Promise to reject with an error matching {{= it.expected }}",
|
|
794
|
+
not: "Expected Promise to not reject",
|
|
795
|
+
notConstructor: "Expected Promise to not reject with a {{= it.expected }}",
|
|
796
|
+
notPredicate: "Expected {{= it.actual }} to not match predicate function",
|
|
797
|
+
notRegex: "Expected Promise to not reject with an error matching {{= it.expected }}"
|
|
798
|
+
},
|
|
799
|
+
test: (report) => async (promise, narrowerOrMessage, message) => {
|
|
800
|
+
if (!promise || typeof promise.then !== "function") {
|
|
801
|
+
report({
|
|
802
|
+
noStringify: true,
|
|
803
|
+
status: "notok",
|
|
804
|
+
messageId: "invalidArgument",
|
|
805
|
+
actual: typeof promise,
|
|
806
|
+
expected: "Promise"
|
|
807
|
+
});
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
try {
|
|
811
|
+
await promise;
|
|
812
|
+
} catch (error) {
|
|
813
|
+
processError(report, error, narrowerOrMessage, message);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
report({
|
|
817
|
+
noStringify: true,
|
|
818
|
+
status: "notok",
|
|
819
|
+
messageId: "throws",
|
|
820
|
+
message: typeof narrowerOrMessage === "string" ? narrowerOrMessage : message
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
//#endregion
|
|
826
|
+
//#region src/assert/throws.ts
|
|
827
|
+
const messages = {
|
|
828
|
+
nonError: "Expected function to throw an instance of Error",
|
|
829
|
+
throws: "Expected function to throw",
|
|
830
|
+
invalidConstructor: "Expected function to throw {{= it.expected }}",
|
|
831
|
+
predicate: "Expected {{= it.actual }} to match predicate function",
|
|
832
|
+
regex: "Expected function to throw an error matching {{= it.expected }}",
|
|
833
|
+
not: "Expected function to not throw",
|
|
834
|
+
notConstructor: "Expected function to not throw a {{= it.expected }}",
|
|
835
|
+
notPredicate: "Expected function to not throw an error matching the predicate",
|
|
836
|
+
notRegex: "Expected function to not throw an error matching {{= it.expected }}"
|
|
837
|
+
};
|
|
838
|
+
const [throws, notThrows] = (0, hein_assertion_utils.createAssertion)({
|
|
839
|
+
messages,
|
|
840
|
+
test: (report) => ((callback, narrowerOrMessage, message) => {
|
|
841
|
+
const argumentType = getType(callback);
|
|
842
|
+
if (argumentType !== "function") throw new hein_assertion_utils.AssertionError(argumentType, "function", `Expected ${argumentType} to be a function`);
|
|
843
|
+
try {
|
|
844
|
+
callback();
|
|
845
|
+
} catch (error) {
|
|
846
|
+
return processError(report, error, narrowerOrMessage, message);
|
|
847
|
+
}
|
|
848
|
+
return report({
|
|
849
|
+
noStringify: true,
|
|
850
|
+
status: "notok",
|
|
851
|
+
messageId: "throws",
|
|
852
|
+
message: typeof narrowerOrMessage === "string" ? narrowerOrMessage : message
|
|
853
|
+
});
|
|
854
|
+
})
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region src/assert/deep-has-property.ts
|
|
859
|
+
const [deepHasProperty, deepNotHasProperty] = (0, hein_assertion_utils.createAssertion)({
|
|
860
|
+
messages: {
|
|
861
|
+
noProperty: "Expected {{= it.actual }} to have property {{= it.expected }}",
|
|
862
|
+
wrongValue: "Expected {{= it.obj }} to have property {{= it.expected }} with value {{= it.value }}",
|
|
863
|
+
not: "Expected {{= it.actual }} to not have property {{= it.expected }}",
|
|
864
|
+
notWrongValue: "Expected {{= it.obj }} to not have property {{= it.expected }} with value {{= it.value }}"
|
|
865
|
+
},
|
|
866
|
+
test: (report) => (...args) => {
|
|
867
|
+
const [actual, expected, value] = args;
|
|
868
|
+
const actualStringified = (0, hein_assertion_utils.stringify)(actual);
|
|
869
|
+
if ((0, lodash_has_js.default)(actual, expected)) {
|
|
870
|
+
if (args.length === 3) {
|
|
871
|
+
const actualValue = (0, lodash_get_js.default)(actual, expected);
|
|
872
|
+
if (actualValue === value) return report({
|
|
873
|
+
status: "ok",
|
|
874
|
+
messageId: "notWrongValue",
|
|
875
|
+
expected: value,
|
|
876
|
+
actual: actualValue,
|
|
877
|
+
data: {
|
|
878
|
+
value,
|
|
879
|
+
expected,
|
|
880
|
+
obj: actualStringified
|
|
881
|
+
},
|
|
882
|
+
noStringify: true
|
|
883
|
+
});
|
|
884
|
+
return report({
|
|
885
|
+
status: "notok",
|
|
886
|
+
messageId: "wrongValue",
|
|
887
|
+
expected: value,
|
|
888
|
+
actual: actualValue,
|
|
889
|
+
data: {
|
|
890
|
+
value,
|
|
891
|
+
expected,
|
|
892
|
+
obj: actualStringified
|
|
893
|
+
},
|
|
894
|
+
noStringify: true
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
return report({
|
|
898
|
+
status: "ok",
|
|
899
|
+
noStringify: true,
|
|
900
|
+
expected,
|
|
901
|
+
actual: actualStringified
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
return report({
|
|
905
|
+
status: "notok",
|
|
906
|
+
messageId: "noProperty",
|
|
907
|
+
expected,
|
|
908
|
+
actual: actualStringified,
|
|
909
|
+
noStringify: true
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
//#endregion
|
|
915
|
+
//#region src/assert/starts-with.ts
|
|
916
|
+
const [startsWith, notStartsWith] = (0, hein_assertion_utils.createAssertion)({
|
|
917
|
+
messages: {
|
|
918
|
+
wrongStart: "Expected {{= it.actual }} to start with {{= it.expected }}",
|
|
919
|
+
not: "Expected {{= it.actual }} to not start with {{= it.expected }}"
|
|
920
|
+
},
|
|
921
|
+
test: (report) => (actual, start) => {
|
|
922
|
+
if (actual.startsWith(start)) report({
|
|
923
|
+
messageId: "not",
|
|
924
|
+
status: "ok",
|
|
925
|
+
actual,
|
|
926
|
+
expected: start
|
|
927
|
+
});
|
|
928
|
+
else report({
|
|
929
|
+
messageId: "wrongStart",
|
|
930
|
+
status: "notok",
|
|
931
|
+
actual,
|
|
932
|
+
expected: start
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region src/assert/ends-with.ts
|
|
939
|
+
const [endsWith, notEndsWith] = (0, hein_assertion_utils.createAssertion)({
|
|
940
|
+
messages: {
|
|
941
|
+
wrongEnd: "Expected {{= it.actual }} to end with {{= it.expected }}",
|
|
942
|
+
not: "Expected {{= it.actual }} to not end with {{= it.expected }}"
|
|
943
|
+
},
|
|
944
|
+
test: (report) => (actual, end) => {
|
|
945
|
+
if (actual.endsWith(end)) report({
|
|
946
|
+
messageId: "not",
|
|
947
|
+
status: "ok",
|
|
948
|
+
actual,
|
|
949
|
+
expected: end
|
|
950
|
+
});
|
|
951
|
+
else report({
|
|
952
|
+
messageId: "wrongEnd",
|
|
953
|
+
status: "notok",
|
|
954
|
+
actual,
|
|
955
|
+
expected: end
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
//#endregion
|
|
961
|
+
//#region src/assert/is-before.ts
|
|
962
|
+
const [isBefore, notBefore] = (0, hein_assertion_utils.createAssertion)({
|
|
963
|
+
messages: {
|
|
964
|
+
after: "Expected {{= it.actual }} to be before {{= it.expected }}",
|
|
965
|
+
not: "Expected {{= it.actual }} to not be before {{= it.expected }}"
|
|
966
|
+
},
|
|
967
|
+
test: (report) => (actual, expected) => {
|
|
968
|
+
if (actual >= expected) return report({
|
|
969
|
+
messageId: "after",
|
|
970
|
+
status: "notok",
|
|
971
|
+
actual,
|
|
972
|
+
expected
|
|
973
|
+
});
|
|
974
|
+
return report({
|
|
975
|
+
status: "ok",
|
|
976
|
+
actual,
|
|
977
|
+
expected
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
|
|
982
|
+
//#endregion
|
|
983
|
+
//#region src/assert/is-after.ts
|
|
984
|
+
const [isAfter, notAfter] = (0, hein_assertion_utils.createAssertion)({
|
|
985
|
+
messages: {
|
|
986
|
+
before: "Expected {{= it.actual }} to be after {{= it.expected }}",
|
|
987
|
+
not: "Expected {{= it.actual }} to not be after {{= it.expected }}"
|
|
988
|
+
},
|
|
989
|
+
test: (report) => (actual, expected) => {
|
|
990
|
+
if (actual <= expected) return report({
|
|
991
|
+
messageId: "before",
|
|
992
|
+
status: "notok",
|
|
993
|
+
actual,
|
|
994
|
+
expected
|
|
995
|
+
});
|
|
996
|
+
return report({
|
|
997
|
+
status: "ok",
|
|
998
|
+
actual,
|
|
999
|
+
expected
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
//#endregion
|
|
1005
|
+
//#region src/assert/is-between.ts
|
|
1006
|
+
const [isBetween, notBetween] = (0, hein_assertion_utils.createAssertion)({
|
|
1007
|
+
messages: {
|
|
1008
|
+
notBetween: "Expected {{= it.actual }} to be between {{= it.lesser }} and {{= it.greater }}",
|
|
1009
|
+
not: "Expected {{= it.actual }} to not be between {{= it.lesser }} and {{= it.greater }}"
|
|
1010
|
+
},
|
|
1011
|
+
test: (report) => (actual, start, end, { inclusive = true } = {}) => {
|
|
1012
|
+
const [greater, lesser] = end > start ? [end, start] : [start, end];
|
|
1013
|
+
const inclusivelyBetween = actual <= greater && actual >= lesser;
|
|
1014
|
+
const exclusivelyBetween = actual < greater && actual > lesser;
|
|
1015
|
+
if (inclusive && !inclusivelyBetween) return report({
|
|
1016
|
+
messageId: "notBetween",
|
|
1017
|
+
status: "notok",
|
|
1018
|
+
actual,
|
|
1019
|
+
data: {
|
|
1020
|
+
lesser,
|
|
1021
|
+
greater
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
if (!inclusive && !exclusivelyBetween) return report({
|
|
1025
|
+
messageId: "notBetween",
|
|
1026
|
+
status: "notok",
|
|
1027
|
+
actual,
|
|
1028
|
+
data: {
|
|
1029
|
+
lesser,
|
|
1030
|
+
greater
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
return report({
|
|
1034
|
+
status: "ok",
|
|
1035
|
+
actual,
|
|
1036
|
+
data: {
|
|
1037
|
+
lesser,
|
|
1038
|
+
greater
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
//#endregion
|
|
1045
|
+
//#region src/assert/in-ballpark.ts
|
|
1046
|
+
const [inBallpark, notInBallpark] = (0, hein_assertion_utils.createAssertion)({
|
|
1047
|
+
messages: {
|
|
1048
|
+
miss: "Expected {{= it.actual }} to be in ballpark of {{= it.expected }}",
|
|
1049
|
+
not: "Expected {{= it.actual }} to not be in ballpark of {{= it.expected }}",
|
|
1050
|
+
invalidMultiplier: "Expected multiplier to be between 0 and 1"
|
|
1051
|
+
},
|
|
1052
|
+
test: (report) => (actual, expected, allowedDifference = .1) => {
|
|
1053
|
+
const absActual = Math.abs(actual);
|
|
1054
|
+
const absExpected = Math.abs(expected);
|
|
1055
|
+
if (allowedDifference <= 0 || allowedDifference >= 1) {
|
|
1056
|
+
report({
|
|
1057
|
+
status: "ok",
|
|
1058
|
+
messageId: "invalidMultiplier",
|
|
1059
|
+
actual: allowedDifference
|
|
1060
|
+
});
|
|
1061
|
+
return report({
|
|
1062
|
+
status: "notok",
|
|
1063
|
+
messageId: "invalidMultiplier",
|
|
1064
|
+
actual: allowedDifference
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
if (absActual <= absExpected * (1 + allowedDifference) && absActual >= absExpected * (1 - allowedDifference)) return report({
|
|
1068
|
+
status: "ok",
|
|
1069
|
+
expected,
|
|
1070
|
+
actual
|
|
1071
|
+
});
|
|
1072
|
+
return report({
|
|
1073
|
+
status: "notok",
|
|
1074
|
+
messageId: "miss",
|
|
1075
|
+
expected,
|
|
1076
|
+
actual
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
//#endregion
|
|
1082
|
+
//#region src/assert/round-to.ts
|
|
1083
|
+
const [roundTo, notRoundTo] = (0, hein_assertion_utils.createAssertion)({
|
|
1084
|
+
messages: {
|
|
1085
|
+
miss: "Expected {{= it.actual }} to round to {{= it.expected }}",
|
|
1086
|
+
tooManyDecimals: "Invalid argument for target, decimals for target ({{= it.expected }}) cannot be less than rounding decimals ({{= it.decimals }})",
|
|
1087
|
+
not: "Expected {{= it.actual }} to not round to {{= it.expected }}"
|
|
1088
|
+
},
|
|
1089
|
+
test: (report) => (actual, expected, decimals = 0) => {
|
|
1090
|
+
var _expected$toString$sp;
|
|
1091
|
+
if (((_expected$toString$sp = expected.toString().split(".")[1]) === null || _expected$toString$sp === void 0 ? void 0 : _expected$toString$sp.length) > decimals) {
|
|
1092
|
+
report({
|
|
1093
|
+
status: "notok",
|
|
1094
|
+
messageId: "tooManyDecimals",
|
|
1095
|
+
expected,
|
|
1096
|
+
actual,
|
|
1097
|
+
data: { decimals },
|
|
1098
|
+
noStringify: true
|
|
1099
|
+
});
|
|
1100
|
+
report({
|
|
1101
|
+
status: "ok",
|
|
1102
|
+
messageId: "tooManyDecimals",
|
|
1103
|
+
expected,
|
|
1104
|
+
actual,
|
|
1105
|
+
data: { decimals },
|
|
1106
|
+
noStringify: true
|
|
1107
|
+
});
|
|
1108
|
+
return true;
|
|
1109
|
+
}
|
|
1110
|
+
if (round(actual, decimals) === expected) return report({
|
|
1111
|
+
status: "ok",
|
|
1112
|
+
expected,
|
|
1113
|
+
actual
|
|
1114
|
+
});
|
|
1115
|
+
return report({
|
|
1116
|
+
status: "notok",
|
|
1117
|
+
messageId: "miss",
|
|
1118
|
+
expected,
|
|
1119
|
+
actual
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1123
|
+
const round = (value, decimals) => {
|
|
1124
|
+
const factor = 10 ** decimals;
|
|
1125
|
+
return Math.round(value * factor) / factor;
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
//#endregion
|
|
1129
|
+
//#region src/assert/has-members.ts
|
|
1130
|
+
const [hasMembers, notHasMembers] = (0, hein_assertion_utils.createAssertion)({
|
|
1131
|
+
messages: {
|
|
1132
|
+
hasMembers: "Expected {{= it.actual }} to have members {{= it.expected }}",
|
|
1133
|
+
same: "Expected {{= it.actual }} to have same members as {{= it.expected }}",
|
|
1134
|
+
order: "Expected {{= it.actual }} to have ordered members {{= it.expected }}",
|
|
1135
|
+
not: "Expected {{= it.actual }} to not have members {{= it.expected }}",
|
|
1136
|
+
notSame: "Expected {{= it.actual }} to not have same members as {{= it.expected }}"
|
|
1137
|
+
},
|
|
1138
|
+
test: (report) => (actual, expected, { deep = false, partial = false, ordered = false, same = false } = {}, message) => {
|
|
1139
|
+
let lastIndex = -1;
|
|
1140
|
+
for (const item of expected) if (deep || partial) {
|
|
1141
|
+
const actualIndex = actual.findIndex((actualItem, index) => {
|
|
1142
|
+
if (!ordered) return match$1(actualItem, item, { partial });
|
|
1143
|
+
if (lastIndex >= index) return false;
|
|
1144
|
+
return match$1(actualItem, item, { partial });
|
|
1145
|
+
});
|
|
1146
|
+
lastIndex = actualIndex;
|
|
1147
|
+
if (actualIndex === -1) return report({
|
|
1148
|
+
status: "notok",
|
|
1149
|
+
messageId: ordered ? "order" : "hasMembers",
|
|
1150
|
+
actual,
|
|
1151
|
+
expected,
|
|
1152
|
+
message
|
|
1153
|
+
});
|
|
1154
|
+
} else if (actual.includes(item)) {
|
|
1155
|
+
if (ordered && lastIndex >= actual.indexOf(item, lastIndex + 1)) return report({
|
|
1156
|
+
status: "notok",
|
|
1157
|
+
messageId: "order",
|
|
1158
|
+
actual,
|
|
1159
|
+
expected,
|
|
1160
|
+
message
|
|
1161
|
+
});
|
|
1162
|
+
lastIndex = actual.indexOf(item, lastIndex + 1);
|
|
1163
|
+
} else return report({
|
|
1164
|
+
status: "notok",
|
|
1165
|
+
messageId: "hasMembers",
|
|
1166
|
+
actual,
|
|
1167
|
+
expected,
|
|
1168
|
+
message
|
|
1169
|
+
});
|
|
1170
|
+
if (same && actual.length !== expected.length) return report({
|
|
1171
|
+
status: "notok",
|
|
1172
|
+
messageId: "same",
|
|
1173
|
+
actual,
|
|
1174
|
+
expected,
|
|
1175
|
+
message
|
|
1176
|
+
});
|
|
1177
|
+
return report({
|
|
1178
|
+
status: "ok",
|
|
1179
|
+
messageId: same ? "notSame" : "not",
|
|
1180
|
+
actual,
|
|
1181
|
+
expected,
|
|
1182
|
+
message
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
//#endregion
|
|
1188
|
+
//#region src/assert/has-keys.ts
|
|
1189
|
+
const [hasKeys, notHasKeys] = (0, hein_assertion_utils.createAssertion)({
|
|
1190
|
+
messages: {
|
|
1191
|
+
noKey: "Expected {{= it.object }} to have keys {{= it.expected }}",
|
|
1192
|
+
not: "Expected {{= it.object }} to not have keys {{= it.expected }}"
|
|
1193
|
+
},
|
|
1194
|
+
test: (report) => (object, keys, message) => {
|
|
1195
|
+
const keysArray = (0, lodash_castArray_js.default)(keys);
|
|
1196
|
+
if (object instanceof Map) {
|
|
1197
|
+
for (const key of keysArray) if (!object.has(key)) {
|
|
1198
|
+
report({
|
|
1199
|
+
status: "notok",
|
|
1200
|
+
message,
|
|
1201
|
+
messageId: "noKey",
|
|
1202
|
+
data: { object },
|
|
1203
|
+
actual: [...object.keys()],
|
|
1204
|
+
expected: keysArray
|
|
1205
|
+
});
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
report({
|
|
1209
|
+
status: "ok",
|
|
1210
|
+
data: { object },
|
|
1211
|
+
actual: [...object.keys()],
|
|
1212
|
+
expected: keysArray
|
|
1213
|
+
});
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
for (const key of keysArray) if (!(key in object)) {
|
|
1217
|
+
report({
|
|
1218
|
+
status: "notok",
|
|
1219
|
+
message,
|
|
1220
|
+
messageId: "noKey",
|
|
1221
|
+
data: { object },
|
|
1222
|
+
actual: object,
|
|
1223
|
+
expected: keysArray
|
|
1224
|
+
});
|
|
1225
|
+
return;
|
|
1226
|
+
}
|
|
1227
|
+
report({
|
|
1228
|
+
status: "ok",
|
|
1229
|
+
data: { object },
|
|
1230
|
+
actual: Object.keys(object),
|
|
1231
|
+
expected: keysArray
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
//#endregion
|
|
1237
|
+
//#region src/assert.ts
|
|
1238
|
+
var assert_exports = /* @__PURE__ */ __export({
|
|
1239
|
+
assert: () => assert,
|
|
1240
|
+
deepEqual: () => deepEqual,
|
|
1241
|
+
deepHasProperty: () => deepHasProperty,
|
|
1242
|
+
deepNotHasProperty: () => deepNotHasProperty,
|
|
1243
|
+
endsWith: () => endsWith,
|
|
1244
|
+
equal: () => equal,
|
|
1245
|
+
greaterThan: () => greaterThan,
|
|
1246
|
+
greaterThanEqual: () => greaterThanEqual,
|
|
1247
|
+
hasKeys: () => hasKeys,
|
|
1248
|
+
hasMembers: () => hasMembers,
|
|
1249
|
+
hasProperty: () => hasProperty,
|
|
1250
|
+
hasSize: () => hasSize,
|
|
1251
|
+
inBallpark: () => inBallpark,
|
|
1252
|
+
includes: () => includes,
|
|
1253
|
+
instanceOf: () => instanceOf,
|
|
1254
|
+
isAfter: () => isAfter,
|
|
1255
|
+
isBefore: () => isBefore,
|
|
1256
|
+
isBetween: () => isBetween,
|
|
1257
|
+
isEmpty: () => isEmpty,
|
|
1258
|
+
isType: () => isType,
|
|
1259
|
+
lessThan: () => lessThan,
|
|
1260
|
+
lessThanEqual: () => lessThanEqual,
|
|
1261
|
+
match: () => match,
|
|
1262
|
+
notAfter: () => notAfter,
|
|
1263
|
+
notBefore: () => notBefore,
|
|
1264
|
+
notBetween: () => notBetween,
|
|
1265
|
+
notDeepEqual: () => notDeepEqual,
|
|
1266
|
+
notEndsWith: () => notEndsWith,
|
|
1267
|
+
notEqual: () => notEqual,
|
|
1268
|
+
notGreaterThan: () => notGreaterThan,
|
|
1269
|
+
notGreaterThanEqual: () => notGreaterThanEqual,
|
|
1270
|
+
notHasKeys: () => notHasKeys,
|
|
1271
|
+
notHasMembers: () => notHasMembers,
|
|
1272
|
+
notHasProperty: () => notHasProperty,
|
|
1273
|
+
notHasSize: () => notHasSize,
|
|
1274
|
+
notInBallpark: () => notInBallpark,
|
|
1275
|
+
notIncludes: () => notIncludes,
|
|
1276
|
+
notInstanceOf: () => notInstanceOf,
|
|
1277
|
+
notIsEmpty: () => notIsEmpty,
|
|
1278
|
+
notIsType: () => notIsType,
|
|
1279
|
+
notLessThan: () => notLessThan,
|
|
1280
|
+
notLessThanEqual: () => notLessThanEqual,
|
|
1281
|
+
notMatch: () => notMatch,
|
|
1282
|
+
notRejects: () => notRejects,
|
|
1283
|
+
notRoundTo: () => notRoundTo,
|
|
1284
|
+
notStartsWith: () => notStartsWith,
|
|
1285
|
+
notThrows: () => notThrows,
|
|
1286
|
+
rejects: () => rejects,
|
|
1287
|
+
roundTo: () => roundTo,
|
|
1288
|
+
startsWith: () => startsWith,
|
|
1289
|
+
throws: () => throws
|
|
1290
|
+
});
|
|
1291
|
+
const assert = () => {
|
|
1292
|
+
throw new Error("Not implemented");
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
//#endregion
|
|
1296
|
+
Object.defineProperty(exports, '__toESM', {
|
|
1297
|
+
enumerable: true,
|
|
1298
|
+
get: function () {
|
|
1299
|
+
return __toESM;
|
|
1300
|
+
}
|
|
1301
|
+
});
|
|
1302
|
+
Object.defineProperty(exports, 'any', {
|
|
1303
|
+
enumerable: true,
|
|
1304
|
+
get: function () {
|
|
1305
|
+
return any;
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
Object.defineProperty(exports, 'assert', {
|
|
1309
|
+
enumerable: true,
|
|
1310
|
+
get: function () {
|
|
1311
|
+
return assert;
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
Object.defineProperty(exports, 'assert_exports', {
|
|
1315
|
+
enumerable: true,
|
|
1316
|
+
get: function () {
|
|
1317
|
+
return assert_exports;
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
Object.defineProperty(exports, 'createEvaluation', {
|
|
1321
|
+
enumerable: true,
|
|
1322
|
+
get: function () {
|
|
1323
|
+
return createEvaluation;
|
|
1324
|
+
}
|
|
1325
|
+
});
|
|
1326
|
+
Object.defineProperty(exports, 'deepEqual', {
|
|
1327
|
+
enumerable: true,
|
|
1328
|
+
get: function () {
|
|
1329
|
+
return deepEqual;
|
|
1330
|
+
}
|
|
1331
|
+
});
|
|
1332
|
+
Object.defineProperty(exports, 'deepHasProperty', {
|
|
1333
|
+
enumerable: true,
|
|
1334
|
+
get: function () {
|
|
1335
|
+
return deepHasProperty;
|
|
1336
|
+
}
|
|
1337
|
+
});
|
|
1338
|
+
Object.defineProperty(exports, 'deepNotHasProperty', {
|
|
1339
|
+
enumerable: true,
|
|
1340
|
+
get: function () {
|
|
1341
|
+
return deepNotHasProperty;
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1344
|
+
Object.defineProperty(exports, 'endsWith', {
|
|
1345
|
+
enumerable: true,
|
|
1346
|
+
get: function () {
|
|
1347
|
+
return endsWith;
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
Object.defineProperty(exports, 'equal', {
|
|
1351
|
+
enumerable: true,
|
|
1352
|
+
get: function () {
|
|
1353
|
+
return equal;
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
Object.defineProperty(exports, 'greaterThan', {
|
|
1357
|
+
enumerable: true,
|
|
1358
|
+
get: function () {
|
|
1359
|
+
return greaterThan;
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
Object.defineProperty(exports, 'greaterThanEqual', {
|
|
1363
|
+
enumerable: true,
|
|
1364
|
+
get: function () {
|
|
1365
|
+
return greaterThanEqual;
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
Object.defineProperty(exports, 'hasKeys', {
|
|
1369
|
+
enumerable: true,
|
|
1370
|
+
get: function () {
|
|
1371
|
+
return hasKeys;
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
Object.defineProperty(exports, 'hasMembers', {
|
|
1375
|
+
enumerable: true,
|
|
1376
|
+
get: function () {
|
|
1377
|
+
return hasMembers;
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
Object.defineProperty(exports, 'hasProperty', {
|
|
1381
|
+
enumerable: true,
|
|
1382
|
+
get: function () {
|
|
1383
|
+
return hasProperty;
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
Object.defineProperty(exports, 'hasSize', {
|
|
1387
|
+
enumerable: true,
|
|
1388
|
+
get: function () {
|
|
1389
|
+
return hasSize;
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
Object.defineProperty(exports, 'inBallpark', {
|
|
1393
|
+
enumerable: true,
|
|
1394
|
+
get: function () {
|
|
1395
|
+
return inBallpark;
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
Object.defineProperty(exports, 'includes', {
|
|
1399
|
+
enumerable: true,
|
|
1400
|
+
get: function () {
|
|
1401
|
+
return includes;
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
Object.defineProperty(exports, 'instanceOf', {
|
|
1405
|
+
enumerable: true,
|
|
1406
|
+
get: function () {
|
|
1407
|
+
return instanceOf;
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
Object.defineProperty(exports, 'isAfter', {
|
|
1411
|
+
enumerable: true,
|
|
1412
|
+
get: function () {
|
|
1413
|
+
return isAfter;
|
|
1414
|
+
}
|
|
1415
|
+
});
|
|
1416
|
+
Object.defineProperty(exports, 'isBefore', {
|
|
1417
|
+
enumerable: true,
|
|
1418
|
+
get: function () {
|
|
1419
|
+
return isBefore;
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
Object.defineProperty(exports, 'isBetween', {
|
|
1423
|
+
enumerable: true,
|
|
1424
|
+
get: function () {
|
|
1425
|
+
return isBetween;
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
Object.defineProperty(exports, 'isEmpty', {
|
|
1429
|
+
enumerable: true,
|
|
1430
|
+
get: function () {
|
|
1431
|
+
return isEmpty;
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
Object.defineProperty(exports, 'isType', {
|
|
1435
|
+
enumerable: true,
|
|
1436
|
+
get: function () {
|
|
1437
|
+
return isType;
|
|
1438
|
+
}
|
|
1439
|
+
});
|
|
1440
|
+
Object.defineProperty(exports, 'lessThan', {
|
|
1441
|
+
enumerable: true,
|
|
1442
|
+
get: function () {
|
|
1443
|
+
return lessThan;
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1446
|
+
Object.defineProperty(exports, 'lessThanEqual', {
|
|
1447
|
+
enumerable: true,
|
|
1448
|
+
get: function () {
|
|
1449
|
+
return lessThanEqual;
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1452
|
+
Object.defineProperty(exports, 'match', {
|
|
1453
|
+
enumerable: true,
|
|
1454
|
+
get: function () {
|
|
1455
|
+
return match;
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
Object.defineProperty(exports, 'notAfter', {
|
|
1459
|
+
enumerable: true,
|
|
1460
|
+
get: function () {
|
|
1461
|
+
return notAfter;
|
|
1462
|
+
}
|
|
1463
|
+
});
|
|
1464
|
+
Object.defineProperty(exports, 'notBefore', {
|
|
1465
|
+
enumerable: true,
|
|
1466
|
+
get: function () {
|
|
1467
|
+
return notBefore;
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
Object.defineProperty(exports, 'notBetween', {
|
|
1471
|
+
enumerable: true,
|
|
1472
|
+
get: function () {
|
|
1473
|
+
return notBetween;
|
|
1474
|
+
}
|
|
1475
|
+
});
|
|
1476
|
+
Object.defineProperty(exports, 'notDeepEqual', {
|
|
1477
|
+
enumerable: true,
|
|
1478
|
+
get: function () {
|
|
1479
|
+
return notDeepEqual;
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
Object.defineProperty(exports, 'notEndsWith', {
|
|
1483
|
+
enumerable: true,
|
|
1484
|
+
get: function () {
|
|
1485
|
+
return notEndsWith;
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
Object.defineProperty(exports, 'notEqual', {
|
|
1489
|
+
enumerable: true,
|
|
1490
|
+
get: function () {
|
|
1491
|
+
return notEqual;
|
|
1492
|
+
}
|
|
1493
|
+
});
|
|
1494
|
+
Object.defineProperty(exports, 'notGreaterThan', {
|
|
1495
|
+
enumerable: true,
|
|
1496
|
+
get: function () {
|
|
1497
|
+
return notGreaterThan;
|
|
1498
|
+
}
|
|
1499
|
+
});
|
|
1500
|
+
Object.defineProperty(exports, 'notGreaterThanEqual', {
|
|
1501
|
+
enumerable: true,
|
|
1502
|
+
get: function () {
|
|
1503
|
+
return notGreaterThanEqual;
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
Object.defineProperty(exports, 'notHasKeys', {
|
|
1507
|
+
enumerable: true,
|
|
1508
|
+
get: function () {
|
|
1509
|
+
return notHasKeys;
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
Object.defineProperty(exports, 'notHasMembers', {
|
|
1513
|
+
enumerable: true,
|
|
1514
|
+
get: function () {
|
|
1515
|
+
return notHasMembers;
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
Object.defineProperty(exports, 'notHasProperty', {
|
|
1519
|
+
enumerable: true,
|
|
1520
|
+
get: function () {
|
|
1521
|
+
return notHasProperty;
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
Object.defineProperty(exports, 'notHasSize', {
|
|
1525
|
+
enumerable: true,
|
|
1526
|
+
get: function () {
|
|
1527
|
+
return notHasSize;
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
Object.defineProperty(exports, 'notInBallpark', {
|
|
1531
|
+
enumerable: true,
|
|
1532
|
+
get: function () {
|
|
1533
|
+
return notInBallpark;
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
Object.defineProperty(exports, 'notIncludes', {
|
|
1537
|
+
enumerable: true,
|
|
1538
|
+
get: function () {
|
|
1539
|
+
return notIncludes;
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1542
|
+
Object.defineProperty(exports, 'notInstanceOf', {
|
|
1543
|
+
enumerable: true,
|
|
1544
|
+
get: function () {
|
|
1545
|
+
return notInstanceOf;
|
|
1546
|
+
}
|
|
1547
|
+
});
|
|
1548
|
+
Object.defineProperty(exports, 'notIsEmpty', {
|
|
1549
|
+
enumerable: true,
|
|
1550
|
+
get: function () {
|
|
1551
|
+
return notIsEmpty;
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1554
|
+
Object.defineProperty(exports, 'notIsType', {
|
|
1555
|
+
enumerable: true,
|
|
1556
|
+
get: function () {
|
|
1557
|
+
return notIsType;
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
Object.defineProperty(exports, 'notLessThan', {
|
|
1561
|
+
enumerable: true,
|
|
1562
|
+
get: function () {
|
|
1563
|
+
return notLessThan;
|
|
1564
|
+
}
|
|
1565
|
+
});
|
|
1566
|
+
Object.defineProperty(exports, 'notLessThanEqual', {
|
|
1567
|
+
enumerable: true,
|
|
1568
|
+
get: function () {
|
|
1569
|
+
return notLessThanEqual;
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1572
|
+
Object.defineProperty(exports, 'notMatch', {
|
|
1573
|
+
enumerable: true,
|
|
1574
|
+
get: function () {
|
|
1575
|
+
return notMatch;
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
Object.defineProperty(exports, 'notRejects', {
|
|
1579
|
+
enumerable: true,
|
|
1580
|
+
get: function () {
|
|
1581
|
+
return notRejects;
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
Object.defineProperty(exports, 'notRoundTo', {
|
|
1585
|
+
enumerable: true,
|
|
1586
|
+
get: function () {
|
|
1587
|
+
return notRoundTo;
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
Object.defineProperty(exports, 'notStartsWith', {
|
|
1591
|
+
enumerable: true,
|
|
1592
|
+
get: function () {
|
|
1593
|
+
return notStartsWith;
|
|
1594
|
+
}
|
|
1595
|
+
});
|
|
1596
|
+
Object.defineProperty(exports, 'notThrows', {
|
|
1597
|
+
enumerable: true,
|
|
1598
|
+
get: function () {
|
|
1599
|
+
return notThrows;
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1602
|
+
Object.defineProperty(exports, 'rejects', {
|
|
1603
|
+
enumerable: true,
|
|
1604
|
+
get: function () {
|
|
1605
|
+
return rejects;
|
|
1606
|
+
}
|
|
1607
|
+
});
|
|
1608
|
+
Object.defineProperty(exports, 'roundTo', {
|
|
1609
|
+
enumerable: true,
|
|
1610
|
+
get: function () {
|
|
1611
|
+
return roundTo;
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
Object.defineProperty(exports, 'startsWith', {
|
|
1615
|
+
enumerable: true,
|
|
1616
|
+
get: function () {
|
|
1617
|
+
return startsWith;
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
Object.defineProperty(exports, 'throws', {
|
|
1621
|
+
enumerable: true,
|
|
1622
|
+
get: function () {
|
|
1623
|
+
return throws;
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
//# sourceMappingURL=assert-DZjgWjOw.cjs.map
|