Skip to content

Commit 6454e16

Browse files
konardclaude
andcommitted
Add comprehensive edge case tests for $mol_vary
Added missing test cases to improve coverage: - Special float values: NaN, Infinity, -Infinity, -0 - Empty collections: empty string, empty Map, empty Set, empty arrays, empty objects - Unicode strings: emojis and multibyte characters (🎉, 你好, 🔥✨💡) - Additional TypedArrays: Uint16Array, Int16Array - Empty typed arrays - Boundary values: exact boundaries between encoding sizes (27/28, 255/256, etc.) - Complex nested structures: deeply nested arrays, mixed types - Mixed type lists with various data types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 21d4b3c commit 6454e16

File tree

1 file changed

+105
-13
lines changed

1 file changed

+105
-13
lines changed

vary/vary.test.ts

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ namespace $.$$ {
1212
}
1313

1414
$mol_test({
15-
15+
1616
"vary pack logical"( $ ) {
1717
check( null, [ spec|none ] )
1818
check( true, [ $mol_vary_spec.true ] )
1919
check( false, [ $mol_vary_spec.fake ] )
2020
check( undefined, [ spec|both ] )
2121
},
22+
23+
"vary pack special floats"( $ ) {
24+
check( NaN, [ fp64, ... new Uint8Array( new Float64Array([ NaN ]).buffer ) ] )
25+
check( Infinity, [ fp64, ... new Uint8Array( new Float64Array([ Infinity ]).buffer ) ] )
26+
check( -Infinity, [ fp64, ... new Uint8Array( new Float64Array([ -Infinity ]).buffer ) ] )
27+
check( -0, [ fp64, ... new Uint8Array( new Float64Array([ -0 ]).buffer ) ] )
28+
},
2229

2330
"vary pack uint0"( $ ) {
2431
check( 0, [ 0 ] )
@@ -102,10 +109,17 @@ namespace $.$$ {
102109
},
103110

104111
"vary pack text"( $ ) {
112+
check( '', [ text|0 ] )
105113
check( 'foo', [ text|3, ... str('foo') ] )
106114
const long = 'abcdefghijklmnopqrstuvwxyzЖЫ'
107115
check( long, [ text|l1, 28, ... str(long) ] )
108116
},
117+
118+
"vary pack text unicode"( $ ) {
119+
check( '🎉', [ text|4, ... str('🎉') ] )
120+
check( '你好', [ text|6, ... str('你好') ] )
121+
check( '🔥✨💡', [ text|12, ... str('🔥✨💡') ] )
122+
},
109123

110124
"vary pack dedup text"( $ ) {
111125
check(
@@ -123,6 +137,14 @@ namespace $.$$ {
123137
new Int8Array([ -128, 127 ]),
124138
[ blob|2, sint|~l1, -128, 127 ],
125139
)
140+
check(
141+
new Uint16Array([ 255 ]),
142+
[ blob|2, uint|l2, 255, 0 ],
143+
)
144+
check(
145+
new Int16Array([ -128 ]),
146+
[ blob|2, sint|~l2, -128, 255 ],
147+
)
126148
check(
127149
new Uint32Array([ 255 ]),
128150
[ blob|4, uint|l4, 255, 0, 0, 0 ],
@@ -148,6 +170,17 @@ namespace $.$$ {
148170
[ blob|8, fp64, ... new Uint8Array( new Float64Array([ 1.5 ]).buffer ) ],
149171
)
150172
},
173+
174+
"vary pack blob empty"( $ ) {
175+
check(
176+
new Uint8Array([]),
177+
[ blob|0, uint|l1 ],
178+
)
179+
check(
180+
new Float32Array([]),
181+
[ blob|0, fp32 ],
182+
)
183+
},
151184

152185
"vary pack dedup blob"( $ ) {
153186
const part = new Uint8Array([ 1, 2 ])
@@ -193,21 +226,35 @@ namespace $.$$ {
193226
},
194227

195228
"vary pack Map"( $ ) {
196-
229+
197230
check(
198231
new Map< any, any >([ [ 'foo', 1 ], [ 2, 'bar' ] ]),
199232
[ tupl|2, text|4, ... str('keys'), text|4, ... str('vals'), list|2, text|3, ... str('foo'), 2, list|2, 1, text|3, ... str('bar') ],
200233
)
201-
234+
235+
},
236+
237+
"vary pack Map empty"( $ ) {
238+
check(
239+
new Map(),
240+
[ tupl|2, text|4, ... str('keys'), text|4, ... str('vals'), list|0, list|0 ],
241+
)
202242
},
203243

204244
"vary pack Set"( $ ) {
205-
245+
206246
check(
207247
new Set([ 7, 'foo' ]),
208248
[ tupl|1, text|4, ... str('vals'), list|2, 7, text|3, ... str('foo') ],
209249
)
210-
250+
251+
},
252+
253+
"vary pack Set empty"( $ ) {
254+
check(
255+
new Set(),
256+
[ tupl|1, text|4, ... str('vals'), list|0 ],
257+
)
211258
},
212259

213260
"vary pack Date"( $ ) { // native date is unstable
@@ -221,32 +268,77 @@ namespace $.$$ {
221268
},
222269

223270
"vary pack custom class"( $ ) {
224-
271+
225272
class Foo {
226-
273+
227274
constructor(
228275
readonly a: number,
229276
readonly b: number,
230277
) {}
231-
278+
232279
;[ Symbol.iterator ]() { // deep comparable
233280
return [ this.a, this.b ].values()
234281
}
235-
282+
236283
}
237-
284+
238285
$mol_vary.type(
239286
[ 'a', 'b' ],
240287
( a = 0, b = 0 )=> new Foo( a, b ),
241288
foo => [ foo.a, foo.b ],
242289
)
243-
290+
244291
check(
245292
new Foo( 1, 2 ),
246293
[ tupl|2, text|1, ... str('a'), text|1, ... str('b'), 1, 2 ],
247294
)
248-
295+
249296
},
250-
297+
298+
"vary pack list empty"( $ ) {
299+
check( [], [ list|0 ] )
300+
},
301+
302+
"vary pack struct empty"( $ ) {
303+
check( {}, [ tupl|0 ] )
304+
},
305+
306+
"vary pack nested mixed"( $ ) {
307+
check(
308+
{ a: [ 1, 2, { b: 'test' } ], c: true },
309+
[ tupl|2, text|1, ... str('a'), text|1, ... str('c'), list|3, 1, 2, tupl|1, text|1, ... str('b'), text|4, ... str('test'), $mol_vary_spec.true ],
310+
)
311+
},
312+
313+
"vary pack deeply nested"( $ ) {
314+
check(
315+
[ [ [ [ 1 ] ] ] ],
316+
[ list|1, list|1, list|1, list|1, 1 ],
317+
)
318+
},
319+
320+
"vary pack mixed types in list"( $ ) {
321+
check(
322+
[ 1, 'two', true, null, undefined, 1.5 ],
323+
[ list|6, 1, text|3, ... str('two'), $mol_vary_spec.true, spec|none, spec|both, fp64, ... new Uint8Array( new Float64Array([ 1.5 ]).buffer ) ],
324+
)
325+
},
326+
327+
"vary pack uint boundary values"( $ ) {
328+
check( 27, [ 27 ] )
329+
check( 28, [ uint|l1, 28 ] )
330+
check( 255, [ uint|l1, 255 ] )
331+
check( 256, [ uint|l2, 0, 1 ] )
332+
check( 65535, [ uint|l2, 255, 255 ] )
333+
check( 65536, [ uint|l4, 0, 0, 1, 0 ] )
334+
},
335+
336+
"vary pack sint boundary values"( $ ) {
337+
check( -28, [ -28 ] )
338+
check( -29, [ sint|~l1, -29 ] )
339+
check( -128, [ sint|~l1, 128 ] )
340+
check( -129, [ sint|~l2, 127, 255 ] )
341+
},
342+
251343
})
252344
}

0 commit comments

Comments
 (0)