@@ -222,6 +222,52 @@ export const testBinaryCodegen = (transcode: (system: ModuleType, type: Type, va
222222 const value4 : any [ ] = [ ] ;
223223 expect ( ( ) => transcode ( system , type , value4 ) ) . toThrow ( ) ;
224224 } ) ;
225+
226+ test ( 'can encode named tuple with head and tail' , ( ) => {
227+ const system = new ModuleType ( ) ;
228+ const t = system . t ;
229+ const type = system . t . Tuple ( [ t . Key ( 'name' , t . str ) ] , t . num , [ t . Key ( 'status' , t . bool ) ] ) ;
230+ const value : any [ ] = [ 'John' , 42 , 100 , true ] ;
231+ expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
232+ } ) ;
233+
234+ test ( 'can encode named tuple head only' , ( ) => {
235+ const system = new ModuleType ( ) ;
236+ const t = system . t ;
237+ const type = system . t . Tuple ( [ t . Key ( 'id' , t . num ) , t . Key ( 'name' , t . str ) ] , t . bool ) ;
238+ const value : any [ ] = [ 123 , 'Alice' , true , false ] ;
239+ expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
240+ } ) ;
241+
242+ test ( 'can encode named tuple tail only' , ( ) => {
243+ const system = new ModuleType ( ) ;
244+ const t = system . t ;
245+ const type = system . t . Array ( t . str ) . tail ( t . Key ( 'count' , t . num ) , t . Key ( 'valid' , t . bool ) ) ;
246+ const value : any [ ] = [ 'item1' , 'item2' , 5 , true ] ;
247+ expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
248+ } ) ;
249+
250+ test ( 'can encode complex named tuple' , ( ) => {
251+ const system = new ModuleType ( ) ;
252+ const t = system . t ;
253+ const type = system . t . Tuple (
254+ [ t . Key ( 'header' , t . str ) , t . Key ( 'version' , t . num ) ] ,
255+ t . Object ( t . Key ( 'data' , t . str ) ) ,
256+ [ t . Key ( 'checksum' , t . num ) , t . Key ( 'timestamp' , t . num ) ] ,
257+ ) ;
258+ const value : any [ ] = [ 'v1' , 2 , { data : 'test1' } , { data : 'test2' } , 12345 , 1234567890 ] ;
259+ expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
260+ } ) ;
261+
262+ test ( 'can encode nested named tuple' , ( ) => {
263+ const system = new ModuleType ( ) ;
264+ const t = system . t ;
265+ const type = system . t . Tuple ( [
266+ t . Key ( 'metadata' , t . Tuple ( [ t . Key ( 'type' , t . str ) , t . Key ( 'size' , t . num ) ] ) ) ,
267+ ] , t . str ) ;
268+ const value : any [ ] = [ [ 'document' , 1024 ] , 'content1' , 'content2' ] ;
269+ expect ( transcode ( system , type , value ) ) . toStrictEqual ( value ) ;
270+ } ) ;
225271 } ) ;
226272
227273 describe ( '"obj" type' , ( ) => {
0 commit comments