ts-data-forge 6.8.0 → 6.9.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/dist/array/impl/array-utils-set-op.d.mts.map +1 -1
- package/dist/array/impl/array-utils-set-op.mjs +1 -3
- package/dist/array/impl/array-utils-set-op.mjs.map +1 -1
- package/dist/array/impl/array-utils-validation.d.mts.map +1 -1
- package/dist/array/impl/array-utils-validation.mjs +2 -6
- package/dist/array/impl/array-utils-validation.mjs.map +1 -1
- package/dist/object/object.d.mts +52 -0
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +103 -1
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/fast-deep-equal.d.mts.map +1 -1
- package/dist/others/fast-deep-equal.mjs +0 -1
- package/dist/others/fast-deep-equal.mjs.map +1 -1
- package/package.json +12 -12
- package/src/array/impl/array-utils-overload-type-error.test.mts +2 -4
- package/src/array/impl/array-utils-set-op.mts +0 -1
- package/src/array/impl/array-utils-validation.mts +2 -6
- package/src/functional/optional.test.mts +5 -7
- package/src/functional/result.test.mts +8 -10
- package/src/functional/ternary-result.test.mts +4 -4
- package/src/json/json.test.mts +5 -5
- package/src/number/branded-types/finite-number.test.mts +11 -15
- package/src/number/branded-types/int.test.mts +13 -13
- package/src/number/branded-types/int16.test.mts +15 -15
- package/src/number/branded-types/int32.test.mts +15 -15
- package/src/number/branded-types/non-negative-finite-number.test.mts +15 -19
- package/src/number/branded-types/non-negative-int16.test.mts +15 -15
- package/src/number/branded-types/non-negative-int32.test.mts +15 -15
- package/src/number/branded-types/non-zero-finite-number.test.mts +18 -18
- package/src/number/branded-types/non-zero-int.test.mts +14 -18
- package/src/number/branded-types/non-zero-int16.test.mts +15 -19
- package/src/number/branded-types/non-zero-int32.test.mts +15 -19
- package/src/number/branded-types/non-zero-safe-int.test.mts +18 -22
- package/src/number/branded-types/non-zero-uint16.test.mts +15 -15
- package/src/number/branded-types/non-zero-uint32.test.mts +15 -15
- package/src/number/branded-types/positive-finite-number.test.mts +18 -18
- package/src/number/branded-types/positive-int.test.mts +16 -22
- package/src/number/branded-types/positive-int16.test.mts +14 -14
- package/src/number/branded-types/positive-int32.test.mts +14 -14
- package/src/number/branded-types/positive-safe-int.test.mts +18 -20
- package/src/number/branded-types/positive-uint16.test.mts +15 -15
- package/src/number/branded-types/positive-uint32.test.mts +15 -15
- package/src/number/branded-types/safe-int.test.mts +17 -21
- package/src/number/branded-types/safe-uint.test.mts +16 -22
- package/src/number/branded-types/uint.test.mts +14 -14
- package/src/number/branded-types/uint16.test.mts +14 -14
- package/src/number/branded-types/uint32.test.mts +14 -14
- package/src/number/enum/int8.test.mts +1 -1
- package/src/number/enum/uint8.test.mts +1 -1
- package/src/object/object.mts +170 -1
- package/src/object/object.test.mts +172 -0
- package/src/others/fast-deep-equal.mts +0 -1
- package/src/others/unknown-to-string.test.mts +1 -1
|
@@ -9,43 +9,39 @@ import {
|
|
|
9
9
|
describe('NonZeroInt32 test', () => {
|
|
10
10
|
describe(asNonZeroInt32, () => {
|
|
11
11
|
test('accepts valid non-zero int32 values', () => {
|
|
12
|
-
expect(() => asNonZeroInt32(1)).not.
|
|
12
|
+
expect(() => asNonZeroInt32(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroInt32(-1)).not.
|
|
14
|
+
expect(() => asNonZeroInt32(-1)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroInt32(2_147_483_647)).not.
|
|
16
|
+
expect(() => asNonZeroInt32(2_147_483_647)).not.toThrow(); // 2^31 - 1
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroInt32(-2_147_483_648)).not.
|
|
18
|
+
expect(() => asNonZeroInt32(-2_147_483_648)).not.toThrow(); // -2^31
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('rejects zero', () => {
|
|
22
|
-
expect(() => asNonZeroInt32(0)).
|
|
22
|
+
expect(() => asNonZeroInt32(0)).toThrow(TypeError);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('rejects values outside int32 range', () => {
|
|
26
|
-
expect(() => asNonZeroInt32(2_147_483_648)).
|
|
26
|
+
expect(() => asNonZeroInt32(2_147_483_648)).toThrow(TypeError); // 2^31
|
|
27
27
|
|
|
28
|
-
expect(() => asNonZeroInt32(-2_147_483_649)).
|
|
28
|
+
expect(() => asNonZeroInt32(-2_147_483_649)).toThrow(TypeError); // -2^31 - 1
|
|
29
29
|
|
|
30
|
-
expect(() => asNonZeroInt32(4_294_967_296)).
|
|
30
|
+
expect(() => asNonZeroInt32(4_294_967_296)).toThrow(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asNonZeroInt32(-4_294_967_296)).
|
|
32
|
+
expect(() => asNonZeroInt32(-4_294_967_296)).toThrow(TypeError);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('rejects non-integers', () => {
|
|
36
|
-
expect(() => asNonZeroInt32(Number.NaN)).
|
|
36
|
+
expect(() => asNonZeroInt32(Number.NaN)).toThrow(TypeError);
|
|
37
37
|
|
|
38
|
-
expect(() => asNonZeroInt32(Number.POSITIVE_INFINITY)).
|
|
39
|
-
TypeError,
|
|
40
|
-
);
|
|
38
|
+
expect(() => asNonZeroInt32(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
41
39
|
|
|
42
|
-
expect(() => asNonZeroInt32(Number.NEGATIVE_INFINITY)).
|
|
43
|
-
TypeError,
|
|
44
|
-
);
|
|
40
|
+
expect(() => asNonZeroInt32(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
45
41
|
|
|
46
|
-
expect(() => asNonZeroInt32(1.2)).
|
|
42
|
+
expect(() => asNonZeroInt32(1.2)).toThrow(TypeError);
|
|
47
43
|
|
|
48
|
-
expect(() => asNonZeroInt32(-3.4)).
|
|
44
|
+
expect(() => asNonZeroInt32(-3.4)).toThrow(TypeError);
|
|
49
45
|
});
|
|
50
46
|
|
|
51
47
|
test('returns the same value for valid inputs', () => {
|
|
@@ -70,7 +66,7 @@ describe('NonZeroInt32 test', () => {
|
|
|
70
66
|
] as const)(
|
|
71
67
|
`asNonZeroInt32($name) should throw a TypeError`,
|
|
72
68
|
({ value }) => {
|
|
73
|
-
expect(() => asNonZeroInt32(value)).
|
|
69
|
+
expect(() => asNonZeroInt32(value)).toThrow(
|
|
74
70
|
new TypeError(
|
|
75
71
|
`Expected a non-zero integer in [-2^31, 2^31), got: ${value}`,
|
|
76
72
|
),
|
|
@@ -9,57 +9,53 @@ import {
|
|
|
9
9
|
describe('NonZeroSafeInt test', () => {
|
|
10
10
|
describe(asNonZeroSafeInt, () => {
|
|
11
11
|
test('accepts valid non-zero safe integers', () => {
|
|
12
|
-
expect(() => asNonZeroSafeInt(1)).not.
|
|
12
|
+
expect(() => asNonZeroSafeInt(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroSafeInt(-1)).not.
|
|
14
|
+
expect(() => asNonZeroSafeInt(-1)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroSafeInt(42)).not.
|
|
16
|
+
expect(() => asNonZeroSafeInt(42)).not.toThrow();
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroSafeInt(-42)).not.
|
|
18
|
+
expect(() => asNonZeroSafeInt(-42)).not.toThrow();
|
|
19
19
|
|
|
20
|
-
expect(() =>
|
|
21
|
-
asNonZeroSafeInt(Number.MAX_SAFE_INTEGER),
|
|
22
|
-
).not.toThrowError();
|
|
20
|
+
expect(() => asNonZeroSafeInt(Number.MAX_SAFE_INTEGER)).not.toThrow();
|
|
23
21
|
|
|
24
|
-
expect(() =>
|
|
25
|
-
asNonZeroSafeInt(Number.MIN_SAFE_INTEGER),
|
|
26
|
-
).not.toThrowError();
|
|
22
|
+
expect(() => asNonZeroSafeInt(Number.MIN_SAFE_INTEGER)).not.toThrow();
|
|
27
23
|
});
|
|
28
24
|
|
|
29
25
|
test('rejects zero', () => {
|
|
30
|
-
expect(() => asNonZeroSafeInt(0)).
|
|
26
|
+
expect(() => asNonZeroSafeInt(0)).toThrow(TypeError);
|
|
31
27
|
|
|
32
|
-
expect(() => asNonZeroSafeInt(-0)).
|
|
28
|
+
expect(() => asNonZeroSafeInt(-0)).toThrow(TypeError);
|
|
33
29
|
});
|
|
34
30
|
|
|
35
31
|
test('rejects values outside safe integer range', () => {
|
|
36
|
-
expect(() => asNonZeroSafeInt(Number.MAX_SAFE_INTEGER + 1)).
|
|
32
|
+
expect(() => asNonZeroSafeInt(Number.MAX_SAFE_INTEGER + 1)).toThrow(
|
|
37
33
|
TypeError,
|
|
38
34
|
);
|
|
39
35
|
|
|
40
|
-
expect(() => asNonZeroSafeInt(Number.MIN_SAFE_INTEGER - 1)).
|
|
36
|
+
expect(() => asNonZeroSafeInt(Number.MIN_SAFE_INTEGER - 1)).toThrow(
|
|
41
37
|
TypeError,
|
|
42
38
|
);
|
|
43
39
|
|
|
44
|
-
expect(() => asNonZeroSafeInt(Number.MAX_VALUE)).
|
|
40
|
+
expect(() => asNonZeroSafeInt(Number.MAX_VALUE)).toThrow(TypeError);
|
|
45
41
|
|
|
46
|
-
expect(() => asNonZeroSafeInt(-Number.MAX_VALUE)).
|
|
42
|
+
expect(() => asNonZeroSafeInt(-Number.MAX_VALUE)).toThrow(TypeError);
|
|
47
43
|
});
|
|
48
44
|
|
|
49
45
|
test('rejects non-integers', () => {
|
|
50
|
-
expect(() => asNonZeroSafeInt(Number.NaN)).
|
|
46
|
+
expect(() => asNonZeroSafeInt(Number.NaN)).toThrow(TypeError);
|
|
51
47
|
|
|
52
|
-
expect(() => asNonZeroSafeInt(Number.POSITIVE_INFINITY)).
|
|
48
|
+
expect(() => asNonZeroSafeInt(Number.POSITIVE_INFINITY)).toThrow(
|
|
53
49
|
TypeError,
|
|
54
50
|
);
|
|
55
51
|
|
|
56
|
-
expect(() => asNonZeroSafeInt(Number.NEGATIVE_INFINITY)).
|
|
52
|
+
expect(() => asNonZeroSafeInt(Number.NEGATIVE_INFINITY)).toThrow(
|
|
57
53
|
TypeError,
|
|
58
54
|
);
|
|
59
55
|
|
|
60
|
-
expect(() => asNonZeroSafeInt(1.2)).
|
|
56
|
+
expect(() => asNonZeroSafeInt(1.2)).toThrow(TypeError);
|
|
61
57
|
|
|
62
|
-
expect(() => asNonZeroSafeInt(-3.4)).
|
|
58
|
+
expect(() => asNonZeroSafeInt(-3.4)).toThrow(TypeError);
|
|
63
59
|
});
|
|
64
60
|
|
|
65
61
|
test('returns the same value for valid inputs', () => {
|
|
@@ -80,7 +76,7 @@ describe('NonZeroSafeInt test', () => {
|
|
|
80
76
|
] as const)(
|
|
81
77
|
`asNonZeroSafeInt($name) should throw a TypeError`,
|
|
82
78
|
({ value }) => {
|
|
83
|
-
expect(() => asNonZeroSafeInt(value)).
|
|
79
|
+
expect(() => asNonZeroSafeInt(value)).toThrow(
|
|
84
80
|
new TypeError(`Expected a non-zero safe integer, got: ${value}`),
|
|
85
81
|
);
|
|
86
82
|
},
|
|
@@ -9,45 +9,45 @@ import {
|
|
|
9
9
|
describe('NonZeroUint16 test', () => {
|
|
10
10
|
describe(asNonZeroUint16, () => {
|
|
11
11
|
test('accepts valid non-zero uint16 values', () => {
|
|
12
|
-
expect(() => asNonZeroUint16(1)).not.
|
|
12
|
+
expect(() => asNonZeroUint16(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroUint16(1000)).not.
|
|
14
|
+
expect(() => asNonZeroUint16(1000)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroUint16(65_535)).not.
|
|
16
|
+
expect(() => asNonZeroUint16(65_535)).not.toThrow(); // 2^16 - 1
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroUint16(32_768)).not.
|
|
18
|
+
expect(() => asNonZeroUint16(32_768)).not.toThrow(); // 2^15
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('rejects zero', () => {
|
|
22
|
-
expect(() => asNonZeroUint16(0)).
|
|
22
|
+
expect(() => asNonZeroUint16(0)).toThrow(TypeError);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('rejects values outside uint16 range', () => {
|
|
26
|
-
expect(() => asNonZeroUint16(65_536)).
|
|
26
|
+
expect(() => asNonZeroUint16(65_536)).toThrow(TypeError); // 2^16
|
|
27
27
|
|
|
28
|
-
expect(() => asNonZeroUint16(100_000)).
|
|
28
|
+
expect(() => asNonZeroUint16(100_000)).toThrow(TypeError);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
test('rejects negative integers', () => {
|
|
32
|
-
expect(() => asNonZeroUint16(-1)).
|
|
32
|
+
expect(() => asNonZeroUint16(-1)).toThrow(TypeError);
|
|
33
33
|
|
|
34
|
-
expect(() => asNonZeroUint16(-42)).
|
|
34
|
+
expect(() => asNonZeroUint16(-42)).toThrow(TypeError);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
test('rejects non-integers', () => {
|
|
38
|
-
expect(() => asNonZeroUint16(Number.NaN)).
|
|
38
|
+
expect(() => asNonZeroUint16(Number.NaN)).toThrow(TypeError);
|
|
39
39
|
|
|
40
|
-
expect(() => asNonZeroUint16(Number.POSITIVE_INFINITY)).
|
|
40
|
+
expect(() => asNonZeroUint16(Number.POSITIVE_INFINITY)).toThrow(
|
|
41
41
|
TypeError,
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
expect(() => asNonZeroUint16(Number.NEGATIVE_INFINITY)).
|
|
44
|
+
expect(() => asNonZeroUint16(Number.NEGATIVE_INFINITY)).toThrow(
|
|
45
45
|
TypeError,
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
expect(() => asNonZeroUint16(1.2)).
|
|
48
|
+
expect(() => asNonZeroUint16(1.2)).toThrow(TypeError);
|
|
49
49
|
|
|
50
|
-
expect(() => asNonZeroUint16(-3.4)).
|
|
50
|
+
expect(() => asNonZeroUint16(-3.4)).toThrow(TypeError);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
test('returns the same value for valid inputs', () => {
|
|
@@ -70,7 +70,7 @@ describe('NonZeroUint16 test', () => {
|
|
|
70
70
|
] as const)(
|
|
71
71
|
`asNonZeroUint16($name) should throw a TypeError`,
|
|
72
72
|
({ value }) => {
|
|
73
|
-
expect(() => asNonZeroUint16(value)).
|
|
73
|
+
expect(() => asNonZeroUint16(value)).toThrow(
|
|
74
74
|
new TypeError(
|
|
75
75
|
`Expected a non-zero integer in [1, 2^16), got: ${value}`,
|
|
76
76
|
),
|
|
@@ -9,45 +9,45 @@ import {
|
|
|
9
9
|
describe('NonZeroUint32 test', () => {
|
|
10
10
|
describe(asNonZeroUint32, () => {
|
|
11
11
|
test('accepts valid non-zero uint32 values', () => {
|
|
12
|
-
expect(() => asNonZeroUint32(1)).not.
|
|
12
|
+
expect(() => asNonZeroUint32(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroUint32(1000)).not.
|
|
14
|
+
expect(() => asNonZeroUint32(1000)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroUint32(4_294_967_295)).not.
|
|
16
|
+
expect(() => asNonZeroUint32(4_294_967_295)).not.toThrow(); // 2^32 - 1
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroUint32(2_147_483_648)).not.
|
|
18
|
+
expect(() => asNonZeroUint32(2_147_483_648)).not.toThrow(); // 2^31
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('rejects zero', () => {
|
|
22
|
-
expect(() => asNonZeroUint32(0)).
|
|
22
|
+
expect(() => asNonZeroUint32(0)).toThrow(TypeError);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('rejects values outside uint32 range', () => {
|
|
26
|
-
expect(() => asNonZeroUint32(4_294_967_296)).
|
|
26
|
+
expect(() => asNonZeroUint32(4_294_967_296)).toThrow(TypeError); // 2^32
|
|
27
27
|
|
|
28
|
-
expect(() => asNonZeroUint32(10_000_000_000)).
|
|
28
|
+
expect(() => asNonZeroUint32(10_000_000_000)).toThrow(TypeError);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
test('rejects negative integers', () => {
|
|
32
|
-
expect(() => asNonZeroUint32(-1)).
|
|
32
|
+
expect(() => asNonZeroUint32(-1)).toThrow(TypeError);
|
|
33
33
|
|
|
34
|
-
expect(() => asNonZeroUint32(-42)).
|
|
34
|
+
expect(() => asNonZeroUint32(-42)).toThrow(TypeError);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
test('rejects non-integers', () => {
|
|
38
|
-
expect(() => asNonZeroUint32(Number.NaN)).
|
|
38
|
+
expect(() => asNonZeroUint32(Number.NaN)).toThrow(TypeError);
|
|
39
39
|
|
|
40
|
-
expect(() => asNonZeroUint32(Number.POSITIVE_INFINITY)).
|
|
40
|
+
expect(() => asNonZeroUint32(Number.POSITIVE_INFINITY)).toThrow(
|
|
41
41
|
TypeError,
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
expect(() => asNonZeroUint32(Number.NEGATIVE_INFINITY)).
|
|
44
|
+
expect(() => asNonZeroUint32(Number.NEGATIVE_INFINITY)).toThrow(
|
|
45
45
|
TypeError,
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
expect(() => asNonZeroUint32(1.2)).
|
|
48
|
+
expect(() => asNonZeroUint32(1.2)).toThrow(TypeError);
|
|
49
49
|
|
|
50
|
-
expect(() => asNonZeroUint32(-3.4)).
|
|
50
|
+
expect(() => asNonZeroUint32(-3.4)).toThrow(TypeError);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
test('returns the same value for valid inputs', () => {
|
|
@@ -70,7 +70,7 @@ describe('NonZeroUint32 test', () => {
|
|
|
70
70
|
] as const)(
|
|
71
71
|
`asNonZeroUint32($name) should throw a TypeError`,
|
|
72
72
|
({ value }) => {
|
|
73
|
-
expect(() => asNonZeroUint32(value)).
|
|
73
|
+
expect(() => asNonZeroUint32(value)).toThrow(
|
|
74
74
|
new TypeError(
|
|
75
75
|
`Expected a non-zero integer in [1, 2^32), got: ${value}`,
|
|
76
76
|
),
|
|
@@ -9,43 +9,43 @@ import {
|
|
|
9
9
|
describe('PositiveFiniteNumber test', () => {
|
|
10
10
|
describe(asPositiveFiniteNumber, () => {
|
|
11
11
|
test('accepts valid positive finite numbers', () => {
|
|
12
|
-
expect(() => asPositiveFiniteNumber(1)).not.
|
|
12
|
+
expect(() => asPositiveFiniteNumber(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asPositiveFiniteNumber(3.14)).not.
|
|
14
|
+
expect(() => asPositiveFiniteNumber(3.14)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asPositiveFiniteNumber(0.5)).not.
|
|
16
|
+
expect(() => asPositiveFiniteNumber(0.5)).not.toThrow();
|
|
17
17
|
|
|
18
|
-
expect(() => asPositiveFiniteNumber(Number.MIN_VALUE)).not.
|
|
18
|
+
expect(() => asPositiveFiniteNumber(Number.MIN_VALUE)).not.toThrow();
|
|
19
19
|
|
|
20
|
-
expect(() => asPositiveFiniteNumber(Number.MAX_VALUE)).not.
|
|
20
|
+
expect(() => asPositiveFiniteNumber(Number.MAX_VALUE)).not.toThrow();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test('rejects zero', () => {
|
|
24
|
-
expect(() => asPositiveFiniteNumber(0)).
|
|
24
|
+
expect(() => asPositiveFiniteNumber(0)).toThrow(TypeError);
|
|
25
25
|
|
|
26
|
-
expect(() => asPositiveFiniteNumber(-0)).
|
|
26
|
+
expect(() => asPositiveFiniteNumber(-0)).toThrow(TypeError);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
test('rejects negative numbers', () => {
|
|
30
|
-
expect(() => asPositiveFiniteNumber(-1)).
|
|
30
|
+
expect(() => asPositiveFiniteNumber(-1)).toThrow(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asPositiveFiniteNumber(-0.1)).
|
|
32
|
+
expect(() => asPositiveFiniteNumber(-0.1)).toThrow(TypeError);
|
|
33
33
|
|
|
34
|
-
expect(() => asPositiveFiniteNumber(-Number.MAX_VALUE)).
|
|
34
|
+
expect(() => asPositiveFiniteNumber(-Number.MAX_VALUE)).toThrow(
|
|
35
35
|
TypeError,
|
|
36
36
|
);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
test('rejects non-finite numbers', () => {
|
|
40
|
-
expect(() => asPositiveFiniteNumber(Number.NaN)).
|
|
40
|
+
expect(() => asPositiveFiniteNumber(Number.NaN)).toThrow(TypeError);
|
|
41
41
|
|
|
42
|
-
expect(() =>
|
|
43
|
-
|
|
44
|
-
)
|
|
42
|
+
expect(() => asPositiveFiniteNumber(Number.POSITIVE_INFINITY)).toThrow(
|
|
43
|
+
TypeError,
|
|
44
|
+
);
|
|
45
45
|
|
|
46
|
-
expect(() =>
|
|
47
|
-
|
|
48
|
-
)
|
|
46
|
+
expect(() => asPositiveFiniteNumber(Number.NEGATIVE_INFINITY)).toThrow(
|
|
47
|
+
TypeError,
|
|
48
|
+
);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('returns the same value for valid inputs', () => {
|
|
@@ -64,7 +64,7 @@ describe('PositiveFiniteNumber test', () => {
|
|
|
64
64
|
] as const)(
|
|
65
65
|
`asPositiveFiniteNumber($name) should throw a TypeError`,
|
|
66
66
|
({ value }) => {
|
|
67
|
-
expect(() => asPositiveFiniteNumber(value)).
|
|
67
|
+
expect(() => asPositiveFiniteNumber(value)).toThrow(
|
|
68
68
|
new TypeError(`Expected a positive finite number, got: ${value}`),
|
|
69
69
|
);
|
|
70
70
|
},
|
|
@@ -5,47 +5,41 @@ import { asPositiveInt, isPositiveInt, PositiveInt } from './positive-int.mjs';
|
|
|
5
5
|
describe('PositiveInt test', () => {
|
|
6
6
|
describe(asPositiveInt, () => {
|
|
7
7
|
test('accepts valid positive integers', () => {
|
|
8
|
-
expect(() => asPositiveInt(1)).not.
|
|
8
|
+
expect(() => asPositiveInt(1)).not.toThrow();
|
|
9
9
|
|
|
10
|
-
expect(() => asPositiveInt(2)).not.
|
|
10
|
+
expect(() => asPositiveInt(2)).not.toThrow();
|
|
11
11
|
|
|
12
|
-
expect(() => asPositiveInt(42)).not.
|
|
12
|
+
expect(() => asPositiveInt(42)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asPositiveInt(100)).not.
|
|
14
|
+
expect(() => asPositiveInt(100)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asPositiveInt(Number.MAX_SAFE_INTEGER)).not.
|
|
16
|
+
expect(() => asPositiveInt(Number.MAX_SAFE_INTEGER)).not.toThrow();
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
test('rejects zero', () => {
|
|
20
|
-
expect(() => asPositiveInt(0)).
|
|
20
|
+
expect(() => asPositiveInt(0)).toThrow(TypeError);
|
|
21
21
|
|
|
22
|
-
expect(() => asPositiveInt(-0)).
|
|
22
|
+
expect(() => asPositiveInt(-0)).toThrow(TypeError);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('rejects negative integers', () => {
|
|
26
|
-
expect(() => asPositiveInt(-1)).
|
|
26
|
+
expect(() => asPositiveInt(-1)).toThrow(TypeError);
|
|
27
27
|
|
|
28
|
-
expect(() => asPositiveInt(-42)).
|
|
28
|
+
expect(() => asPositiveInt(-42)).toThrow(TypeError);
|
|
29
29
|
|
|
30
|
-
expect(() => asPositiveInt(Number.MIN_SAFE_INTEGER)).
|
|
31
|
-
TypeError,
|
|
32
|
-
);
|
|
30
|
+
expect(() => asPositiveInt(Number.MIN_SAFE_INTEGER)).toThrow(TypeError);
|
|
33
31
|
});
|
|
34
32
|
|
|
35
33
|
test('rejects non-integers', () => {
|
|
36
|
-
expect(() => asPositiveInt(Number.NaN)).
|
|
34
|
+
expect(() => asPositiveInt(Number.NaN)).toThrow(TypeError);
|
|
37
35
|
|
|
38
|
-
expect(() => asPositiveInt(Number.POSITIVE_INFINITY)).
|
|
39
|
-
TypeError,
|
|
40
|
-
);
|
|
36
|
+
expect(() => asPositiveInt(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
41
37
|
|
|
42
|
-
expect(() => asPositiveInt(Number.NEGATIVE_INFINITY)).
|
|
43
|
-
TypeError,
|
|
44
|
-
);
|
|
38
|
+
expect(() => asPositiveInt(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
45
39
|
|
|
46
|
-
expect(() => asPositiveInt(1.2)).
|
|
40
|
+
expect(() => asPositiveInt(1.2)).toThrow(TypeError);
|
|
47
41
|
|
|
48
|
-
expect(() => asPositiveInt(-3.4)).
|
|
42
|
+
expect(() => asPositiveInt(-3.4)).toThrow(TypeError);
|
|
49
43
|
});
|
|
50
44
|
|
|
51
45
|
test('returns the same value for valid inputs', () => {
|
|
@@ -67,7 +61,7 @@ describe('PositiveInt test', () => {
|
|
|
67
61
|
] as const)(
|
|
68
62
|
`asPositiveInt($name) should throw a TypeError`,
|
|
69
63
|
({ value }) => {
|
|
70
|
-
expect(() => asPositiveInt(value)).
|
|
64
|
+
expect(() => asPositiveInt(value)).toThrow(
|
|
71
65
|
new TypeError(`Expected a positive integer, got: ${value}`),
|
|
72
66
|
);
|
|
73
67
|
},
|
|
@@ -9,43 +9,43 @@ import {
|
|
|
9
9
|
describe('PositiveInt16 test', () => {
|
|
10
10
|
describe(asPositiveInt16, () => {
|
|
11
11
|
test('accepts valid positive int16 values', () => {
|
|
12
|
-
expect(() => asPositiveInt16(1)).not.
|
|
12
|
+
expect(() => asPositiveInt16(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asPositiveInt16(1000)).not.
|
|
14
|
+
expect(() => asPositiveInt16(1000)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asPositiveInt16(32_767)).not.
|
|
16
|
+
expect(() => asPositiveInt16(32_767)).not.toThrow(); // 2^15 - 1
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
test('rejects zero', () => {
|
|
20
|
-
expect(() => asPositiveInt16(0)).
|
|
20
|
+
expect(() => asPositiveInt16(0)).toThrow(TypeError);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test('rejects values outside int16 range', () => {
|
|
24
|
-
expect(() => asPositiveInt16(32_768)).
|
|
24
|
+
expect(() => asPositiveInt16(32_768)).toThrow(TypeError); // 2^15
|
|
25
25
|
|
|
26
|
-
expect(() => asPositiveInt16(65_536)).
|
|
26
|
+
expect(() => asPositiveInt16(65_536)).toThrow(TypeError);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
test('rejects negative integers', () => {
|
|
30
|
-
expect(() => asPositiveInt16(-1)).
|
|
30
|
+
expect(() => asPositiveInt16(-1)).toThrow(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asPositiveInt16(-42)).
|
|
32
|
+
expect(() => asPositiveInt16(-42)).toThrow(TypeError);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('rejects non-integers', () => {
|
|
36
|
-
expect(() => asPositiveInt16(Number.NaN)).
|
|
36
|
+
expect(() => asPositiveInt16(Number.NaN)).toThrow(TypeError);
|
|
37
37
|
|
|
38
|
-
expect(() => asPositiveInt16(Number.POSITIVE_INFINITY)).
|
|
38
|
+
expect(() => asPositiveInt16(Number.POSITIVE_INFINITY)).toThrow(
|
|
39
39
|
TypeError,
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
expect(() => asPositiveInt16(Number.NEGATIVE_INFINITY)).
|
|
42
|
+
expect(() => asPositiveInt16(Number.NEGATIVE_INFINITY)).toThrow(
|
|
43
43
|
TypeError,
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
expect(() => asPositiveInt16(1.2)).
|
|
46
|
+
expect(() => asPositiveInt16(1.2)).toThrow(TypeError);
|
|
47
47
|
|
|
48
|
-
expect(() => asPositiveInt16(-3.4)).
|
|
48
|
+
expect(() => asPositiveInt16(-3.4)).toThrow(TypeError);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('returns the same value for valid inputs', () => {
|
|
@@ -68,7 +68,7 @@ describe('PositiveInt16 test', () => {
|
|
|
68
68
|
] as const)(
|
|
69
69
|
`asPositiveInt16($name) should throw a TypeError`,
|
|
70
70
|
({ value }) => {
|
|
71
|
-
expect(() => asPositiveInt16(value)).
|
|
71
|
+
expect(() => asPositiveInt16(value)).toThrow(
|
|
72
72
|
new TypeError(
|
|
73
73
|
`Expected a positive integer in [1, 2^15), got: ${value}`,
|
|
74
74
|
),
|
|
@@ -9,43 +9,43 @@ import {
|
|
|
9
9
|
describe('PositiveInt32 test', () => {
|
|
10
10
|
describe(asPositiveInt32, () => {
|
|
11
11
|
test('accepts valid positive int32 values', () => {
|
|
12
|
-
expect(() => asPositiveInt32(1)).not.
|
|
12
|
+
expect(() => asPositiveInt32(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asPositiveInt32(1000)).not.
|
|
14
|
+
expect(() => asPositiveInt32(1000)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asPositiveInt32(2_147_483_647)).not.
|
|
16
|
+
expect(() => asPositiveInt32(2_147_483_647)).not.toThrow(); // 2^31 - 1
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
test('rejects zero', () => {
|
|
20
|
-
expect(() => asPositiveInt32(0)).
|
|
20
|
+
expect(() => asPositiveInt32(0)).toThrow(TypeError);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test('rejects values outside int32 range', () => {
|
|
24
|
-
expect(() => asPositiveInt32(2_147_483_648)).
|
|
24
|
+
expect(() => asPositiveInt32(2_147_483_648)).toThrow(TypeError); // 2^31
|
|
25
25
|
|
|
26
|
-
expect(() => asPositiveInt32(4_294_967_296)).
|
|
26
|
+
expect(() => asPositiveInt32(4_294_967_296)).toThrow(TypeError);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
test('rejects negative integers', () => {
|
|
30
|
-
expect(() => asPositiveInt32(-1)).
|
|
30
|
+
expect(() => asPositiveInt32(-1)).toThrow(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asPositiveInt32(-42)).
|
|
32
|
+
expect(() => asPositiveInt32(-42)).toThrow(TypeError);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('rejects non-integers', () => {
|
|
36
|
-
expect(() => asPositiveInt32(Number.NaN)).
|
|
36
|
+
expect(() => asPositiveInt32(Number.NaN)).toThrow(TypeError);
|
|
37
37
|
|
|
38
|
-
expect(() => asPositiveInt32(Number.POSITIVE_INFINITY)).
|
|
38
|
+
expect(() => asPositiveInt32(Number.POSITIVE_INFINITY)).toThrow(
|
|
39
39
|
TypeError,
|
|
40
40
|
);
|
|
41
41
|
|
|
42
|
-
expect(() => asPositiveInt32(Number.NEGATIVE_INFINITY)).
|
|
42
|
+
expect(() => asPositiveInt32(Number.NEGATIVE_INFINITY)).toThrow(
|
|
43
43
|
TypeError,
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
expect(() => asPositiveInt32(1.2)).
|
|
46
|
+
expect(() => asPositiveInt32(1.2)).toThrow(TypeError);
|
|
47
47
|
|
|
48
|
-
expect(() => asPositiveInt32(-3.4)).
|
|
48
|
+
expect(() => asPositiveInt32(-3.4)).toThrow(TypeError);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('returns the same value for valid inputs', () => {
|
|
@@ -68,7 +68,7 @@ describe('PositiveInt32 test', () => {
|
|
|
68
68
|
] as const)(
|
|
69
69
|
`asPositiveInt32($name) should throw a TypeError`,
|
|
70
70
|
({ value }) => {
|
|
71
|
-
expect(() => asPositiveInt32(value)).
|
|
71
|
+
expect(() => asPositiveInt32(value)).toThrow(
|
|
72
72
|
new TypeError(
|
|
73
73
|
`Expected a positive integer in [1, 2^31), got: ${value}`,
|
|
74
74
|
),
|
|
@@ -9,57 +9,55 @@ import {
|
|
|
9
9
|
describe('PositiveSafeInt test', () => {
|
|
10
10
|
describe(asPositiveSafeInt, () => {
|
|
11
11
|
test('accepts valid positive safe integers', () => {
|
|
12
|
-
expect(() => asPositiveSafeInt(1)).not.
|
|
12
|
+
expect(() => asPositiveSafeInt(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asPositiveSafeInt(2)).not.
|
|
14
|
+
expect(() => asPositiveSafeInt(2)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asPositiveSafeInt(42)).not.
|
|
16
|
+
expect(() => asPositiveSafeInt(42)).not.toThrow();
|
|
17
17
|
|
|
18
|
-
expect(() => asPositiveSafeInt(100)).not.
|
|
18
|
+
expect(() => asPositiveSafeInt(100)).not.toThrow();
|
|
19
19
|
|
|
20
|
-
expect(() =>
|
|
21
|
-
asPositiveSafeInt(Number.MAX_SAFE_INTEGER),
|
|
22
|
-
).not.toThrowError();
|
|
20
|
+
expect(() => asPositiveSafeInt(Number.MAX_SAFE_INTEGER)).not.toThrow();
|
|
23
21
|
});
|
|
24
22
|
|
|
25
23
|
test('rejects zero', () => {
|
|
26
|
-
expect(() => asPositiveSafeInt(0)).
|
|
24
|
+
expect(() => asPositiveSafeInt(0)).toThrow(TypeError);
|
|
27
25
|
|
|
28
|
-
expect(() => asPositiveSafeInt(-0)).
|
|
26
|
+
expect(() => asPositiveSafeInt(-0)).toThrow(TypeError);
|
|
29
27
|
});
|
|
30
28
|
|
|
31
29
|
test('rejects negative integers', () => {
|
|
32
|
-
expect(() => asPositiveSafeInt(-1)).
|
|
30
|
+
expect(() => asPositiveSafeInt(-1)).toThrow(TypeError);
|
|
33
31
|
|
|
34
|
-
expect(() => asPositiveSafeInt(-42)).
|
|
32
|
+
expect(() => asPositiveSafeInt(-42)).toThrow(TypeError);
|
|
35
33
|
|
|
36
|
-
expect(() => asPositiveSafeInt(Number.MIN_SAFE_INTEGER)).
|
|
34
|
+
expect(() => asPositiveSafeInt(Number.MIN_SAFE_INTEGER)).toThrow(
|
|
37
35
|
TypeError,
|
|
38
36
|
);
|
|
39
37
|
});
|
|
40
38
|
|
|
41
39
|
test('rejects values outside safe integer range', () => {
|
|
42
|
-
expect(() => asPositiveSafeInt(Number.MAX_SAFE_INTEGER + 1)).
|
|
40
|
+
expect(() => asPositiveSafeInt(Number.MAX_SAFE_INTEGER + 1)).toThrow(
|
|
43
41
|
TypeError,
|
|
44
42
|
);
|
|
45
43
|
|
|
46
|
-
expect(() => asPositiveSafeInt(Number.MAX_VALUE)).
|
|
44
|
+
expect(() => asPositiveSafeInt(Number.MAX_VALUE)).toThrow(TypeError);
|
|
47
45
|
});
|
|
48
46
|
|
|
49
47
|
test('rejects non-integers', () => {
|
|
50
|
-
expect(() => asPositiveSafeInt(Number.NaN)).
|
|
48
|
+
expect(() => asPositiveSafeInt(Number.NaN)).toThrow(TypeError);
|
|
51
49
|
|
|
52
|
-
expect(() => asPositiveSafeInt(Number.POSITIVE_INFINITY)).
|
|
50
|
+
expect(() => asPositiveSafeInt(Number.POSITIVE_INFINITY)).toThrow(
|
|
53
51
|
TypeError,
|
|
54
52
|
);
|
|
55
53
|
|
|
56
|
-
expect(() => asPositiveSafeInt(Number.NEGATIVE_INFINITY)).
|
|
54
|
+
expect(() => asPositiveSafeInt(Number.NEGATIVE_INFINITY)).toThrow(
|
|
57
55
|
TypeError,
|
|
58
56
|
);
|
|
59
57
|
|
|
60
|
-
expect(() => asPositiveSafeInt(1.2)).
|
|
58
|
+
expect(() => asPositiveSafeInt(1.2)).toThrow(TypeError);
|
|
61
59
|
|
|
62
|
-
expect(() => asPositiveSafeInt(-3.4)).
|
|
60
|
+
expect(() => asPositiveSafeInt(-3.4)).toThrow(TypeError);
|
|
63
61
|
});
|
|
64
62
|
|
|
65
63
|
test('returns the same value for valid inputs', () => {
|
|
@@ -81,7 +79,7 @@ describe('PositiveSafeInt test', () => {
|
|
|
81
79
|
] as const)(
|
|
82
80
|
`asPositiveSafeInt($name) should throw a TypeError`,
|
|
83
81
|
({ value }) => {
|
|
84
|
-
expect(() => asPositiveSafeInt(value)).
|
|
82
|
+
expect(() => asPositiveSafeInt(value)).toThrow(
|
|
85
83
|
new TypeError(`Expected a positive safe integer, got: ${value}`),
|
|
86
84
|
);
|
|
87
85
|
},
|