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
|
@@ -6,31 +6,27 @@ import { asNonZeroFiniteNumber } from './non-zero-finite-number.mjs';
|
|
|
6
6
|
describe('FiniteNumber test', () => {
|
|
7
7
|
describe(asFiniteNumber, () => {
|
|
8
8
|
test('accepts valid finite numbers', () => {
|
|
9
|
-
expect(() => asFiniteNumber(0)).not.
|
|
9
|
+
expect(() => asFiniteNumber(0)).not.toThrow();
|
|
10
10
|
|
|
11
|
-
expect(() => asFiniteNumber(1)).not.
|
|
11
|
+
expect(() => asFiniteNumber(1)).not.toThrow();
|
|
12
12
|
|
|
13
|
-
expect(() => asFiniteNumber(-1)).not.
|
|
13
|
+
expect(() => asFiniteNumber(-1)).not.toThrow();
|
|
14
14
|
|
|
15
|
-
expect(() => asFiniteNumber(3.14)).not.
|
|
15
|
+
expect(() => asFiniteNumber(3.14)).not.toThrow();
|
|
16
16
|
|
|
17
|
-
expect(() => asFiniteNumber(-2.5)).not.
|
|
17
|
+
expect(() => asFiniteNumber(-2.5)).not.toThrow();
|
|
18
18
|
|
|
19
|
-
expect(() => asFiniteNumber(Number.MAX_VALUE)).not.
|
|
19
|
+
expect(() => asFiniteNumber(Number.MAX_VALUE)).not.toThrow();
|
|
20
20
|
|
|
21
|
-
expect(() => asFiniteNumber(-Number.MAX_VALUE)).not.
|
|
21
|
+
expect(() => asFiniteNumber(-Number.MAX_VALUE)).not.toThrow();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
test('rejects non-finite numbers', () => {
|
|
25
|
-
expect(() => asFiniteNumber(Number.NaN)).
|
|
25
|
+
expect(() => asFiniteNumber(Number.NaN)).toThrow(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asFiniteNumber(Number.POSITIVE_INFINITY)).
|
|
28
|
-
TypeError,
|
|
29
|
-
);
|
|
27
|
+
expect(() => asFiniteNumber(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
30
28
|
|
|
31
|
-
expect(() => asFiniteNumber(Number.NEGATIVE_INFINITY)).
|
|
32
|
-
TypeError,
|
|
33
|
-
);
|
|
29
|
+
expect(() => asFiniteNumber(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
34
30
|
});
|
|
35
31
|
|
|
36
32
|
test('returns the same value for valid inputs', () => {
|
|
@@ -48,7 +44,7 @@ describe('FiniteNumber test', () => {
|
|
|
48
44
|
] as const)(
|
|
49
45
|
`asFiniteNumber($name) should throw a TypeError`,
|
|
50
46
|
({ value }) => {
|
|
51
|
-
expect(() => asFiniteNumber(value)).
|
|
47
|
+
expect(() => asFiniteNumber(value)).toThrow(
|
|
52
48
|
new TypeError(`Expected a finite number, got: ${value}`),
|
|
53
49
|
);
|
|
54
50
|
},
|
|
@@ -6,31 +6,31 @@ import { asNonZeroInt } from './non-zero-int.mjs';
|
|
|
6
6
|
describe('Int test', () => {
|
|
7
7
|
describe(asInt, () => {
|
|
8
8
|
test('accepts valid integers', () => {
|
|
9
|
-
expect(() => asInt(0)).not.
|
|
9
|
+
expect(() => asInt(0)).not.toThrow();
|
|
10
10
|
|
|
11
|
-
expect(() => asInt(1)).not.
|
|
11
|
+
expect(() => asInt(1)).not.toThrow();
|
|
12
12
|
|
|
13
|
-
expect(() => asInt(-1)).not.
|
|
13
|
+
expect(() => asInt(-1)).not.toThrow();
|
|
14
14
|
|
|
15
|
-
expect(() => asInt(42)).not.
|
|
15
|
+
expect(() => asInt(42)).not.toThrow();
|
|
16
16
|
|
|
17
|
-
expect(() => asInt(-42)).not.
|
|
17
|
+
expect(() => asInt(-42)).not.toThrow();
|
|
18
18
|
|
|
19
|
-
expect(() => asInt(Number.MAX_SAFE_INTEGER)).not.
|
|
19
|
+
expect(() => asInt(Number.MAX_SAFE_INTEGER)).not.toThrow();
|
|
20
20
|
|
|
21
|
-
expect(() => asInt(Number.MIN_SAFE_INTEGER)).not.
|
|
21
|
+
expect(() => asInt(Number.MIN_SAFE_INTEGER)).not.toThrow();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
test('rejects non-integers', () => {
|
|
25
|
-
expect(() => asInt(Number.NaN)).
|
|
25
|
+
expect(() => asInt(Number.NaN)).toThrow(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asInt(Number.POSITIVE_INFINITY)).
|
|
27
|
+
expect(() => asInt(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
28
28
|
|
|
29
|
-
expect(() => asInt(Number.NEGATIVE_INFINITY)).
|
|
29
|
+
expect(() => asInt(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
30
30
|
|
|
31
|
-
expect(() => asInt(1.2)).
|
|
31
|
+
expect(() => asInt(1.2)).toThrow(TypeError);
|
|
32
32
|
|
|
33
|
-
expect(() => asInt(-3.4)).
|
|
33
|
+
expect(() => asInt(-3.4)).toThrow(TypeError);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('returns the same value for valid inputs', () => {
|
|
@@ -48,7 +48,7 @@ describe('Int test', () => {
|
|
|
48
48
|
{ name: '1.2', value: 1.2 },
|
|
49
49
|
{ name: '-3.4', value: -3.4 },
|
|
50
50
|
] as const)(`asInt($name) should throw a TypeError`, ({ value }) => {
|
|
51
|
-
expect(() => asInt(value)).
|
|
51
|
+
expect(() => asInt(value)).toThrow(
|
|
52
52
|
new TypeError(`Expected an integer, got: ${value}`),
|
|
53
53
|
);
|
|
54
54
|
});
|
|
@@ -6,37 +6,37 @@ import { asNonZeroInt16 } from './non-zero-int16.mjs';
|
|
|
6
6
|
describe('Int16 test', () => {
|
|
7
7
|
describe(asInt16, () => {
|
|
8
8
|
test('accepts valid int16 values', () => {
|
|
9
|
-
expect(() => asInt16(0)).not.
|
|
9
|
+
expect(() => asInt16(0)).not.toThrow();
|
|
10
10
|
|
|
11
|
-
expect(() => asInt16(1)).not.
|
|
11
|
+
expect(() => asInt16(1)).not.toThrow();
|
|
12
12
|
|
|
13
|
-
expect(() => asInt16(-1)).not.
|
|
13
|
+
expect(() => asInt16(-1)).not.toThrow();
|
|
14
14
|
|
|
15
|
-
expect(() => asInt16(32_767)).not.
|
|
15
|
+
expect(() => asInt16(32_767)).not.toThrow(); // 2^15 - 1
|
|
16
16
|
|
|
17
|
-
expect(() => asInt16(-32_768)).not.
|
|
17
|
+
expect(() => asInt16(-32_768)).not.toThrow(); // -2^15
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
test('rejects values outside int16 range', () => {
|
|
21
|
-
expect(() => asInt16(32_768)).
|
|
21
|
+
expect(() => asInt16(32_768)).toThrow(TypeError); // 2^15
|
|
22
22
|
|
|
23
|
-
expect(() => asInt16(-32_769)).
|
|
23
|
+
expect(() => asInt16(-32_769)).toThrow(TypeError); // -2^15 - 1
|
|
24
24
|
|
|
25
|
-
expect(() => asInt16(65_536)).
|
|
25
|
+
expect(() => asInt16(65_536)).toThrow(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asInt16(-65_536)).
|
|
27
|
+
expect(() => asInt16(-65_536)).toThrow(TypeError);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('rejects non-integers', () => {
|
|
31
|
-
expect(() => asInt16(Number.NaN)).
|
|
31
|
+
expect(() => asInt16(Number.NaN)).toThrow(TypeError);
|
|
32
32
|
|
|
33
|
-
expect(() => asInt16(Number.POSITIVE_INFINITY)).
|
|
33
|
+
expect(() => asInt16(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
34
34
|
|
|
35
|
-
expect(() => asInt16(Number.NEGATIVE_INFINITY)).
|
|
35
|
+
expect(() => asInt16(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
36
36
|
|
|
37
|
-
expect(() => asInt16(1.2)).
|
|
37
|
+
expect(() => asInt16(1.2)).toThrow(TypeError);
|
|
38
38
|
|
|
39
|
-
expect(() => asInt16(-3.4)).
|
|
39
|
+
expect(() => asInt16(-3.4)).toThrow(TypeError);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
test('returns the same value for valid inputs', () => {
|
|
@@ -58,7 +58,7 @@ describe('Int16 test', () => {
|
|
|
58
58
|
{ name: '1.2', value: 1.2 },
|
|
59
59
|
{ name: '-3.4', value: -3.4 },
|
|
60
60
|
] as const)(`asInt16($name) should throw a TypeError`, ({ value }) => {
|
|
61
|
-
expect(() => asInt16(value)).
|
|
61
|
+
expect(() => asInt16(value)).toThrow(
|
|
62
62
|
new TypeError(`Expected an integer in [-2^15, 2^15), got: ${value}`),
|
|
63
63
|
);
|
|
64
64
|
});
|
|
@@ -6,37 +6,37 @@ import { asNonZeroInt32 } from './non-zero-int32.mjs';
|
|
|
6
6
|
describe('Int32 test', () => {
|
|
7
7
|
describe(asInt32, () => {
|
|
8
8
|
test('accepts valid int32 values', () => {
|
|
9
|
-
expect(() => asInt32(0)).not.
|
|
9
|
+
expect(() => asInt32(0)).not.toThrow();
|
|
10
10
|
|
|
11
|
-
expect(() => asInt32(1)).not.
|
|
11
|
+
expect(() => asInt32(1)).not.toThrow();
|
|
12
12
|
|
|
13
|
-
expect(() => asInt32(-1)).not.
|
|
13
|
+
expect(() => asInt32(-1)).not.toThrow();
|
|
14
14
|
|
|
15
|
-
expect(() => asInt32(2_147_483_647)).not.
|
|
15
|
+
expect(() => asInt32(2_147_483_647)).not.toThrow(); // 2^31 - 1
|
|
16
16
|
|
|
17
|
-
expect(() => asInt32(-2_147_483_648)).not.
|
|
17
|
+
expect(() => asInt32(-2_147_483_648)).not.toThrow(); // -2^31
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
test('rejects values outside int32 range', () => {
|
|
21
|
-
expect(() => asInt32(2_147_483_648)).
|
|
21
|
+
expect(() => asInt32(2_147_483_648)).toThrow(TypeError); // 2^31
|
|
22
22
|
|
|
23
|
-
expect(() => asInt32(-2_147_483_649)).
|
|
23
|
+
expect(() => asInt32(-2_147_483_649)).toThrow(TypeError); // -2^31 - 1
|
|
24
24
|
|
|
25
|
-
expect(() => asInt32(4_294_967_296)).
|
|
25
|
+
expect(() => asInt32(4_294_967_296)).toThrow(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asInt32(-4_294_967_296)).
|
|
27
|
+
expect(() => asInt32(-4_294_967_296)).toThrow(TypeError);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('rejects non-integers', () => {
|
|
31
|
-
expect(() => asInt32(Number.NaN)).
|
|
31
|
+
expect(() => asInt32(Number.NaN)).toThrow(TypeError);
|
|
32
32
|
|
|
33
|
-
expect(() => asInt32(Number.POSITIVE_INFINITY)).
|
|
33
|
+
expect(() => asInt32(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
34
34
|
|
|
35
|
-
expect(() => asInt32(Number.NEGATIVE_INFINITY)).
|
|
35
|
+
expect(() => asInt32(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
36
36
|
|
|
37
|
-
expect(() => asInt32(1.2)).
|
|
37
|
+
expect(() => asInt32(1.2)).toThrow(TypeError);
|
|
38
38
|
|
|
39
|
-
expect(() => asInt32(-3.4)).
|
|
39
|
+
expect(() => asInt32(-3.4)).toThrow(TypeError);
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
test('returns the same value for valid inputs', () => {
|
|
@@ -58,7 +58,7 @@ describe('Int32 test', () => {
|
|
|
58
58
|
{ name: '1.2', value: 1.2 },
|
|
59
59
|
{ name: '-3.4', value: -3.4 },
|
|
60
60
|
] as const)(`asInt32($name) should throw a TypeError`, ({ value }) => {
|
|
61
|
-
expect(() => asInt32(value)).
|
|
61
|
+
expect(() => asInt32(value)).toThrow(
|
|
62
62
|
new TypeError(`Expected an integer in [-2^31, 2^31), got: ${value}`),
|
|
63
63
|
);
|
|
64
64
|
});
|
|
@@ -9,41 +9,37 @@ import {
|
|
|
9
9
|
describe('NonNegativeFiniteNumber test', () => {
|
|
10
10
|
describe(asNonNegativeFiniteNumber, () => {
|
|
11
11
|
test('accepts valid non-negative finite numbers', () => {
|
|
12
|
-
expect(() => asNonNegativeFiniteNumber(0)).not.
|
|
12
|
+
expect(() => asNonNegativeFiniteNumber(0)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonNegativeFiniteNumber(1)).not.
|
|
14
|
+
expect(() => asNonNegativeFiniteNumber(1)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonNegativeFiniteNumber(3.14)).not.
|
|
16
|
+
expect(() => asNonNegativeFiniteNumber(3.14)).not.toThrow();
|
|
17
17
|
|
|
18
|
-
expect(() => asNonNegativeFiniteNumber(0.5)).not.
|
|
18
|
+
expect(() => asNonNegativeFiniteNumber(0.5)).not.toThrow();
|
|
19
19
|
|
|
20
|
-
expect(() =>
|
|
21
|
-
asNonNegativeFiniteNumber(Number.MAX_VALUE),
|
|
22
|
-
).not.toThrowError();
|
|
20
|
+
expect(() => asNonNegativeFiniteNumber(Number.MAX_VALUE)).not.toThrow();
|
|
23
21
|
});
|
|
24
22
|
|
|
25
23
|
test('rejects negative numbers', () => {
|
|
26
|
-
expect(() => asNonNegativeFiniteNumber(-1)).
|
|
24
|
+
expect(() => asNonNegativeFiniteNumber(-1)).toThrow(TypeError);
|
|
27
25
|
|
|
28
|
-
expect(() => asNonNegativeFiniteNumber(-0.1)).
|
|
26
|
+
expect(() => asNonNegativeFiniteNumber(-0.1)).toThrow(TypeError);
|
|
29
27
|
|
|
30
|
-
expect(() => asNonNegativeFiniteNumber(-Number.MAX_VALUE)).
|
|
28
|
+
expect(() => asNonNegativeFiniteNumber(-Number.MAX_VALUE)).toThrow(
|
|
31
29
|
TypeError,
|
|
32
30
|
);
|
|
33
31
|
});
|
|
34
32
|
|
|
35
33
|
test('rejects non-finite numbers', () => {
|
|
36
|
-
expect(() => asNonNegativeFiniteNumber(Number.NaN)).
|
|
34
|
+
expect(() => asNonNegativeFiniteNumber(Number.NaN)).toThrow(TypeError);
|
|
35
|
+
|
|
36
|
+
expect(() => asNonNegativeFiniteNumber(Number.POSITIVE_INFINITY)).toThrow(
|
|
37
37
|
TypeError,
|
|
38
38
|
);
|
|
39
39
|
|
|
40
|
-
expect(() =>
|
|
41
|
-
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
expect(() =>
|
|
45
|
-
asNonNegativeFiniteNumber(Number.NEGATIVE_INFINITY),
|
|
46
|
-
).toThrowError(TypeError);
|
|
40
|
+
expect(() => asNonNegativeFiniteNumber(Number.NEGATIVE_INFINITY)).toThrow(
|
|
41
|
+
TypeError,
|
|
42
|
+
);
|
|
47
43
|
});
|
|
48
44
|
|
|
49
45
|
test('returns the same value for valid inputs', () => {
|
|
@@ -62,7 +58,7 @@ describe('NonNegativeFiniteNumber test', () => {
|
|
|
62
58
|
] as const)(
|
|
63
59
|
`asNonNegativeFiniteNumber($name) should throw a TypeError`,
|
|
64
60
|
({ value }) => {
|
|
65
|
-
expect(() => asNonNegativeFiniteNumber(value)).
|
|
61
|
+
expect(() => asNonNegativeFiniteNumber(value)).toThrow(
|
|
66
62
|
new TypeError(`Expected a non-negative finite number, got: ${value}`),
|
|
67
63
|
);
|
|
68
64
|
},
|
|
@@ -10,43 +10,43 @@ import { asPositiveInt16 } from './positive-int16.mjs';
|
|
|
10
10
|
describe('NonNegativeInt16 test', () => {
|
|
11
11
|
describe(asNonNegativeInt16, () => {
|
|
12
12
|
test('accepts valid non-negative int16 values', () => {
|
|
13
|
-
expect(() => asNonNegativeInt16(0)).not.
|
|
13
|
+
expect(() => asNonNegativeInt16(0)).not.toThrow();
|
|
14
14
|
|
|
15
|
-
expect(() => asNonNegativeInt16(1)).not.
|
|
15
|
+
expect(() => asNonNegativeInt16(1)).not.toThrow();
|
|
16
16
|
|
|
17
|
-
expect(() => asNonNegativeInt16(1000)).not.
|
|
17
|
+
expect(() => asNonNegativeInt16(1000)).not.toThrow();
|
|
18
18
|
|
|
19
|
-
expect(() => asNonNegativeInt16(32_767)).not.
|
|
19
|
+
expect(() => asNonNegativeInt16(32_767)).not.toThrow(); // 2^15 - 1
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
test('rejects negative integers', () => {
|
|
23
|
-
expect(() => asNonNegativeInt16(-1)).
|
|
23
|
+
expect(() => asNonNegativeInt16(-1)).toThrow(TypeError);
|
|
24
24
|
|
|
25
|
-
expect(() => asNonNegativeInt16(-42)).
|
|
25
|
+
expect(() => asNonNegativeInt16(-42)).toThrow(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asNonNegativeInt16(-32_768)).
|
|
27
|
+
expect(() => asNonNegativeInt16(-32_768)).toThrow(TypeError);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('rejects values outside int16 range', () => {
|
|
31
|
-
expect(() => asNonNegativeInt16(32_768)).
|
|
31
|
+
expect(() => asNonNegativeInt16(32_768)).toThrow(TypeError); // 2^15
|
|
32
32
|
|
|
33
|
-
expect(() => asNonNegativeInt16(65_536)).
|
|
33
|
+
expect(() => asNonNegativeInt16(65_536)).toThrow(TypeError);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('rejects non-integers', () => {
|
|
37
|
-
expect(() => asNonNegativeInt16(Number.NaN)).
|
|
37
|
+
expect(() => asNonNegativeInt16(Number.NaN)).toThrow(TypeError);
|
|
38
38
|
|
|
39
|
-
expect(() => asNonNegativeInt16(Number.POSITIVE_INFINITY)).
|
|
39
|
+
expect(() => asNonNegativeInt16(Number.POSITIVE_INFINITY)).toThrow(
|
|
40
40
|
TypeError,
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
expect(() => asNonNegativeInt16(Number.NEGATIVE_INFINITY)).
|
|
43
|
+
expect(() => asNonNegativeInt16(Number.NEGATIVE_INFINITY)).toThrow(
|
|
44
44
|
TypeError,
|
|
45
45
|
);
|
|
46
46
|
|
|
47
|
-
expect(() => asNonNegativeInt16(1.2)).
|
|
47
|
+
expect(() => asNonNegativeInt16(1.2)).toThrow(TypeError);
|
|
48
48
|
|
|
49
|
-
expect(() => asNonNegativeInt16(-3.4)).
|
|
49
|
+
expect(() => asNonNegativeInt16(-3.4)).toThrow(TypeError);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
test('returns the same value for valid inputs', () => {
|
|
@@ -68,7 +68,7 @@ describe('NonNegativeInt16 test', () => {
|
|
|
68
68
|
] as const)(
|
|
69
69
|
`asNonNegativeInt16($name) should throw a TypeError`,
|
|
70
70
|
({ value }) => {
|
|
71
|
-
expect(() => asNonNegativeInt16(value)).
|
|
71
|
+
expect(() => asNonNegativeInt16(value)).toThrow(
|
|
72
72
|
new TypeError(
|
|
73
73
|
`Expected a non-negative integer in [0, 2^15), got: ${value}`,
|
|
74
74
|
),
|
|
@@ -10,43 +10,43 @@ import { asPositiveInt32 } from './positive-int32.mjs';
|
|
|
10
10
|
describe('NonNegativeInt32 test', () => {
|
|
11
11
|
describe(asNonNegativeInt32, () => {
|
|
12
12
|
test('accepts valid non-negative int32 values', () => {
|
|
13
|
-
expect(() => asNonNegativeInt32(0)).not.
|
|
13
|
+
expect(() => asNonNegativeInt32(0)).not.toThrow();
|
|
14
14
|
|
|
15
|
-
expect(() => asNonNegativeInt32(1)).not.
|
|
15
|
+
expect(() => asNonNegativeInt32(1)).not.toThrow();
|
|
16
16
|
|
|
17
|
-
expect(() => asNonNegativeInt32(1000)).not.
|
|
17
|
+
expect(() => asNonNegativeInt32(1000)).not.toThrow();
|
|
18
18
|
|
|
19
|
-
expect(() => asNonNegativeInt32(2_147_483_647)).not.
|
|
19
|
+
expect(() => asNonNegativeInt32(2_147_483_647)).not.toThrow(); // 2^31 - 1
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
test('rejects negative integers', () => {
|
|
23
|
-
expect(() => asNonNegativeInt32(-1)).
|
|
23
|
+
expect(() => asNonNegativeInt32(-1)).toThrow(TypeError);
|
|
24
24
|
|
|
25
|
-
expect(() => asNonNegativeInt32(-42)).
|
|
25
|
+
expect(() => asNonNegativeInt32(-42)).toThrow(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asNonNegativeInt32(-2_147_483_648)).
|
|
27
|
+
expect(() => asNonNegativeInt32(-2_147_483_648)).toThrow(TypeError);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('rejects values outside int32 range', () => {
|
|
31
|
-
expect(() => asNonNegativeInt32(2_147_483_648)).
|
|
31
|
+
expect(() => asNonNegativeInt32(2_147_483_648)).toThrow(TypeError); // 2^31
|
|
32
32
|
|
|
33
|
-
expect(() => asNonNegativeInt32(4_294_967_296)).
|
|
33
|
+
expect(() => asNonNegativeInt32(4_294_967_296)).toThrow(TypeError);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('rejects non-integers', () => {
|
|
37
|
-
expect(() => asNonNegativeInt32(Number.NaN)).
|
|
37
|
+
expect(() => asNonNegativeInt32(Number.NaN)).toThrow(TypeError);
|
|
38
38
|
|
|
39
|
-
expect(() => asNonNegativeInt32(Number.POSITIVE_INFINITY)).
|
|
39
|
+
expect(() => asNonNegativeInt32(Number.POSITIVE_INFINITY)).toThrow(
|
|
40
40
|
TypeError,
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
expect(() => asNonNegativeInt32(Number.NEGATIVE_INFINITY)).
|
|
43
|
+
expect(() => asNonNegativeInt32(Number.NEGATIVE_INFINITY)).toThrow(
|
|
44
44
|
TypeError,
|
|
45
45
|
);
|
|
46
46
|
|
|
47
|
-
expect(() => asNonNegativeInt32(1.2)).
|
|
47
|
+
expect(() => asNonNegativeInt32(1.2)).toThrow(TypeError);
|
|
48
48
|
|
|
49
|
-
expect(() => asNonNegativeInt32(-3.4)).
|
|
49
|
+
expect(() => asNonNegativeInt32(-3.4)).toThrow(TypeError);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
test('returns the same value for valid inputs', () => {
|
|
@@ -68,7 +68,7 @@ describe('NonNegativeInt32 test', () => {
|
|
|
68
68
|
] as const)(
|
|
69
69
|
`asNonNegativeInt32($name) should throw a TypeError`,
|
|
70
70
|
({ value }) => {
|
|
71
|
-
expect(() => asNonNegativeInt32(value)).
|
|
71
|
+
expect(() => asNonNegativeInt32(value)).toThrow(
|
|
72
72
|
new TypeError(
|
|
73
73
|
`Expected a non-negative integer in [0, 2^31), got: ${value}`,
|
|
74
74
|
),
|
|
@@ -9,39 +9,39 @@ import {
|
|
|
9
9
|
describe('NonZeroFiniteNumber test', () => {
|
|
10
10
|
describe(asNonZeroFiniteNumber, () => {
|
|
11
11
|
test('accepts valid non-zero finite numbers', () => {
|
|
12
|
-
expect(() => asNonZeroFiniteNumber(1)).not.
|
|
12
|
+
expect(() => asNonZeroFiniteNumber(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroFiniteNumber(-1)).not.
|
|
14
|
+
expect(() => asNonZeroFiniteNumber(-1)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroFiniteNumber(3.14)).not.
|
|
16
|
+
expect(() => asNonZeroFiniteNumber(3.14)).not.toThrow();
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroFiniteNumber(-2.5)).not.
|
|
18
|
+
expect(() => asNonZeroFiniteNumber(-2.5)).not.toThrow();
|
|
19
19
|
|
|
20
|
-
expect(() => asNonZeroFiniteNumber(0.001)).not.
|
|
20
|
+
expect(() => asNonZeroFiniteNumber(0.001)).not.toThrow();
|
|
21
21
|
|
|
22
|
-
expect(() => asNonZeroFiniteNumber(-0.001)).not.
|
|
22
|
+
expect(() => asNonZeroFiniteNumber(-0.001)).not.toThrow();
|
|
23
23
|
|
|
24
|
-
expect(() => asNonZeroFiniteNumber(Number.MAX_VALUE)).not.
|
|
24
|
+
expect(() => asNonZeroFiniteNumber(Number.MAX_VALUE)).not.toThrow();
|
|
25
25
|
|
|
26
|
-
expect(() => asNonZeroFiniteNumber(-Number.MAX_VALUE)).not.
|
|
26
|
+
expect(() => asNonZeroFiniteNumber(-Number.MAX_VALUE)).not.toThrow();
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
test('rejects zero', () => {
|
|
30
|
-
expect(() => asNonZeroFiniteNumber(0)).
|
|
30
|
+
expect(() => asNonZeroFiniteNumber(0)).toThrow(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asNonZeroFiniteNumber(-0)).
|
|
32
|
+
expect(() => asNonZeroFiniteNumber(-0)).toThrow(TypeError);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('rejects non-finite numbers', () => {
|
|
36
|
-
expect(() => asNonZeroFiniteNumber(Number.NaN)).
|
|
36
|
+
expect(() => asNonZeroFiniteNumber(Number.NaN)).toThrow(TypeError);
|
|
37
37
|
|
|
38
|
-
expect(() =>
|
|
39
|
-
|
|
40
|
-
)
|
|
38
|
+
expect(() => asNonZeroFiniteNumber(Number.POSITIVE_INFINITY)).toThrow(
|
|
39
|
+
TypeError,
|
|
40
|
+
);
|
|
41
41
|
|
|
42
|
-
expect(() =>
|
|
43
|
-
|
|
44
|
-
)
|
|
42
|
+
expect(() => asNonZeroFiniteNumber(Number.NEGATIVE_INFINITY)).toThrow(
|
|
43
|
+
TypeError,
|
|
44
|
+
);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
test('returns the same value for valid inputs', () => {
|
|
@@ -60,7 +60,7 @@ describe('NonZeroFiniteNumber test', () => {
|
|
|
60
60
|
] as const)(
|
|
61
61
|
`asNonZeroFiniteNumber($name) should throw a TypeError`,
|
|
62
62
|
({ value }) => {
|
|
63
|
-
expect(() => asNonZeroFiniteNumber(value)).
|
|
63
|
+
expect(() => asNonZeroFiniteNumber(value)).toThrow(
|
|
64
64
|
new TypeError(`Expected a non-zero finite number, got: ${value}`),
|
|
65
65
|
);
|
|
66
66
|
},
|
|
@@ -5,39 +5,35 @@ import { asNonZeroInt, isNonZeroInt, NonZeroInt } from './non-zero-int.mjs';
|
|
|
5
5
|
describe('NonZeroInt test', () => {
|
|
6
6
|
describe(asNonZeroInt, () => {
|
|
7
7
|
test('accepts valid non-zero integers', () => {
|
|
8
|
-
expect(() => asNonZeroInt(1)).not.
|
|
8
|
+
expect(() => asNonZeroInt(1)).not.toThrow();
|
|
9
9
|
|
|
10
|
-
expect(() => asNonZeroInt(-1)).not.
|
|
10
|
+
expect(() => asNonZeroInt(-1)).not.toThrow();
|
|
11
11
|
|
|
12
|
-
expect(() => asNonZeroInt(42)).not.
|
|
12
|
+
expect(() => asNonZeroInt(42)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroInt(-42)).not.
|
|
14
|
+
expect(() => asNonZeroInt(-42)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroInt(Number.MAX_SAFE_INTEGER)).not.
|
|
16
|
+
expect(() => asNonZeroInt(Number.MAX_SAFE_INTEGER)).not.toThrow();
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroInt(Number.MIN_SAFE_INTEGER)).not.
|
|
18
|
+
expect(() => asNonZeroInt(Number.MIN_SAFE_INTEGER)).not.toThrow();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('rejects zero', () => {
|
|
22
|
-
expect(() => asNonZeroInt(0)).
|
|
22
|
+
expect(() => asNonZeroInt(0)).toThrow(TypeError);
|
|
23
23
|
|
|
24
|
-
expect(() => asNonZeroInt(-0)).
|
|
24
|
+
expect(() => asNonZeroInt(-0)).toThrow(TypeError);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test('rejects non-integers', () => {
|
|
28
|
-
expect(() => asNonZeroInt(Number.NaN)).
|
|
28
|
+
expect(() => asNonZeroInt(Number.NaN)).toThrow(TypeError);
|
|
29
29
|
|
|
30
|
-
expect(() => asNonZeroInt(Number.POSITIVE_INFINITY)).
|
|
31
|
-
TypeError,
|
|
32
|
-
);
|
|
30
|
+
expect(() => asNonZeroInt(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
33
31
|
|
|
34
|
-
expect(() => asNonZeroInt(Number.NEGATIVE_INFINITY)).
|
|
35
|
-
TypeError,
|
|
36
|
-
);
|
|
32
|
+
expect(() => asNonZeroInt(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
37
33
|
|
|
38
|
-
expect(() => asNonZeroInt(1.2)).
|
|
34
|
+
expect(() => asNonZeroInt(1.2)).toThrow(TypeError);
|
|
39
35
|
|
|
40
|
-
expect(() => asNonZeroInt(-3.4)).
|
|
36
|
+
expect(() => asNonZeroInt(-3.4)).toThrow(TypeError);
|
|
41
37
|
});
|
|
42
38
|
|
|
43
39
|
test('returns the same value for valid inputs', () => {
|
|
@@ -56,7 +52,7 @@ describe('NonZeroInt test', () => {
|
|
|
56
52
|
{ name: '-3.4', value: -3.4 },
|
|
57
53
|
{ name: '0', value: 0 },
|
|
58
54
|
] as const)(`asNonZeroInt($name) should throw a TypeError`, ({ value }) => {
|
|
59
|
-
expect(() => asNonZeroInt(value)).
|
|
55
|
+
expect(() => asNonZeroInt(value)).toThrow(
|
|
60
56
|
new TypeError(`Expected a non-zero integer, got: ${value}`),
|
|
61
57
|
);
|
|
62
58
|
});
|
|
@@ -9,43 +9,39 @@ import {
|
|
|
9
9
|
describe('NonZeroInt16 test', () => {
|
|
10
10
|
describe(asNonZeroInt16, () => {
|
|
11
11
|
test('accepts valid non-zero int16 values', () => {
|
|
12
|
-
expect(() => asNonZeroInt16(1)).not.
|
|
12
|
+
expect(() => asNonZeroInt16(1)).not.toThrow();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroInt16(-1)).not.
|
|
14
|
+
expect(() => asNonZeroInt16(-1)).not.toThrow();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroInt16(32_767)).not.
|
|
16
|
+
expect(() => asNonZeroInt16(32_767)).not.toThrow(); // 2^15 - 1
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroInt16(-32_768)).not.
|
|
18
|
+
expect(() => asNonZeroInt16(-32_768)).not.toThrow(); // -2^15
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('rejects zero', () => {
|
|
22
|
-
expect(() => asNonZeroInt16(0)).
|
|
22
|
+
expect(() => asNonZeroInt16(0)).toThrow(TypeError);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('rejects values outside int16 range', () => {
|
|
26
|
-
expect(() => asNonZeroInt16(32_768)).
|
|
26
|
+
expect(() => asNonZeroInt16(32_768)).toThrow(TypeError); // 2^15
|
|
27
27
|
|
|
28
|
-
expect(() => asNonZeroInt16(-32_769)).
|
|
28
|
+
expect(() => asNonZeroInt16(-32_769)).toThrow(TypeError); // -2^15 - 1
|
|
29
29
|
|
|
30
|
-
expect(() => asNonZeroInt16(65_536)).
|
|
30
|
+
expect(() => asNonZeroInt16(65_536)).toThrow(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asNonZeroInt16(-65_536)).
|
|
32
|
+
expect(() => asNonZeroInt16(-65_536)).toThrow(TypeError);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('rejects non-integers', () => {
|
|
36
|
-
expect(() => asNonZeroInt16(Number.NaN)).
|
|
36
|
+
expect(() => asNonZeroInt16(Number.NaN)).toThrow(TypeError);
|
|
37
37
|
|
|
38
|
-
expect(() => asNonZeroInt16(Number.POSITIVE_INFINITY)).
|
|
39
|
-
TypeError,
|
|
40
|
-
);
|
|
38
|
+
expect(() => asNonZeroInt16(Number.POSITIVE_INFINITY)).toThrow(TypeError);
|
|
41
39
|
|
|
42
|
-
expect(() => asNonZeroInt16(Number.NEGATIVE_INFINITY)).
|
|
43
|
-
TypeError,
|
|
44
|
-
);
|
|
40
|
+
expect(() => asNonZeroInt16(Number.NEGATIVE_INFINITY)).toThrow(TypeError);
|
|
45
41
|
|
|
46
|
-
expect(() => asNonZeroInt16(1.2)).
|
|
42
|
+
expect(() => asNonZeroInt16(1.2)).toThrow(TypeError);
|
|
47
43
|
|
|
48
|
-
expect(() => asNonZeroInt16(-3.4)).
|
|
44
|
+
expect(() => asNonZeroInt16(-3.4)).toThrow(TypeError);
|
|
49
45
|
});
|
|
50
46
|
|
|
51
47
|
test('returns the same value for valid inputs', () => {
|
|
@@ -70,7 +66,7 @@ describe('NonZeroInt16 test', () => {
|
|
|
70
66
|
] as const)(
|
|
71
67
|
`asNonZeroInt16($name) should throw a TypeError`,
|
|
72
68
|
({ value }) => {
|
|
73
|
-
expect(() => asNonZeroInt16(value)).
|
|
69
|
+
expect(() => asNonZeroInt16(value)).toThrow(
|
|
74
70
|
new TypeError(
|
|
75
71
|
`Expected a non-zero integer in [-2^15, 2^15), got: ${value}`,
|
|
76
72
|
),
|