ts-data-forge 1.0.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/LICENSE +201 -0
- package/README.md +534 -0
- package/package.json +101 -0
- package/src/array/array-utils-creation.test.mts +443 -0
- package/src/array/array-utils-modification.test.mts +197 -0
- package/src/array/array-utils-overload-type-error.test.mts +149 -0
- package/src/array/array-utils-reducing-value.test.mts +425 -0
- package/src/array/array-utils-search.test.mts +169 -0
- package/src/array/array-utils-set-op.test.mts +335 -0
- package/src/array/array-utils-slice-clamped.test.mts +113 -0
- package/src/array/array-utils-slicing.test.mts +316 -0
- package/src/array/array-utils-transformation.test.mts +790 -0
- package/src/array/array-utils-validation.test.mts +492 -0
- package/src/array/array-utils.mts +4000 -0
- package/src/array/array.test.mts +146 -0
- package/src/array/index.mts +2 -0
- package/src/array/tuple-utils.mts +519 -0
- package/src/array/tuple-utils.test.mts +518 -0
- package/src/collections/imap-mapped.mts +801 -0
- package/src/collections/imap-mapped.test.mts +860 -0
- package/src/collections/imap.mts +651 -0
- package/src/collections/imap.test.mts +932 -0
- package/src/collections/index.mts +6 -0
- package/src/collections/iset-mapped.mts +889 -0
- package/src/collections/iset-mapped.test.mts +1187 -0
- package/src/collections/iset.mts +682 -0
- package/src/collections/iset.test.mts +1084 -0
- package/src/collections/queue.mts +390 -0
- package/src/collections/queue.test.mts +282 -0
- package/src/collections/stack.mts +423 -0
- package/src/collections/stack.test.mts +225 -0
- package/src/expect-type.mts +206 -0
- package/src/functional/index.mts +4 -0
- package/src/functional/match.mts +300 -0
- package/src/functional/match.test.mts +177 -0
- package/src/functional/optional.mts +733 -0
- package/src/functional/optional.test.mts +619 -0
- package/src/functional/pipe.mts +212 -0
- package/src/functional/pipe.test.mts +85 -0
- package/src/functional/result.mts +1134 -0
- package/src/functional/result.test.mts +777 -0
- package/src/globals.d.mts +38 -0
- package/src/guard/has-key.mts +119 -0
- package/src/guard/has-key.test.mts +219 -0
- package/src/guard/index.mts +7 -0
- package/src/guard/is-non-empty-string.mts +108 -0
- package/src/guard/is-non-empty-string.test.mts +91 -0
- package/src/guard/is-non-null-object.mts +106 -0
- package/src/guard/is-non-null-object.test.mts +90 -0
- package/src/guard/is-primitive.mts +165 -0
- package/src/guard/is-primitive.test.mts +102 -0
- package/src/guard/is-record.mts +153 -0
- package/src/guard/is-record.test.mts +112 -0
- package/src/guard/is-type.mts +450 -0
- package/src/guard/is-type.test.mts +496 -0
- package/src/guard/key-is-in.mts +163 -0
- package/src/guard/key-is-in.test.mts +19 -0
- package/src/index.mts +10 -0
- package/src/iterator/index.mts +1 -0
- package/src/iterator/range.mts +120 -0
- package/src/iterator/range.test.mts +33 -0
- package/src/json/index.mts +1 -0
- package/src/json/json.mts +711 -0
- package/src/json/json.test.mts +628 -0
- package/src/number/branded-types/finite-number.mts +354 -0
- package/src/number/branded-types/finite-number.test.mts +135 -0
- package/src/number/branded-types/index.mts +26 -0
- package/src/number/branded-types/int.mts +278 -0
- package/src/number/branded-types/int.test.mts +140 -0
- package/src/number/branded-types/int16.mts +192 -0
- package/src/number/branded-types/int16.test.mts +170 -0
- package/src/number/branded-types/int32.mts +193 -0
- package/src/number/branded-types/int32.test.mts +170 -0
- package/src/number/branded-types/non-negative-finite-number.mts +223 -0
- package/src/number/branded-types/non-negative-finite-number.test.mts +188 -0
- package/src/number/branded-types/non-negative-int16.mts +187 -0
- package/src/number/branded-types/non-negative-int16.test.mts +201 -0
- package/src/number/branded-types/non-negative-int32.mts +187 -0
- package/src/number/branded-types/non-negative-int32.test.mts +204 -0
- package/src/number/branded-types/non-zero-finite-number.mts +229 -0
- package/src/number/branded-types/non-zero-finite-number.test.mts +198 -0
- package/src/number/branded-types/non-zero-int.mts +167 -0
- package/src/number/branded-types/non-zero-int.test.mts +177 -0
- package/src/number/branded-types/non-zero-int16.mts +196 -0
- package/src/number/branded-types/non-zero-int16.test.mts +195 -0
- package/src/number/branded-types/non-zero-int32.mts +196 -0
- package/src/number/branded-types/non-zero-int32.test.mts +197 -0
- package/src/number/branded-types/non-zero-safe-int.mts +196 -0
- package/src/number/branded-types/non-zero-safe-int.test.mts +232 -0
- package/src/number/branded-types/non-zero-uint16.mts +189 -0
- package/src/number/branded-types/non-zero-uint16.test.mts +199 -0
- package/src/number/branded-types/non-zero-uint32.mts +189 -0
- package/src/number/branded-types/non-zero-uint32.test.mts +199 -0
- package/src/number/branded-types/positive-finite-number.mts +241 -0
- package/src/number/branded-types/positive-finite-number.test.mts +204 -0
- package/src/number/branded-types/positive-int.mts +304 -0
- package/src/number/branded-types/positive-int.test.mts +176 -0
- package/src/number/branded-types/positive-int16.mts +188 -0
- package/src/number/branded-types/positive-int16.test.mts +197 -0
- package/src/number/branded-types/positive-int32.mts +188 -0
- package/src/number/branded-types/positive-int32.test.mts +197 -0
- package/src/number/branded-types/positive-safe-int.mts +187 -0
- package/src/number/branded-types/positive-safe-int.test.mts +210 -0
- package/src/number/branded-types/positive-uint16.mts +188 -0
- package/src/number/branded-types/positive-uint16.test.mts +203 -0
- package/src/number/branded-types/positive-uint32.mts +188 -0
- package/src/number/branded-types/positive-uint32.test.mts +203 -0
- package/src/number/branded-types/safe-int.mts +291 -0
- package/src/number/branded-types/safe-int.test.mts +170 -0
- package/src/number/branded-types/safe-uint.mts +187 -0
- package/src/number/branded-types/safe-uint.test.mts +176 -0
- package/src/number/branded-types/uint.mts +179 -0
- package/src/number/branded-types/uint.test.mts +158 -0
- package/src/number/branded-types/uint16.mts +186 -0
- package/src/number/branded-types/uint16.test.mts +170 -0
- package/src/number/branded-types/uint32.mts +218 -0
- package/src/number/branded-types/uint32.test.mts +170 -0
- package/src/number/enum/index.mts +2 -0
- package/src/number/enum/int8.mts +344 -0
- package/src/number/enum/int8.test.mts +180 -0
- package/src/number/enum/uint8.mts +293 -0
- package/src/number/enum/uint8.test.mts +164 -0
- package/src/number/index.mts +4 -0
- package/src/number/num.mts +604 -0
- package/src/number/num.test.mts +242 -0
- package/src/number/refined-number-utils.mts +566 -0
- package/src/object/index.mts +1 -0
- package/src/object/object.mts +447 -0
- package/src/object/object.test.mts +124 -0
- package/src/others/cast-mutable.mts +113 -0
- package/src/others/cast-readonly.mts +192 -0
- package/src/others/cast-readonly.test.mts +89 -0
- package/src/others/if-then.mts +98 -0
- package/src/others/if-then.test.mts +75 -0
- package/src/others/index.mts +7 -0
- package/src/others/map-nullable.mts +172 -0
- package/src/others/map-nullable.test.mts +297 -0
- package/src/others/memoize-function.mts +196 -0
- package/src/others/memoize-function.test.mts +168 -0
- package/src/others/tuple.mts +160 -0
- package/src/others/tuple.test.mts +11 -0
- package/src/others/unknown-to-string.mts +215 -0
- package/src/others/unknown-to-string.test.mts +114 -0
|
@@ -0,0 +1,932 @@
|
|
|
1
|
+
import { Optional } from '../functional/index.mjs';
|
|
2
|
+
import { IMap } from './imap.mjs';
|
|
3
|
+
|
|
4
|
+
describe('IMap[Symbol.iterator]', () => {
|
|
5
|
+
test('case 1', () => {
|
|
6
|
+
const m0 = IMap.create(
|
|
7
|
+
IMap.create([
|
|
8
|
+
[1, 10],
|
|
9
|
+
[2, 20],
|
|
10
|
+
[3, 30],
|
|
11
|
+
] as const),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(m0).toStrictEqual(
|
|
15
|
+
IMap.create([
|
|
16
|
+
[1, 10],
|
|
17
|
+
[2, 20],
|
|
18
|
+
[3, 30],
|
|
19
|
+
] as const),
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('should work with for-of loops', () => {
|
|
24
|
+
const map = IMap.create([
|
|
25
|
+
['a', 1],
|
|
26
|
+
['b', 2],
|
|
27
|
+
]);
|
|
28
|
+
const collected: [string, number][] = [];
|
|
29
|
+
|
|
30
|
+
for (const entry of map) {
|
|
31
|
+
collected.push([...entry]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expect(collected).toHaveLength(2);
|
|
35
|
+
expect(collected).toContainEqual(['a', 1]);
|
|
36
|
+
expect(collected).toContainEqual(['b', 2]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should work with spread operator', () => {
|
|
40
|
+
const map = IMap.create([
|
|
41
|
+
['a', 1],
|
|
42
|
+
['b', 2],
|
|
43
|
+
]);
|
|
44
|
+
const entries = [...map];
|
|
45
|
+
|
|
46
|
+
expect(entries).toHaveLength(2);
|
|
47
|
+
expect(entries).toContainEqual(['a', 1]);
|
|
48
|
+
expect(entries).toContainEqual(['b', 2]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('should work with Array.from', () => {
|
|
52
|
+
const map = IMap.create([
|
|
53
|
+
['a', 1],
|
|
54
|
+
['b', 2],
|
|
55
|
+
]);
|
|
56
|
+
const entries = Array.from(map);
|
|
57
|
+
|
|
58
|
+
expect(entries).toHaveLength(2);
|
|
59
|
+
expect(entries).toContainEqual(['a', 1]);
|
|
60
|
+
expect(entries).toContainEqual(['b', 2]);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('IMap.create', () => {
|
|
65
|
+
test('should create empty map', () => {
|
|
66
|
+
const map = IMap.create<string, number>([]);
|
|
67
|
+
expect(map.size).toBe(0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('should create map from JavaScript Map', () => {
|
|
71
|
+
const jsMap = new Map([
|
|
72
|
+
['a', 1],
|
|
73
|
+
['b', 2],
|
|
74
|
+
]);
|
|
75
|
+
const map = IMap.create(jsMap);
|
|
76
|
+
expect(map.size).toBe(2);
|
|
77
|
+
expect(Optional.unwrap(map.get('a'))).toBe(1);
|
|
78
|
+
expect(Optional.unwrap(map.get('b'))).toBe(2);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('should create map from another IMap', () => {
|
|
82
|
+
const original = IMap.create([
|
|
83
|
+
['a', 1],
|
|
84
|
+
['b', 2],
|
|
85
|
+
]);
|
|
86
|
+
const copy = IMap.create(original);
|
|
87
|
+
expect(copy.size).toBe(2);
|
|
88
|
+
expect(Optional.unwrap(copy.get('a'))).toBe(1);
|
|
89
|
+
expect(Optional.unwrap(copy.get('b'))).toBe(2);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('IMap.equal', () => {
|
|
94
|
+
test('should return false for different maps (implementation bug)', () => {
|
|
95
|
+
// Note: IMap.equal has a bug - it compares Optional<V> with V directly
|
|
96
|
+
// This is expected behavior given the current implementation
|
|
97
|
+
const map1 = IMap.create([
|
|
98
|
+
['a', 1],
|
|
99
|
+
['b', 2],
|
|
100
|
+
]);
|
|
101
|
+
const map2 = IMap.create([
|
|
102
|
+
['a', 1],
|
|
103
|
+
['b', 2],
|
|
104
|
+
]);
|
|
105
|
+
expect(IMap.equal(map1, map2)).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('should return false for different creation order (implementation bug)', () => {
|
|
109
|
+
// Note: IMap.equal has a bug - it compares Optional<V> with V directly
|
|
110
|
+
const map1 = IMap.create([
|
|
111
|
+
['a', 1],
|
|
112
|
+
['b', 2],
|
|
113
|
+
]);
|
|
114
|
+
const map2 = IMap.create([
|
|
115
|
+
['b', 2],
|
|
116
|
+
['a', 1],
|
|
117
|
+
]);
|
|
118
|
+
expect(IMap.equal(map1, map2)).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('should return false for maps with different sizes', () => {
|
|
122
|
+
const map1 = IMap.create<'a' | 'b', number>([['a', 1]]);
|
|
123
|
+
const map2 = IMap.create([
|
|
124
|
+
['a', 1],
|
|
125
|
+
['b', 2],
|
|
126
|
+
]);
|
|
127
|
+
expect(IMap.equal(map1, map2)).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('should return false for maps with different values', () => {
|
|
131
|
+
const map1 = IMap.create([
|
|
132
|
+
['a', 1],
|
|
133
|
+
['b', 2],
|
|
134
|
+
]);
|
|
135
|
+
const map2 = IMap.create([
|
|
136
|
+
['a', 1],
|
|
137
|
+
['b', 3],
|
|
138
|
+
]);
|
|
139
|
+
expect(IMap.equal(map1, map2)).toBe(false);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('should return false for maps with different keys', () => {
|
|
143
|
+
const map1 = IMap.create<'a' | 'b' | 'c', number>([
|
|
144
|
+
['a', 1],
|
|
145
|
+
['b', 2],
|
|
146
|
+
]);
|
|
147
|
+
const map2 = IMap.create<'a' | 'b' | 'c', number>([
|
|
148
|
+
['a', 1],
|
|
149
|
+
['c', 2],
|
|
150
|
+
]);
|
|
151
|
+
expect(IMap.equal(map1, map2)).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('should return true for empty maps', () => {
|
|
155
|
+
const map1 = IMap.create<string, number>([]);
|
|
156
|
+
const map2 = IMap.create<string, number>([]);
|
|
157
|
+
expect(IMap.equal(map1, map2)).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('IMap.size', () => {
|
|
162
|
+
test('case 1', () => {
|
|
163
|
+
const m0 = IMap.create([
|
|
164
|
+
[1, 10],
|
|
165
|
+
[2, 20],
|
|
166
|
+
[3, 30],
|
|
167
|
+
] as const);
|
|
168
|
+
|
|
169
|
+
expect(m0.size).toBe(3);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe('IMap.has', () => {
|
|
174
|
+
test('case 1', () => {
|
|
175
|
+
const m0 = IMap.create([
|
|
176
|
+
[1, 10],
|
|
177
|
+
[3, 30],
|
|
178
|
+
[5, 50],
|
|
179
|
+
[6, 60],
|
|
180
|
+
[7, 70],
|
|
181
|
+
] as const);
|
|
182
|
+
|
|
183
|
+
expect(m0.has(6)).toBe(true);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('case 2', () => {
|
|
187
|
+
const m0 = IMap.create<number, number>([
|
|
188
|
+
[1, 10],
|
|
189
|
+
[3, 30],
|
|
190
|
+
[5, 50],
|
|
191
|
+
[6, 60],
|
|
192
|
+
[7, 70],
|
|
193
|
+
]);
|
|
194
|
+
|
|
195
|
+
expect(m0.has(8)).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('case 3', () => {
|
|
199
|
+
const m0 = IMap.create<number, number>([]);
|
|
200
|
+
|
|
201
|
+
expect(m0.has(0)).toBe(false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test('case 4', () => {
|
|
205
|
+
const m0 = IMap.create<number, number>([
|
|
206
|
+
[1, 10],
|
|
207
|
+
[3, 30],
|
|
208
|
+
[5, 50],
|
|
209
|
+
[6, 60],
|
|
210
|
+
[7, 70],
|
|
211
|
+
[Number.NaN, 0],
|
|
212
|
+
] as const);
|
|
213
|
+
|
|
214
|
+
expect(m0.has(Number.NaN)).toBe(true);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('should handle boolean keys', () => {
|
|
218
|
+
const map = IMap.create([
|
|
219
|
+
[true, 'yes'],
|
|
220
|
+
[false, 'no'],
|
|
221
|
+
]);
|
|
222
|
+
expect(map.has(true)).toBe(true);
|
|
223
|
+
expect(map.has(false)).toBe(true);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('should handle string number keys', () => {
|
|
227
|
+
const map = IMap.create([
|
|
228
|
+
['1', 'one'],
|
|
229
|
+
['2', 'two'],
|
|
230
|
+
]);
|
|
231
|
+
expect(map.has('1')).toBe(true);
|
|
232
|
+
expect(map.has(String(1))).toBe(true);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('IMap.get', () => {
|
|
237
|
+
test('case 1', () => {
|
|
238
|
+
const m0 = IMap.create([
|
|
239
|
+
[1, 10],
|
|
240
|
+
[3, 30],
|
|
241
|
+
[5, 50],
|
|
242
|
+
[6, 60],
|
|
243
|
+
[7, 70],
|
|
244
|
+
] as const);
|
|
245
|
+
|
|
246
|
+
expect(m0.get(6)).toStrictEqual(Optional.some(60));
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('case 2', () => {
|
|
250
|
+
const m0 = IMap.create<number, number>([
|
|
251
|
+
[1, 10],
|
|
252
|
+
[3, 30],
|
|
253
|
+
[5, 50],
|
|
254
|
+
[6, 60],
|
|
255
|
+
[7, 70],
|
|
256
|
+
]);
|
|
257
|
+
|
|
258
|
+
expect(m0.get(8)).toStrictEqual(Optional.none);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('case 3', () => {
|
|
262
|
+
const m0 = IMap.create<number, number>([]);
|
|
263
|
+
|
|
264
|
+
expect(m0.get(0)).toStrictEqual(Optional.none);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test('case 4', () => {
|
|
268
|
+
const m0 = IMap.create<number, number>([
|
|
269
|
+
[1, 10],
|
|
270
|
+
[3, 30],
|
|
271
|
+
[5, 50],
|
|
272
|
+
[6, 60],
|
|
273
|
+
[7, 70],
|
|
274
|
+
[Number.NaN, 100],
|
|
275
|
+
] as const);
|
|
276
|
+
|
|
277
|
+
expect(m0.get(Number.NaN)).toStrictEqual(Optional.some(100));
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test('should handle undefined and null values', () => {
|
|
281
|
+
const map = IMap.create([
|
|
282
|
+
['undef', undefined],
|
|
283
|
+
['null', null],
|
|
284
|
+
]);
|
|
285
|
+
expect(Optional.unwrap(map.get('undef'))).toBe(undefined);
|
|
286
|
+
expect(Optional.unwrap(map.get('null'))).toBe(null);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe('IMap.set', () => {
|
|
291
|
+
test('case 1', () => {
|
|
292
|
+
const m0 = IMap.create<number, number>([
|
|
293
|
+
[1, 10],
|
|
294
|
+
[3, 30],
|
|
295
|
+
[5, 50],
|
|
296
|
+
[6, 60],
|
|
297
|
+
[7, 70],
|
|
298
|
+
]);
|
|
299
|
+
|
|
300
|
+
expect(m0.set(9, 90)).toStrictEqual(
|
|
301
|
+
IMap.create([
|
|
302
|
+
[1, 10],
|
|
303
|
+
[3, 30],
|
|
304
|
+
[5, 50],
|
|
305
|
+
[6, 60],
|
|
306
|
+
[7, 70],
|
|
307
|
+
[9, 90],
|
|
308
|
+
]),
|
|
309
|
+
);
|
|
310
|
+
expect(m0).toStrictEqual(
|
|
311
|
+
IMap.create([
|
|
312
|
+
[1, 10],
|
|
313
|
+
[3, 30],
|
|
314
|
+
[5, 50],
|
|
315
|
+
[6, 60],
|
|
316
|
+
[7, 70],
|
|
317
|
+
]),
|
|
318
|
+
);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test('case 2', () => {
|
|
322
|
+
const m0 = IMap.create([
|
|
323
|
+
[1, 10],
|
|
324
|
+
[3, 30],
|
|
325
|
+
[5, 50],
|
|
326
|
+
[6, 60],
|
|
327
|
+
[7, 70],
|
|
328
|
+
]);
|
|
329
|
+
|
|
330
|
+
expect(m0.set(3, 40)).toStrictEqual(
|
|
331
|
+
IMap.create([
|
|
332
|
+
[1, 10],
|
|
333
|
+
[3, 40],
|
|
334
|
+
[5, 50],
|
|
335
|
+
[6, 60],
|
|
336
|
+
[7, 70],
|
|
337
|
+
]),
|
|
338
|
+
);
|
|
339
|
+
expect(m0).toStrictEqual(
|
|
340
|
+
IMap.create([
|
|
341
|
+
[1, 10],
|
|
342
|
+
[3, 30],
|
|
343
|
+
[5, 50],
|
|
344
|
+
[6, 60],
|
|
345
|
+
[7, 70],
|
|
346
|
+
]),
|
|
347
|
+
);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test('case 3', () => {
|
|
351
|
+
const m0 = IMap.create<number, number>([]);
|
|
352
|
+
|
|
353
|
+
expect(m0.set(1, 10)).toStrictEqual(IMap.create([[1, 10]]));
|
|
354
|
+
expect(m0).toStrictEqual(IMap.create<number, number>([]));
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test('should create new instance when setting (implementation bug)', () => {
|
|
358
|
+
// Note: set method has bug - it compares value === this.get(key) but get returns Optional
|
|
359
|
+
// So it always creates new instance instead of returning same instance for same value
|
|
360
|
+
const map = IMap.create([['a', 1]]);
|
|
361
|
+
const updated = map.set('a', 1);
|
|
362
|
+
expect(updated).not.toBe(map);
|
|
363
|
+
expect(Optional.unwrap(updated.get('a'))).toBe(1);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test('should create new instance even with same value (implementation bug)', () => {
|
|
367
|
+
// Note: set method has bug - it compares value === this.get(key) but get returns Optional
|
|
368
|
+
const map = IMap.create([['a', 1]]);
|
|
369
|
+
const currentValue = map.get('a');
|
|
370
|
+
if (Optional.isSome(currentValue)) {
|
|
371
|
+
const updated = map.set('a', currentValue.value);
|
|
372
|
+
expect(updated).not.toBe(map);
|
|
373
|
+
expect(Optional.unwrap(updated.get('a'))).toBe(1);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
test('should not modify original map when setting', () => {
|
|
378
|
+
const original = IMap.create<string, number>([['a', 1]]);
|
|
379
|
+
const modified = original.set('b', 2);
|
|
380
|
+
|
|
381
|
+
expect(original.size).toBe(1);
|
|
382
|
+
expect(modified.size).toBe(2);
|
|
383
|
+
expect(original.has('b')).toBe(false);
|
|
384
|
+
expect(modified.has('b')).toBe(true);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
describe('IMap.update', () => {
|
|
389
|
+
test('case 1', () => {
|
|
390
|
+
const m0 = IMap.create<number, number>([
|
|
391
|
+
[1, 10],
|
|
392
|
+
[3, 30],
|
|
393
|
+
[5, 50],
|
|
394
|
+
[6, 60],
|
|
395
|
+
[7, 70],
|
|
396
|
+
]);
|
|
397
|
+
|
|
398
|
+
expect(m0.update(9, (x) => 2 * x)).toStrictEqual(
|
|
399
|
+
IMap.create([
|
|
400
|
+
[1, 10],
|
|
401
|
+
[3, 30],
|
|
402
|
+
[5, 50],
|
|
403
|
+
[6, 60],
|
|
404
|
+
[7, 70],
|
|
405
|
+
]),
|
|
406
|
+
);
|
|
407
|
+
expect(m0).toStrictEqual(
|
|
408
|
+
IMap.create([
|
|
409
|
+
[1, 10],
|
|
410
|
+
[3, 30],
|
|
411
|
+
[5, 50],
|
|
412
|
+
[6, 60],
|
|
413
|
+
[7, 70],
|
|
414
|
+
]),
|
|
415
|
+
);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test('case 2', () => {
|
|
419
|
+
const m0 = IMap.create([
|
|
420
|
+
[1, 10],
|
|
421
|
+
[3, 30],
|
|
422
|
+
[5, 50],
|
|
423
|
+
[6, 60],
|
|
424
|
+
[7, 70],
|
|
425
|
+
]);
|
|
426
|
+
|
|
427
|
+
expect(m0.update(3, (x) => 2 * x)).toStrictEqual(
|
|
428
|
+
IMap.create([
|
|
429
|
+
[1, 10],
|
|
430
|
+
[3, 60],
|
|
431
|
+
[5, 50],
|
|
432
|
+
[6, 60],
|
|
433
|
+
[7, 70],
|
|
434
|
+
]),
|
|
435
|
+
);
|
|
436
|
+
expect(m0).toStrictEqual(
|
|
437
|
+
IMap.create([
|
|
438
|
+
[1, 10],
|
|
439
|
+
[3, 30],
|
|
440
|
+
[5, 50],
|
|
441
|
+
[6, 60],
|
|
442
|
+
[7, 70],
|
|
443
|
+
]),
|
|
444
|
+
);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
test('case 3', () => {
|
|
448
|
+
const m0 = IMap.create<number, number>([]);
|
|
449
|
+
|
|
450
|
+
expect(m0.update(1, (x) => 2 * x)).toStrictEqual(IMap.create([]));
|
|
451
|
+
expect(m0).toStrictEqual(IMap.create<number, number>([]));
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test('should not modify original map when updating', () => {
|
|
455
|
+
const original = IMap.create([['a', 1]]);
|
|
456
|
+
const modified = original.update('a', (x) => x * 2);
|
|
457
|
+
|
|
458
|
+
expect(Optional.unwrap(original.get('a'))).toBe(1);
|
|
459
|
+
expect(Optional.unwrap(modified.get('a'))).toBe(2);
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
describe('IMap.delete', () => {
|
|
464
|
+
test('case 1', () => {
|
|
465
|
+
const m0 = IMap.create<number, number>([
|
|
466
|
+
[1, 10],
|
|
467
|
+
[3, 30],
|
|
468
|
+
[5, 50],
|
|
469
|
+
[6, 60],
|
|
470
|
+
[7, 70],
|
|
471
|
+
]);
|
|
472
|
+
|
|
473
|
+
expect(m0.delete(10)).toStrictEqual(
|
|
474
|
+
IMap.create([
|
|
475
|
+
[1, 10],
|
|
476
|
+
[3, 30],
|
|
477
|
+
[5, 50],
|
|
478
|
+
[6, 60],
|
|
479
|
+
[7, 70],
|
|
480
|
+
]),
|
|
481
|
+
);
|
|
482
|
+
expect(m0).toStrictEqual(
|
|
483
|
+
IMap.create([
|
|
484
|
+
[1, 10],
|
|
485
|
+
[3, 30],
|
|
486
|
+
[5, 50],
|
|
487
|
+
[6, 60],
|
|
488
|
+
[7, 70],
|
|
489
|
+
]),
|
|
490
|
+
);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
test('case 2', () => {
|
|
494
|
+
const m0 = IMap.create([
|
|
495
|
+
[1, 10],
|
|
496
|
+
[3, 30],
|
|
497
|
+
[5, 50],
|
|
498
|
+
[6, 60],
|
|
499
|
+
[7, 70],
|
|
500
|
+
]);
|
|
501
|
+
|
|
502
|
+
expect(m0.delete(3)).toStrictEqual(
|
|
503
|
+
IMap.create([
|
|
504
|
+
[1, 10],
|
|
505
|
+
[5, 50],
|
|
506
|
+
[6, 60],
|
|
507
|
+
[7, 70],
|
|
508
|
+
]),
|
|
509
|
+
);
|
|
510
|
+
expect(m0).toStrictEqual(
|
|
511
|
+
IMap.create([
|
|
512
|
+
[1, 10],
|
|
513
|
+
[3, 30],
|
|
514
|
+
[5, 50],
|
|
515
|
+
[6, 60],
|
|
516
|
+
[7, 70],
|
|
517
|
+
]),
|
|
518
|
+
);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
test('case 3', () => {
|
|
522
|
+
const m0 = IMap.create<number, number>([]);
|
|
523
|
+
|
|
524
|
+
expect(m0.delete(1)).toStrictEqual(IMap.create([]));
|
|
525
|
+
expect(m0).toStrictEqual(IMap.create<number, number>([]));
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
test('should not modify original map when deleting', () => {
|
|
529
|
+
const original = IMap.create([
|
|
530
|
+
['a', 1],
|
|
531
|
+
['b', 2],
|
|
532
|
+
]);
|
|
533
|
+
const modified = original.delete('a');
|
|
534
|
+
|
|
535
|
+
expect(original.size).toBe(2);
|
|
536
|
+
expect(modified.size).toBe(1);
|
|
537
|
+
expect(original.has('a')).toBe(true);
|
|
538
|
+
expect(modified.has('a')).toBe(false);
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
describe('IMap.every', () => {
|
|
543
|
+
test('should return true when all elements satisfy predicate', () => {
|
|
544
|
+
const map = IMap.create([
|
|
545
|
+
['a', 2],
|
|
546
|
+
['b', 4],
|
|
547
|
+
['c', 6],
|
|
548
|
+
]);
|
|
549
|
+
expect(map.every((value) => value % 2 === 0)).toBe(true);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
test('should return false when some elements do not satisfy predicate', () => {
|
|
553
|
+
const map = IMap.create([
|
|
554
|
+
['a', 2],
|
|
555
|
+
['b', 3],
|
|
556
|
+
['c', 4],
|
|
557
|
+
]);
|
|
558
|
+
expect(map.every((value) => value % 2 === 0)).toBe(false);
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
test('should return true for empty map', () => {
|
|
562
|
+
const map = IMap.create<string, number>([]);
|
|
563
|
+
expect(map.every((value) => value > 0)).toBe(true);
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
test('should work with key parameter', () => {
|
|
567
|
+
const map = IMap.create([
|
|
568
|
+
['aa', 1],
|
|
569
|
+
['bb', 2],
|
|
570
|
+
['cc', 3],
|
|
571
|
+
]);
|
|
572
|
+
expect(map.every((_value, key) => key.length === 2)).toBe(true);
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
test('should work as type guard', () => {
|
|
576
|
+
const map = IMap.create<string, string | number>([
|
|
577
|
+
['a', 'hello'],
|
|
578
|
+
['b', 'world'],
|
|
579
|
+
]);
|
|
580
|
+
if (map.every((value): value is string => typeof value === 'string')) {
|
|
581
|
+
// Type should be narrowed to IMap<string, string>
|
|
582
|
+
const firstValue = Optional.unwrap(map.get('a'));
|
|
583
|
+
expect(typeof firstValue).toBe('string');
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
describe('IMap.some', () => {
|
|
589
|
+
test('should return true when at least one element satisfies predicate', () => {
|
|
590
|
+
const map = IMap.create([
|
|
591
|
+
['a', 1],
|
|
592
|
+
['b', 2],
|
|
593
|
+
['c', 3],
|
|
594
|
+
]);
|
|
595
|
+
expect(map.some((value) => value % 2 === 0)).toBe(true);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
test('should return false when no elements satisfy predicate', () => {
|
|
599
|
+
const map = IMap.create([
|
|
600
|
+
['a', 1],
|
|
601
|
+
['b', 3],
|
|
602
|
+
['c', 5],
|
|
603
|
+
]);
|
|
604
|
+
expect(map.some((value) => value % 2 === 0)).toBe(false);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
test('should return false for empty map', () => {
|
|
608
|
+
const map = IMap.create<string, number>([]);
|
|
609
|
+
expect(map.some((value) => value > 0)).toBe(false);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
test('should work with key parameter', () => {
|
|
613
|
+
const map = IMap.create([
|
|
614
|
+
['a', 1],
|
|
615
|
+
['bb', 2],
|
|
616
|
+
['c', 3],
|
|
617
|
+
]);
|
|
618
|
+
expect(map.some((_value, key) => key.length > 1)).toBe(true);
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
describe('IMap.withMutations', () => {
|
|
623
|
+
test('should apply multiple mutations', () => {
|
|
624
|
+
const map = IMap.create<string, number>([
|
|
625
|
+
['a', 1],
|
|
626
|
+
['b', 2],
|
|
627
|
+
]);
|
|
628
|
+
|
|
629
|
+
const updated = map.withMutations([
|
|
630
|
+
{ type: 'set', key: 'c', value: 3 },
|
|
631
|
+
{ type: 'update', key: 'a', updater: (x: number) => x * 2 },
|
|
632
|
+
{ type: 'delete', key: 'b' },
|
|
633
|
+
]);
|
|
634
|
+
|
|
635
|
+
expect(updated.size).toBe(2);
|
|
636
|
+
expect(Optional.unwrap(updated.get('a'))).toBe(2);
|
|
637
|
+
expect(Optional.unwrap(updated.get('c'))).toBe(3);
|
|
638
|
+
expect(Optional.isNone(updated.get('b'))).toBe(true);
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
test('should handle empty mutations array', () => {
|
|
642
|
+
const map = IMap.create([
|
|
643
|
+
['a', 1],
|
|
644
|
+
['b', 2],
|
|
645
|
+
]);
|
|
646
|
+
const updated = map.withMutations([]);
|
|
647
|
+
expect(updated.size).toBe(map.size);
|
|
648
|
+
expect(Optional.unwrap(updated.get('a'))).toBe(1);
|
|
649
|
+
expect(Optional.unwrap(updated.get('b'))).toBe(2);
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
test('should handle update on non-existent key', () => {
|
|
653
|
+
const map = IMap.create<string, number>([['a', 1]]);
|
|
654
|
+
const updated = map.withMutations([
|
|
655
|
+
{ type: 'update', key: 'nonexistent', updater: (x: number) => x * 2 },
|
|
656
|
+
]);
|
|
657
|
+
expect(updated.size).toBe(map.size);
|
|
658
|
+
expect(Optional.isNone(updated.get('nonexistent'))).toBe(true);
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
test('should handle mixed operations', () => {
|
|
662
|
+
const map = IMap.create([['a', 1]]);
|
|
663
|
+
const updated = map.withMutations([
|
|
664
|
+
{ type: 'set', key: 'a', value: 10 },
|
|
665
|
+
{ type: 'update', key: 'a', updater: (x: number) => x + 5 },
|
|
666
|
+
]);
|
|
667
|
+
expect(Optional.unwrap(updated.get('a'))).toBe(15);
|
|
668
|
+
});
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
describe('IMap.map', () => {
|
|
672
|
+
test('should transform values', () => {
|
|
673
|
+
const map = IMap.create([
|
|
674
|
+
['a', 1],
|
|
675
|
+
['b', 2],
|
|
676
|
+
['c', 3],
|
|
677
|
+
]);
|
|
678
|
+
const doubled = map.map((value) => value * 2);
|
|
679
|
+
|
|
680
|
+
expect(Optional.unwrap(doubled.get('a'))).toBe(2);
|
|
681
|
+
expect(Optional.unwrap(doubled.get('b'))).toBe(4);
|
|
682
|
+
expect(Optional.unwrap(doubled.get('c'))).toBe(6);
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
test('should work with key in mapping function', () => {
|
|
686
|
+
const map = IMap.create([
|
|
687
|
+
['a', 1],
|
|
688
|
+
['b', 2],
|
|
689
|
+
]);
|
|
690
|
+
const mapped = map.map((value, key) => `${key}-${value}`);
|
|
691
|
+
|
|
692
|
+
expect(Optional.unwrap(mapped.get('a'))).toBe('a-1');
|
|
693
|
+
expect(Optional.unwrap(mapped.get('b'))).toBe('b-2');
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
test('should change value types', () => {
|
|
697
|
+
const map = IMap.create([
|
|
698
|
+
['a', 1],
|
|
699
|
+
['b', 2],
|
|
700
|
+
]);
|
|
701
|
+
const stringified = map.map((value) => value.toString());
|
|
702
|
+
|
|
703
|
+
expect(Optional.unwrap(stringified.get('a'))).toBe('1');
|
|
704
|
+
expect(Optional.unwrap(stringified.get('b'))).toBe('2');
|
|
705
|
+
});
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
describe('IMap.mapKeys', () => {
|
|
709
|
+
test('should transform keys', () => {
|
|
710
|
+
const map = IMap.create([
|
|
711
|
+
['a', 1],
|
|
712
|
+
['b', 2],
|
|
713
|
+
]);
|
|
714
|
+
const mapped = map.mapKeys((key) => key.toUpperCase());
|
|
715
|
+
|
|
716
|
+
expect(Optional.isNone(mapped.get('a'))).toBe(true);
|
|
717
|
+
expect(Optional.unwrap(mapped.get('A'))).toBe(1);
|
|
718
|
+
expect(Optional.unwrap(mapped.get('B'))).toBe(2);
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
test('should work with different key types', () => {
|
|
722
|
+
const map = IMap.create([
|
|
723
|
+
['1', 'one'],
|
|
724
|
+
['2', 'two'],
|
|
725
|
+
]);
|
|
726
|
+
const mapped = map.mapKeys((key) => Number.parseInt(key, 10));
|
|
727
|
+
|
|
728
|
+
expect(Optional.unwrap(mapped.get(1))).toBe('one');
|
|
729
|
+
expect(Optional.unwrap(mapped.get(2))).toBe('two');
|
|
730
|
+
});
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
describe('IMap.mapEntries', () => {
|
|
734
|
+
test('should transform both keys and values', () => {
|
|
735
|
+
const map = IMap.create([
|
|
736
|
+
['a', 1],
|
|
737
|
+
['b', 2],
|
|
738
|
+
]);
|
|
739
|
+
const mapped = map.mapEntries(([key, value]) => [
|
|
740
|
+
key.toUpperCase(),
|
|
741
|
+
value * 2,
|
|
742
|
+
]);
|
|
743
|
+
|
|
744
|
+
expect(Optional.unwrap(mapped.get('A'))).toBe(2);
|
|
745
|
+
expect(Optional.unwrap(mapped.get('B'))).toBe(4);
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
test('should work with type changes', () => {
|
|
749
|
+
const map = IMap.create([
|
|
750
|
+
['a', 1],
|
|
751
|
+
['b', 2],
|
|
752
|
+
]);
|
|
753
|
+
const mapped = map.mapEntries(([key, value]) => [value, key]);
|
|
754
|
+
|
|
755
|
+
expect(Optional.unwrap(mapped.get(1))).toBe('a');
|
|
756
|
+
expect(Optional.unwrap(mapped.get(2))).toBe('b');
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
describe('IMap.forEach', () => {
|
|
761
|
+
test('case 1', () => {
|
|
762
|
+
const m0 = IMap.create([
|
|
763
|
+
[1, 10],
|
|
764
|
+
[3, 30],
|
|
765
|
+
[5, 50],
|
|
766
|
+
[6, 60],
|
|
767
|
+
[7, 70],
|
|
768
|
+
] as const);
|
|
769
|
+
const keys = [1, 3, 5, 6, 7];
|
|
770
|
+
const values = [10, 30, 50, 60, 70];
|
|
771
|
+
|
|
772
|
+
for (const [key, value] of m0.entries()) {
|
|
773
|
+
expect(keys).toContain(key);
|
|
774
|
+
expect(values).toContain(value);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
test('should execute callback for each element', () => {
|
|
779
|
+
const map = IMap.create([
|
|
780
|
+
['a', 1],
|
|
781
|
+
['b', 2],
|
|
782
|
+
['c', 3],
|
|
783
|
+
]);
|
|
784
|
+
const collected: [string, number][] = [];
|
|
785
|
+
|
|
786
|
+
map.forEach((value, key) => {
|
|
787
|
+
collected.push([key, value]);
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
expect(collected).toHaveLength(3);
|
|
791
|
+
expect(collected).toContainEqual(['a', 1]);
|
|
792
|
+
expect(collected).toContainEqual(['b', 2]);
|
|
793
|
+
expect(collected).toContainEqual(['c', 3]);
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
test('should work with empty map', () => {
|
|
797
|
+
const map = IMap.create<string, number>([]);
|
|
798
|
+
let called = false;
|
|
799
|
+
|
|
800
|
+
map.forEach(() => {
|
|
801
|
+
called = true;
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
expect(called).toBe(false);
|
|
805
|
+
});
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
describe('IMap.keys', () => {
|
|
809
|
+
test('case 1', () => {
|
|
810
|
+
const m0 = IMap.create([
|
|
811
|
+
[1, 10],
|
|
812
|
+
[3, 30],
|
|
813
|
+
[5, 50],
|
|
814
|
+
[6, 60],
|
|
815
|
+
[7, 70],
|
|
816
|
+
] as const);
|
|
817
|
+
const keys = [1, 3, 5, 6, 7];
|
|
818
|
+
|
|
819
|
+
for (const k of m0.keys()) {
|
|
820
|
+
expect(keys).toContain(k);
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
describe('IMap.values', () => {
|
|
826
|
+
test('case 1', () => {
|
|
827
|
+
const m0 = IMap.create([
|
|
828
|
+
[1, 10],
|
|
829
|
+
[3, 30],
|
|
830
|
+
[5, 50],
|
|
831
|
+
[6, 60],
|
|
832
|
+
[7, 70],
|
|
833
|
+
]);
|
|
834
|
+
const values = [10, 30, 50, 60, 70];
|
|
835
|
+
|
|
836
|
+
for (const v of m0.values()) {
|
|
837
|
+
expect(values).toContain(v);
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
describe('IMap.entries', () => {
|
|
843
|
+
test('case 1', () => {
|
|
844
|
+
const m0 = IMap.create([
|
|
845
|
+
[1, 10],
|
|
846
|
+
[3, 30],
|
|
847
|
+
[5, 50],
|
|
848
|
+
[6, 60],
|
|
849
|
+
[7, 70],
|
|
850
|
+
]);
|
|
851
|
+
const keys = [1, 3, 5, 6, 7];
|
|
852
|
+
const values = [10, 30, 50, 60, 70];
|
|
853
|
+
|
|
854
|
+
for (const [k, v] of m0.entries()) {
|
|
855
|
+
expect(keys).toContain(k);
|
|
856
|
+
expect(values).toContain(v);
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
describe('IMap.toKeysArray', () => {
|
|
862
|
+
test('should return array of keys', () => {
|
|
863
|
+
const map = IMap.create([
|
|
864
|
+
['a', 1],
|
|
865
|
+
['b', 2],
|
|
866
|
+
['c', 3],
|
|
867
|
+
]);
|
|
868
|
+
const keys = map.toKeysArray();
|
|
869
|
+
expect(keys).toHaveLength(3);
|
|
870
|
+
expect(keys).toContain('a');
|
|
871
|
+
expect(keys).toContain('b');
|
|
872
|
+
expect(keys).toContain('c');
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
describe('IMap.toValuesArray', () => {
|
|
877
|
+
test('should return array of values', () => {
|
|
878
|
+
const map = IMap.create([
|
|
879
|
+
['a', 1],
|
|
880
|
+
['b', 2],
|
|
881
|
+
['c', 3],
|
|
882
|
+
]);
|
|
883
|
+
const values = map.toValuesArray();
|
|
884
|
+
expect(values).toHaveLength(3);
|
|
885
|
+
expect(values).toContain(1);
|
|
886
|
+
expect(values).toContain(2);
|
|
887
|
+
expect(values).toContain(3);
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
describe('IMap.toEntriesArray', () => {
|
|
892
|
+
test('should return array of entries', () => {
|
|
893
|
+
const map = IMap.create([
|
|
894
|
+
['a', 1],
|
|
895
|
+
['b', 2],
|
|
896
|
+
['c', 3],
|
|
897
|
+
]);
|
|
898
|
+
const entries = map.toEntriesArray();
|
|
899
|
+
expect(entries).toHaveLength(3);
|
|
900
|
+
expect(entries).toContainEqual(['a', 1]);
|
|
901
|
+
expect(entries).toContainEqual(['b', 2]);
|
|
902
|
+
expect(entries).toContainEqual(['c', 3]);
|
|
903
|
+
});
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
describe('IMap.toArray', () => {
|
|
907
|
+
test('should be alias for toEntriesArray', () => {
|
|
908
|
+
const map = IMap.create([
|
|
909
|
+
['a', 1],
|
|
910
|
+
['b', 2],
|
|
911
|
+
['c', 3],
|
|
912
|
+
]);
|
|
913
|
+
const entries = map.toArray();
|
|
914
|
+
const entriesArray = map.toEntriesArray();
|
|
915
|
+
expect(entries).toStrictEqual(entriesArray);
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
describe('IMap.toRawMap', () => {
|
|
920
|
+
test('should return underlying ReadonlyMap', () => {
|
|
921
|
+
const map = IMap.create([
|
|
922
|
+
['a', 1],
|
|
923
|
+
['b', 2],
|
|
924
|
+
['c', 3],
|
|
925
|
+
]);
|
|
926
|
+
const rawMap = map.toRawMap();
|
|
927
|
+
expect(rawMap.size).toBe(3);
|
|
928
|
+
expect(rawMap.get('a')).toBe(1);
|
|
929
|
+
expect(rawMap.get('b')).toBe(2);
|
|
930
|
+
expect(rawMap.get('c')).toBe(3);
|
|
931
|
+
});
|
|
932
|
+
});
|