@@ -133,27 +133,100 @@ describe('assertDatasetValue', () => {
133133 dataset ( 'foo' , intType ( true , 64 ) , [ 2 ] ) ,
134134 ) ,
135135 ) . not . toThrow ( ) ;
136+
137+ expect ( ( ) =>
138+ assertDatasetValue (
139+ Float32Array . from ( [ 0 , 1 ] ) , // big ints can be returned as any kind of numbers
140+ dataset ( 'foo' , intType ( true , 64 ) , [ 2 ] ) ,
141+ ) ,
142+ ) . not . toThrow ( ) ;
136143 } ) ;
137144
138- describe ( 'assertDatasetValue' , ( ) => {
139- it ( "should throw when value doesn't satisfy dataset type and shape" , ( ) => {
140- expect ( ( ) =>
141- assertDatasetValue (
142- true ,
143- dataset ( 'foo' , enumType ( intType ( ) , { FOO : 0 } ) , [ ] ) ,
144- ) ,
145- ) . toThrow ( 'Expected number' ) ;
146-
147- expect ( ( ) =>
148- assertDatasetValue ( [ 'foo' , 'bar' ] , dataset ( 'foo' , intType ( ) , [ 2 ] ) ) ,
149- ) . toThrow ( 'Expected number' ) ;
150-
151- expect ( ( ) =>
152- assertDatasetValue (
153- BigInt64Array . from ( [ 0n , 1n ] ) ,
154- dataset ( 'foo' , intType ( ) , [ 2 ] ) ,
155- ) ,
156- ) . toThrow ( 'Expected number' ) ;
157- } ) ;
145+ it ( "should throw when value doesn't satisfy dataset type and shape" , ( ) => {
146+ expect ( ( ) =>
147+ assertDatasetValue (
148+ true ,
149+ dataset ( 'foo' , enumType ( intType ( ) , { FOO : 0 } ) , [ ] ) ,
150+ ) ,
151+ ) . toThrow ( 'Expected number' ) ;
152+
153+ expect ( ( ) =>
154+ assertDatasetValue ( [ 'foo' , 'bar' ] , dataset ( 'foo' , intType ( ) , [ 2 ] ) ) ,
155+ ) . toThrow ( 'Expected number' ) ;
156+
157+ expect ( ( ) =>
158+ assertDatasetValue (
159+ BigInt64Array . from ( [ 0n , 1n ] ) ,
160+ dataset ( 'foo' , intType ( ) , [ 2 ] ) ,
161+ ) ,
162+ ) . toThrow ( 'Expected number' ) ;
163+ } ) ;
164+
165+ it ( 'should not throw when value shape satisfies selection' , ( ) => {
166+ expect ( ( ) =>
167+ assertDatasetValue (
168+ 0 , // scalar => OK
169+ dataset ( 'foo' , intType ( ) , [ 1 ] ) , // 1D dataset
170+ '0' , // scalar selection (only in "Array" vis)
171+ ) ,
172+ ) . not . toThrow ( ) ;
173+
174+ expect ( ( ) =>
175+ assertDatasetValue (
176+ [ 0 ] , // array => OK
177+ dataset ( 'foo' , intType ( ) , [ 1 ] ) , // 1D dataset
178+ ':' , // entire array
179+ ) ,
180+ ) . not . toThrow ( ) ;
181+
182+ expect ( ( ) =>
183+ assertDatasetValue (
184+ 0 , // scalar => OK
185+ dataset ( 'foo' , intType ( ) , [ 1 , 1 ] ) , // 2D dataset
186+ '0,0' , // scalar selection (only in "Array" vis)
187+ ) ,
188+ ) . not . toThrow ( ) ;
189+
190+ expect ( ( ) =>
191+ assertDatasetValue (
192+ [ 0 ] , // array => OK
193+ dataset ( 'foo' , intType ( ) , [ 1 , 1 ] ) , // 2D dataset
194+ '0,:' , // 1D slice selection
195+ ) ,
196+ ) . not . toThrow ( ) ;
197+ } ) ;
198+
199+ it ( "should throw when value shape doesn't satisfy selection" , ( ) => {
200+ expect ( ( ) =>
201+ assertDatasetValue (
202+ [ 0 ] , // array => NOT OK
203+ dataset ( 'foo' , intType ( ) , [ 1 ] ) , // 1D dataset
204+ '0' , // scalar selection (only in "Array" vis)
205+ ) ,
206+ ) . toThrow ( 'Expected number' ) ;
207+
208+ expect ( ( ) =>
209+ assertDatasetValue (
210+ 0 , // scalar => NOT OK
211+ dataset ( 'foo' , intType ( ) , [ 1 ] ) , // 1D dataset
212+ ':' , // entire array
213+ ) ,
214+ ) . toThrow ( 'Expected array or typed array' ) ;
215+
216+ expect ( ( ) =>
217+ assertDatasetValue (
218+ [ 0 ] , // array => NOT OK
219+ dataset ( 'foo' , intType ( ) , [ 1 , 1 ] ) , // 2D dataset
220+ '0,0' , // scalar selection (only in "Array" vis)
221+ ) ,
222+ ) . toThrow ( 'Expected number' ) ;
223+
224+ expect ( ( ) =>
225+ assertDatasetValue (
226+ 0 , // scalar => NOT OK
227+ dataset ( 'foo' , intType ( ) , [ 1 , 1 ] ) , // 2D dataset
228+ '0,:' , // 1D slice
229+ ) ,
230+ ) . toThrow ( 'Expected array' ) ;
158231 } ) ;
159232} ) ;
0 commit comments