ts-data-forge 5.1.1 → 6.1.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-reducing-value.d.mts +28 -0
- package/dist/array/impl/array-utils-reducing-value.d.mts.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +4 -1
- package/dist/array/impl/array-utils-reducing-value.mjs.map +1 -1
- package/dist/array/impl/index.mjs +1 -1
- package/dist/collections/imap.d.mts +1 -1
- package/dist/collections/iset-mapped.d.mts +1 -1
- package/dist/collections/iset.d.mts +1 -1
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +1 -1
- package/dist/guard/is-record.mjs.map +1 -1
- package/package.json +52 -48
- package/src/array/impl/array-utils-overload-type-error.test.mts +4 -2
- package/src/array/impl/array-utils-reducing-value.mts +48 -0
- package/src/collections/imap.mts +1 -1
- package/src/collections/iset-mapped.mts +1 -1
- package/src/collections/iset.mts +1 -1
- package/src/functional/optional.test.mts +7 -5
- package/src/functional/result.test.mts +10 -8
- package/src/functional/ternary-result.test.mts +4 -4
- package/src/guard/has-key.test.mts +89 -186
- package/src/guard/is-record.mts +1 -2
- package/src/guard/is-record.test.mts +57 -67
- package/src/json/json.test.mts +5 -5
- package/src/number/branded-types/finite-number.test.mts +15 -11
- 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 +19 -15
- 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 +18 -14
- package/src/number/branded-types/non-zero-int16.test.mts +19 -15
- package/src/number/branded-types/non-zero-int32.test.mts +19 -15
- package/src/number/branded-types/non-zero-safe-int.test.mts +22 -18
- 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 +22 -16
- 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 +20 -18
- 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 +21 -17
- package/src/number/branded-types/safe-uint.test.mts +22 -16
- 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/others/memoize-function.test.mts +1 -0
|
@@ -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.toThrowError();
|
|
10
10
|
|
|
11
|
-
expect(() => asInt16(1)).not.
|
|
11
|
+
expect(() => asInt16(1)).not.toThrowError();
|
|
12
12
|
|
|
13
|
-
expect(() => asInt16(-1)).not.
|
|
13
|
+
expect(() => asInt16(-1)).not.toThrowError();
|
|
14
14
|
|
|
15
|
-
expect(() => asInt16(32_767)).not.
|
|
15
|
+
expect(() => asInt16(32_767)).not.toThrowError(); // 2^15 - 1
|
|
16
16
|
|
|
17
|
-
expect(() => asInt16(-32_768)).not.
|
|
17
|
+
expect(() => asInt16(-32_768)).not.toThrowError(); // -2^15
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
test('rejects values outside int16 range', () => {
|
|
21
|
-
expect(() => asInt16(32_768)).
|
|
21
|
+
expect(() => asInt16(32_768)).toThrowError(TypeError); // 2^15
|
|
22
22
|
|
|
23
|
-
expect(() => asInt16(-32_769)).
|
|
23
|
+
expect(() => asInt16(-32_769)).toThrowError(TypeError); // -2^15 - 1
|
|
24
24
|
|
|
25
|
-
expect(() => asInt16(65_536)).
|
|
25
|
+
expect(() => asInt16(65_536)).toThrowError(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asInt16(-65_536)).
|
|
27
|
+
expect(() => asInt16(-65_536)).toThrowError(TypeError);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('rejects non-integers', () => {
|
|
31
|
-
expect(() => asInt16(Number.NaN)).
|
|
31
|
+
expect(() => asInt16(Number.NaN)).toThrowError(TypeError);
|
|
32
32
|
|
|
33
|
-
expect(() => asInt16(Number.POSITIVE_INFINITY)).
|
|
33
|
+
expect(() => asInt16(Number.POSITIVE_INFINITY)).toThrowError(TypeError);
|
|
34
34
|
|
|
35
|
-
expect(() => asInt16(Number.NEGATIVE_INFINITY)).
|
|
35
|
+
expect(() => asInt16(Number.NEGATIVE_INFINITY)).toThrowError(TypeError);
|
|
36
36
|
|
|
37
|
-
expect(() => asInt16(1.2)).
|
|
37
|
+
expect(() => asInt16(1.2)).toThrowError(TypeError);
|
|
38
38
|
|
|
39
|
-
expect(() => asInt16(-3.4)).
|
|
39
|
+
expect(() => asInt16(-3.4)).toThrowError(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)).toThrowError(
|
|
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.toThrowError();
|
|
10
10
|
|
|
11
|
-
expect(() => asInt32(1)).not.
|
|
11
|
+
expect(() => asInt32(1)).not.toThrowError();
|
|
12
12
|
|
|
13
|
-
expect(() => asInt32(-1)).not.
|
|
13
|
+
expect(() => asInt32(-1)).not.toThrowError();
|
|
14
14
|
|
|
15
|
-
expect(() => asInt32(2_147_483_647)).not.
|
|
15
|
+
expect(() => asInt32(2_147_483_647)).not.toThrowError(); // 2^31 - 1
|
|
16
16
|
|
|
17
|
-
expect(() => asInt32(-2_147_483_648)).not.
|
|
17
|
+
expect(() => asInt32(-2_147_483_648)).not.toThrowError(); // -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)).toThrowError(TypeError); // 2^31
|
|
22
22
|
|
|
23
|
-
expect(() => asInt32(-2_147_483_649)).
|
|
23
|
+
expect(() => asInt32(-2_147_483_649)).toThrowError(TypeError); // -2^31 - 1
|
|
24
24
|
|
|
25
|
-
expect(() => asInt32(4_294_967_296)).
|
|
25
|
+
expect(() => asInt32(4_294_967_296)).toThrowError(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asInt32(-4_294_967_296)).
|
|
27
|
+
expect(() => asInt32(-4_294_967_296)).toThrowError(TypeError);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('rejects non-integers', () => {
|
|
31
|
-
expect(() => asInt32(Number.NaN)).
|
|
31
|
+
expect(() => asInt32(Number.NaN)).toThrowError(TypeError);
|
|
32
32
|
|
|
33
|
-
expect(() => asInt32(Number.POSITIVE_INFINITY)).
|
|
33
|
+
expect(() => asInt32(Number.POSITIVE_INFINITY)).toThrowError(TypeError);
|
|
34
34
|
|
|
35
|
-
expect(() => asInt32(Number.NEGATIVE_INFINITY)).
|
|
35
|
+
expect(() => asInt32(Number.NEGATIVE_INFINITY)).toThrowError(TypeError);
|
|
36
36
|
|
|
37
|
-
expect(() => asInt32(1.2)).
|
|
37
|
+
expect(() => asInt32(1.2)).toThrowError(TypeError);
|
|
38
38
|
|
|
39
|
-
expect(() => asInt32(-3.4)).
|
|
39
|
+
expect(() => asInt32(-3.4)).toThrowError(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)).toThrowError(
|
|
62
62
|
new TypeError(`Expected an integer in [-2^31, 2^31), got: ${value}`),
|
|
63
63
|
);
|
|
64
64
|
});
|
|
@@ -9,37 +9,41 @@ 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.toThrowError();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonNegativeFiniteNumber(1)).not.
|
|
14
|
+
expect(() => asNonNegativeFiniteNumber(1)).not.toThrowError();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonNegativeFiniteNumber(3.14)).not.
|
|
16
|
+
expect(() => asNonNegativeFiniteNumber(3.14)).not.toThrowError();
|
|
17
17
|
|
|
18
|
-
expect(() => asNonNegativeFiniteNumber(0.5)).not.
|
|
18
|
+
expect(() => asNonNegativeFiniteNumber(0.5)).not.toThrowError();
|
|
19
19
|
|
|
20
|
-
expect(() =>
|
|
20
|
+
expect(() =>
|
|
21
|
+
asNonNegativeFiniteNumber(Number.MAX_VALUE),
|
|
22
|
+
).not.toThrowError();
|
|
21
23
|
});
|
|
22
24
|
|
|
23
25
|
test('rejects negative numbers', () => {
|
|
24
|
-
expect(() => asNonNegativeFiniteNumber(-1)).
|
|
26
|
+
expect(() => asNonNegativeFiniteNumber(-1)).toThrowError(TypeError);
|
|
25
27
|
|
|
26
|
-
expect(() => asNonNegativeFiniteNumber(-0.1)).
|
|
28
|
+
expect(() => asNonNegativeFiniteNumber(-0.1)).toThrowError(TypeError);
|
|
27
29
|
|
|
28
|
-
expect(() => asNonNegativeFiniteNumber(-Number.MAX_VALUE)).
|
|
30
|
+
expect(() => asNonNegativeFiniteNumber(-Number.MAX_VALUE)).toThrowError(
|
|
29
31
|
TypeError,
|
|
30
32
|
);
|
|
31
33
|
});
|
|
32
34
|
|
|
33
35
|
test('rejects non-finite numbers', () => {
|
|
34
|
-
expect(() => asNonNegativeFiniteNumber(Number.NaN)).
|
|
35
|
-
|
|
36
|
-
expect(() => asNonNegativeFiniteNumber(Number.POSITIVE_INFINITY)).toThrow(
|
|
36
|
+
expect(() => asNonNegativeFiniteNumber(Number.NaN)).toThrowError(
|
|
37
37
|
TypeError,
|
|
38
38
|
);
|
|
39
39
|
|
|
40
|
-
expect(() =>
|
|
41
|
-
|
|
42
|
-
);
|
|
40
|
+
expect(() =>
|
|
41
|
+
asNonNegativeFiniteNumber(Number.POSITIVE_INFINITY),
|
|
42
|
+
).toThrowError(TypeError);
|
|
43
|
+
|
|
44
|
+
expect(() =>
|
|
45
|
+
asNonNegativeFiniteNumber(Number.NEGATIVE_INFINITY),
|
|
46
|
+
).toThrowError(TypeError);
|
|
43
47
|
});
|
|
44
48
|
|
|
45
49
|
test('returns the same value for valid inputs', () => {
|
|
@@ -58,7 +62,7 @@ describe('NonNegativeFiniteNumber test', () => {
|
|
|
58
62
|
] as const)(
|
|
59
63
|
`asNonNegativeFiniteNumber($name) should throw a TypeError`,
|
|
60
64
|
({ value }) => {
|
|
61
|
-
expect(() => asNonNegativeFiniteNumber(value)).
|
|
65
|
+
expect(() => asNonNegativeFiniteNumber(value)).toThrowError(
|
|
62
66
|
new TypeError(`Expected a non-negative finite number, got: ${value}`),
|
|
63
67
|
);
|
|
64
68
|
},
|
|
@@ -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.toThrowError();
|
|
14
14
|
|
|
15
|
-
expect(() => asNonNegativeInt16(1)).not.
|
|
15
|
+
expect(() => asNonNegativeInt16(1)).not.toThrowError();
|
|
16
16
|
|
|
17
|
-
expect(() => asNonNegativeInt16(1000)).not.
|
|
17
|
+
expect(() => asNonNegativeInt16(1000)).not.toThrowError();
|
|
18
18
|
|
|
19
|
-
expect(() => asNonNegativeInt16(32_767)).not.
|
|
19
|
+
expect(() => asNonNegativeInt16(32_767)).not.toThrowError(); // 2^15 - 1
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
test('rejects negative integers', () => {
|
|
23
|
-
expect(() => asNonNegativeInt16(-1)).
|
|
23
|
+
expect(() => asNonNegativeInt16(-1)).toThrowError(TypeError);
|
|
24
24
|
|
|
25
|
-
expect(() => asNonNegativeInt16(-42)).
|
|
25
|
+
expect(() => asNonNegativeInt16(-42)).toThrowError(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asNonNegativeInt16(-32_768)).
|
|
27
|
+
expect(() => asNonNegativeInt16(-32_768)).toThrowError(TypeError);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('rejects values outside int16 range', () => {
|
|
31
|
-
expect(() => asNonNegativeInt16(32_768)).
|
|
31
|
+
expect(() => asNonNegativeInt16(32_768)).toThrowError(TypeError); // 2^15
|
|
32
32
|
|
|
33
|
-
expect(() => asNonNegativeInt16(65_536)).
|
|
33
|
+
expect(() => asNonNegativeInt16(65_536)).toThrowError(TypeError);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('rejects non-integers', () => {
|
|
37
|
-
expect(() => asNonNegativeInt16(Number.NaN)).
|
|
37
|
+
expect(() => asNonNegativeInt16(Number.NaN)).toThrowError(TypeError);
|
|
38
38
|
|
|
39
|
-
expect(() => asNonNegativeInt16(Number.POSITIVE_INFINITY)).
|
|
39
|
+
expect(() => asNonNegativeInt16(Number.POSITIVE_INFINITY)).toThrowError(
|
|
40
40
|
TypeError,
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
expect(() => asNonNegativeInt16(Number.NEGATIVE_INFINITY)).
|
|
43
|
+
expect(() => asNonNegativeInt16(Number.NEGATIVE_INFINITY)).toThrowError(
|
|
44
44
|
TypeError,
|
|
45
45
|
);
|
|
46
46
|
|
|
47
|
-
expect(() => asNonNegativeInt16(1.2)).
|
|
47
|
+
expect(() => asNonNegativeInt16(1.2)).toThrowError(TypeError);
|
|
48
48
|
|
|
49
|
-
expect(() => asNonNegativeInt16(-3.4)).
|
|
49
|
+
expect(() => asNonNegativeInt16(-3.4)).toThrowError(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)).toThrowError(
|
|
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.toThrowError();
|
|
14
14
|
|
|
15
|
-
expect(() => asNonNegativeInt32(1)).not.
|
|
15
|
+
expect(() => asNonNegativeInt32(1)).not.toThrowError();
|
|
16
16
|
|
|
17
|
-
expect(() => asNonNegativeInt32(1000)).not.
|
|
17
|
+
expect(() => asNonNegativeInt32(1000)).not.toThrowError();
|
|
18
18
|
|
|
19
|
-
expect(() => asNonNegativeInt32(2_147_483_647)).not.
|
|
19
|
+
expect(() => asNonNegativeInt32(2_147_483_647)).not.toThrowError(); // 2^31 - 1
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
test('rejects negative integers', () => {
|
|
23
|
-
expect(() => asNonNegativeInt32(-1)).
|
|
23
|
+
expect(() => asNonNegativeInt32(-1)).toThrowError(TypeError);
|
|
24
24
|
|
|
25
|
-
expect(() => asNonNegativeInt32(-42)).
|
|
25
|
+
expect(() => asNonNegativeInt32(-42)).toThrowError(TypeError);
|
|
26
26
|
|
|
27
|
-
expect(() => asNonNegativeInt32(-2_147_483_648)).
|
|
27
|
+
expect(() => asNonNegativeInt32(-2_147_483_648)).toThrowError(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)).toThrowError(TypeError); // 2^31
|
|
32
32
|
|
|
33
|
-
expect(() => asNonNegativeInt32(4_294_967_296)).
|
|
33
|
+
expect(() => asNonNegativeInt32(4_294_967_296)).toThrowError(TypeError);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('rejects non-integers', () => {
|
|
37
|
-
expect(() => asNonNegativeInt32(Number.NaN)).
|
|
37
|
+
expect(() => asNonNegativeInt32(Number.NaN)).toThrowError(TypeError);
|
|
38
38
|
|
|
39
|
-
expect(() => asNonNegativeInt32(Number.POSITIVE_INFINITY)).
|
|
39
|
+
expect(() => asNonNegativeInt32(Number.POSITIVE_INFINITY)).toThrowError(
|
|
40
40
|
TypeError,
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
expect(() => asNonNegativeInt32(Number.NEGATIVE_INFINITY)).
|
|
43
|
+
expect(() => asNonNegativeInt32(Number.NEGATIVE_INFINITY)).toThrowError(
|
|
44
44
|
TypeError,
|
|
45
45
|
);
|
|
46
46
|
|
|
47
|
-
expect(() => asNonNegativeInt32(1.2)).
|
|
47
|
+
expect(() => asNonNegativeInt32(1.2)).toThrowError(TypeError);
|
|
48
48
|
|
|
49
|
-
expect(() => asNonNegativeInt32(-3.4)).
|
|
49
|
+
expect(() => asNonNegativeInt32(-3.4)).toThrowError(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)).toThrowError(
|
|
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.toThrowError();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroFiniteNumber(-1)).not.
|
|
14
|
+
expect(() => asNonZeroFiniteNumber(-1)).not.toThrowError();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroFiniteNumber(3.14)).not.
|
|
16
|
+
expect(() => asNonZeroFiniteNumber(3.14)).not.toThrowError();
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroFiniteNumber(-2.5)).not.
|
|
18
|
+
expect(() => asNonZeroFiniteNumber(-2.5)).not.toThrowError();
|
|
19
19
|
|
|
20
|
-
expect(() => asNonZeroFiniteNumber(0.001)).not.
|
|
20
|
+
expect(() => asNonZeroFiniteNumber(0.001)).not.toThrowError();
|
|
21
21
|
|
|
22
|
-
expect(() => asNonZeroFiniteNumber(-0.001)).not.
|
|
22
|
+
expect(() => asNonZeroFiniteNumber(-0.001)).not.toThrowError();
|
|
23
23
|
|
|
24
|
-
expect(() => asNonZeroFiniteNumber(Number.MAX_VALUE)).not.
|
|
24
|
+
expect(() => asNonZeroFiniteNumber(Number.MAX_VALUE)).not.toThrowError();
|
|
25
25
|
|
|
26
|
-
expect(() => asNonZeroFiniteNumber(-Number.MAX_VALUE)).not.
|
|
26
|
+
expect(() => asNonZeroFiniteNumber(-Number.MAX_VALUE)).not.toThrowError();
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
test('rejects zero', () => {
|
|
30
|
-
expect(() => asNonZeroFiniteNumber(0)).
|
|
30
|
+
expect(() => asNonZeroFiniteNumber(0)).toThrowError(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asNonZeroFiniteNumber(-0)).
|
|
32
|
+
expect(() => asNonZeroFiniteNumber(-0)).toThrowError(TypeError);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('rejects non-finite numbers', () => {
|
|
36
|
-
expect(() => asNonZeroFiniteNumber(Number.NaN)).
|
|
36
|
+
expect(() => asNonZeroFiniteNumber(Number.NaN)).toThrowError(TypeError);
|
|
37
37
|
|
|
38
|
-
expect(() =>
|
|
39
|
-
|
|
40
|
-
);
|
|
38
|
+
expect(() =>
|
|
39
|
+
asNonZeroFiniteNumber(Number.POSITIVE_INFINITY),
|
|
40
|
+
).toThrowError(TypeError);
|
|
41
41
|
|
|
42
|
-
expect(() =>
|
|
43
|
-
|
|
44
|
-
);
|
|
42
|
+
expect(() =>
|
|
43
|
+
asNonZeroFiniteNumber(Number.NEGATIVE_INFINITY),
|
|
44
|
+
).toThrowError(TypeError);
|
|
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)).toThrowError(
|
|
64
64
|
new TypeError(`Expected a non-zero finite number, got: ${value}`),
|
|
65
65
|
);
|
|
66
66
|
},
|
|
@@ -5,35 +5,39 @@ 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.toThrowError();
|
|
9
9
|
|
|
10
|
-
expect(() => asNonZeroInt(-1)).not.
|
|
10
|
+
expect(() => asNonZeroInt(-1)).not.toThrowError();
|
|
11
11
|
|
|
12
|
-
expect(() => asNonZeroInt(42)).not.
|
|
12
|
+
expect(() => asNonZeroInt(42)).not.toThrowError();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroInt(-42)).not.
|
|
14
|
+
expect(() => asNonZeroInt(-42)).not.toThrowError();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroInt(Number.MAX_SAFE_INTEGER)).not.
|
|
16
|
+
expect(() => asNonZeroInt(Number.MAX_SAFE_INTEGER)).not.toThrowError();
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroInt(Number.MIN_SAFE_INTEGER)).not.
|
|
18
|
+
expect(() => asNonZeroInt(Number.MIN_SAFE_INTEGER)).not.toThrowError();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('rejects zero', () => {
|
|
22
|
-
expect(() => asNonZeroInt(0)).
|
|
22
|
+
expect(() => asNonZeroInt(0)).toThrowError(TypeError);
|
|
23
23
|
|
|
24
|
-
expect(() => asNonZeroInt(-0)).
|
|
24
|
+
expect(() => asNonZeroInt(-0)).toThrowError(TypeError);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test('rejects non-integers', () => {
|
|
28
|
-
expect(() => asNonZeroInt(Number.NaN)).
|
|
28
|
+
expect(() => asNonZeroInt(Number.NaN)).toThrowError(TypeError);
|
|
29
29
|
|
|
30
|
-
expect(() => asNonZeroInt(Number.POSITIVE_INFINITY)).
|
|
30
|
+
expect(() => asNonZeroInt(Number.POSITIVE_INFINITY)).toThrowError(
|
|
31
|
+
TypeError,
|
|
32
|
+
);
|
|
31
33
|
|
|
32
|
-
expect(() => asNonZeroInt(Number.NEGATIVE_INFINITY)).
|
|
34
|
+
expect(() => asNonZeroInt(Number.NEGATIVE_INFINITY)).toThrowError(
|
|
35
|
+
TypeError,
|
|
36
|
+
);
|
|
33
37
|
|
|
34
|
-
expect(() => asNonZeroInt(1.2)).
|
|
38
|
+
expect(() => asNonZeroInt(1.2)).toThrowError(TypeError);
|
|
35
39
|
|
|
36
|
-
expect(() => asNonZeroInt(-3.4)).
|
|
40
|
+
expect(() => asNonZeroInt(-3.4)).toThrowError(TypeError);
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
test('returns the same value for valid inputs', () => {
|
|
@@ -52,7 +56,7 @@ describe('NonZeroInt test', () => {
|
|
|
52
56
|
{ name: '-3.4', value: -3.4 },
|
|
53
57
|
{ name: '0', value: 0 },
|
|
54
58
|
] as const)(`asNonZeroInt($name) should throw a TypeError`, ({ value }) => {
|
|
55
|
-
expect(() => asNonZeroInt(value)).
|
|
59
|
+
expect(() => asNonZeroInt(value)).toThrowError(
|
|
56
60
|
new TypeError(`Expected a non-zero integer, got: ${value}`),
|
|
57
61
|
);
|
|
58
62
|
});
|
|
@@ -9,39 +9,43 @@ 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.toThrowError();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroInt16(-1)).not.
|
|
14
|
+
expect(() => asNonZeroInt16(-1)).not.toThrowError();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroInt16(32_767)).not.
|
|
16
|
+
expect(() => asNonZeroInt16(32_767)).not.toThrowError(); // 2^15 - 1
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroInt16(-32_768)).not.
|
|
18
|
+
expect(() => asNonZeroInt16(-32_768)).not.toThrowError(); // -2^15
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('rejects zero', () => {
|
|
22
|
-
expect(() => asNonZeroInt16(0)).
|
|
22
|
+
expect(() => asNonZeroInt16(0)).toThrowError(TypeError);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('rejects values outside int16 range', () => {
|
|
26
|
-
expect(() => asNonZeroInt16(32_768)).
|
|
26
|
+
expect(() => asNonZeroInt16(32_768)).toThrowError(TypeError); // 2^15
|
|
27
27
|
|
|
28
|
-
expect(() => asNonZeroInt16(-32_769)).
|
|
28
|
+
expect(() => asNonZeroInt16(-32_769)).toThrowError(TypeError); // -2^15 - 1
|
|
29
29
|
|
|
30
|
-
expect(() => asNonZeroInt16(65_536)).
|
|
30
|
+
expect(() => asNonZeroInt16(65_536)).toThrowError(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asNonZeroInt16(-65_536)).
|
|
32
|
+
expect(() => asNonZeroInt16(-65_536)).toThrowError(TypeError);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('rejects non-integers', () => {
|
|
36
|
-
expect(() => asNonZeroInt16(Number.NaN)).
|
|
36
|
+
expect(() => asNonZeroInt16(Number.NaN)).toThrowError(TypeError);
|
|
37
37
|
|
|
38
|
-
expect(() => asNonZeroInt16(Number.POSITIVE_INFINITY)).
|
|
38
|
+
expect(() => asNonZeroInt16(Number.POSITIVE_INFINITY)).toThrowError(
|
|
39
|
+
TypeError,
|
|
40
|
+
);
|
|
39
41
|
|
|
40
|
-
expect(() => asNonZeroInt16(Number.NEGATIVE_INFINITY)).
|
|
42
|
+
expect(() => asNonZeroInt16(Number.NEGATIVE_INFINITY)).toThrowError(
|
|
43
|
+
TypeError,
|
|
44
|
+
);
|
|
41
45
|
|
|
42
|
-
expect(() => asNonZeroInt16(1.2)).
|
|
46
|
+
expect(() => asNonZeroInt16(1.2)).toThrowError(TypeError);
|
|
43
47
|
|
|
44
|
-
expect(() => asNonZeroInt16(-3.4)).
|
|
48
|
+
expect(() => asNonZeroInt16(-3.4)).toThrowError(TypeError);
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
test('returns the same value for valid inputs', () => {
|
|
@@ -66,7 +70,7 @@ describe('NonZeroInt16 test', () => {
|
|
|
66
70
|
] as const)(
|
|
67
71
|
`asNonZeroInt16($name) should throw a TypeError`,
|
|
68
72
|
({ value }) => {
|
|
69
|
-
expect(() => asNonZeroInt16(value)).
|
|
73
|
+
expect(() => asNonZeroInt16(value)).toThrowError(
|
|
70
74
|
new TypeError(
|
|
71
75
|
`Expected a non-zero integer in [-2^15, 2^15), got: ${value}`,
|
|
72
76
|
),
|
|
@@ -9,39 +9,43 @@ 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.toThrowError();
|
|
13
13
|
|
|
14
|
-
expect(() => asNonZeroInt32(-1)).not.
|
|
14
|
+
expect(() => asNonZeroInt32(-1)).not.toThrowError();
|
|
15
15
|
|
|
16
|
-
expect(() => asNonZeroInt32(2_147_483_647)).not.
|
|
16
|
+
expect(() => asNonZeroInt32(2_147_483_647)).not.toThrowError(); // 2^31 - 1
|
|
17
17
|
|
|
18
|
-
expect(() => asNonZeroInt32(-2_147_483_648)).not.
|
|
18
|
+
expect(() => asNonZeroInt32(-2_147_483_648)).not.toThrowError(); // -2^31
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test('rejects zero', () => {
|
|
22
|
-
expect(() => asNonZeroInt32(0)).
|
|
22
|
+
expect(() => asNonZeroInt32(0)).toThrowError(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)).toThrowError(TypeError); // 2^31
|
|
27
27
|
|
|
28
|
-
expect(() => asNonZeroInt32(-2_147_483_649)).
|
|
28
|
+
expect(() => asNonZeroInt32(-2_147_483_649)).toThrowError(TypeError); // -2^31 - 1
|
|
29
29
|
|
|
30
|
-
expect(() => asNonZeroInt32(4_294_967_296)).
|
|
30
|
+
expect(() => asNonZeroInt32(4_294_967_296)).toThrowError(TypeError);
|
|
31
31
|
|
|
32
|
-
expect(() => asNonZeroInt32(-4_294_967_296)).
|
|
32
|
+
expect(() => asNonZeroInt32(-4_294_967_296)).toThrowError(TypeError);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('rejects non-integers', () => {
|
|
36
|
-
expect(() => asNonZeroInt32(Number.NaN)).
|
|
36
|
+
expect(() => asNonZeroInt32(Number.NaN)).toThrowError(TypeError);
|
|
37
37
|
|
|
38
|
-
expect(() => asNonZeroInt32(Number.POSITIVE_INFINITY)).
|
|
38
|
+
expect(() => asNonZeroInt32(Number.POSITIVE_INFINITY)).toThrowError(
|
|
39
|
+
TypeError,
|
|
40
|
+
);
|
|
39
41
|
|
|
40
|
-
expect(() => asNonZeroInt32(Number.NEGATIVE_INFINITY)).
|
|
42
|
+
expect(() => asNonZeroInt32(Number.NEGATIVE_INFINITY)).toThrowError(
|
|
43
|
+
TypeError,
|
|
44
|
+
);
|
|
41
45
|
|
|
42
|
-
expect(() => asNonZeroInt32(1.2)).
|
|
46
|
+
expect(() => asNonZeroInt32(1.2)).toThrowError(TypeError);
|
|
43
47
|
|
|
44
|
-
expect(() => asNonZeroInt32(-3.4)).
|
|
48
|
+
expect(() => asNonZeroInt32(-3.4)).toThrowError(TypeError);
|
|
45
49
|
});
|
|
46
50
|
|
|
47
51
|
test('returns the same value for valid inputs', () => {
|
|
@@ -66,7 +70,7 @@ describe('NonZeroInt32 test', () => {
|
|
|
66
70
|
] as const)(
|
|
67
71
|
`asNonZeroInt32($name) should throw a TypeError`,
|
|
68
72
|
({ value }) => {
|
|
69
|
-
expect(() => asNonZeroInt32(value)).
|
|
73
|
+
expect(() => asNonZeroInt32(value)).toThrowError(
|
|
70
74
|
new TypeError(
|
|
71
75
|
`Expected a non-zero integer in [-2^31, 2^31), got: ${value}`,
|
|
72
76
|
),
|