@@ -125,3 +125,79 @@ describe('Types mutual conversions', () => {
125125 Buffer . from ( 'abcdefgHkLmn13*#^@*' ) ,
126126 ) ;
127127 } ) ;
128+
129+ describe ( 'Container values' , ( ) => {
130+ testType ( 'Types.list(Types.UINT32)' , Types . list ( Types . UINT32 ) , [ 1 , 2 , 3 , 4 , 5 ] ) ;
131+ testType ( 'Types.tuple(Types.UINT32, Types.TEXT)' , Types . tuple ( Types . UINT32 , Types . TEXT ) , [
132+ 1 ,
133+ '2' ,
134+ ] ) ;
135+ testType (
136+ 'Types.struct(Types.UINT64)' ,
137+ Types . struct ( {
138+ uint64 : Types . UINT64 ,
139+ double : Types . DOUBLE ,
140+ bytes : Types . BYTES ,
141+ tuple : Types . tuple ( Types . UINT64 , Types . TEXT ) ,
142+ } ) ,
143+ {
144+ uint64 : Long . MAX_UNSIGNED_VALUE ,
145+ double : 1.23456 ,
146+ bytes : Buffer . from ( 'abcdefgHkLmn13*#^@*' ) ,
147+ tuple : [ Long . fromString ( '18446744073709551615' ) , 'qwerASDF' ] ,
148+ } ,
149+ ) ;
150+ // now only simple types allowed
151+ // for example, can't use Types.tuple(Types.UINT64, Types.TEXT) as key
152+ // for example, can't use Long as key
153+ testType ( 'Types.dict(Types.UINT32, Types.TEXT)' , Types . dict ( Types . UINT32 , Types . TEXT ) , {
154+ [ 1844674407370955 ] : 'qwerASDF' ,
155+ [ 1844674407370954 ] : 'qwerASDF' ,
156+ } ) ;
157+ testType ( 'Void' , Types . VOID , null ) ;
158+ } ) ;
159+
160+ describe ( 'Variant value' , ( ) => {
161+ const variantStructValue = {
162+ uint64 : Long . MAX_UNSIGNED_VALUE ,
163+ double : 1.23456 ,
164+ bytes : Buffer . from ( 'abcdefgHkLmn13*#^@*' ) ,
165+ tuple : [ Long . fromString ( '18446744073709551615' ) , 'qwerASDF' ] ,
166+ } ;
167+ for ( const valueKey of Object . keys (
168+ variantStructValue ,
169+ ) as ( keyof typeof variantStructValue ) [ ] ) {
170+ testType (
171+ `Variant Types.variant(Types.struct(...))- ${ valueKey } ` ,
172+ Types . variant (
173+ Types . struct ( {
174+ uint64 : Types . UINT64 ,
175+ double : Types . DOUBLE ,
176+ bytes : Types . BYTES ,
177+ tuple : Types . tuple ( Types . UINT64 , Types . TEXT ) ,
178+ } ) ,
179+ ) ,
180+ { [ valueKey ] : variantStructValue [ valueKey ] } ,
181+ ) ;
182+ }
183+ const variantTupleValues = [
184+ Long . fromString ( '18446744073709551613' ) ,
185+ 123456789123450 ,
186+ 'ABCDEF' ,
187+ Buffer . from ( 'Hello Ydb!' ) ,
188+ ] . map ( ( v , i ) => [ v , i ] ) as [ Ydb . IType , number ] [ ] ;
189+
190+ for ( const [ value , idx ] of variantTupleValues ) {
191+ const val : any [ ] = [ undefined , undefined , undefined , undefined ] ;
192+ val [ idx ] = value ;
193+ testType (
194+ `Variant Types.variant(Types.tuple(...)) - ${ idx } ` ,
195+ Types . variant ( Types . tuple ( Types . UINT64 , Types . INT32 , Types . TEXT , Types . BYTES ) ) ,
196+ val ,
197+ ) ;
198+ }
199+ } ) ;
200+
201+ // TODO: add enum
202+ // TODO: add tagged
203+ } ) ;
0 commit comments