Skip to content

Commit 64931c5

Browse files
committed
test: add tests for unsupported index arrays
1 parent ac40e7e commit 64931c5

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

lib/node_modules/@stdlib/array/to-fancy/test/test.get.invalid.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var tape = require( 'tape' );
2424
var hasProxySupport = require( '@stdlib/assert/has-proxy-support' );
2525
var Int32Array = require( '@stdlib/array/int32' );
26+
var Uint8Array = require( '@stdlib/array/uint8' );
2627
var array2fancy = require( './../lib' );
2728

2829

@@ -204,3 +205,81 @@ tape( 'the function returns an array-like object which throws an error when prov
204205
};
205206
}
206207
});
208+
209+
tape( 'the function returns an array-like object which throws an error when provided an unsupported array index (generic)', opts, function test( t ) {
210+
var values;
211+
var x;
212+
var y;
213+
var i;
214+
215+
x = [ 1, 2, 3, 4 ];
216+
y = array2fancy( x, {
217+
'cache': {
218+
'get': get
219+
}
220+
});
221+
222+
values = [
223+
array2fancy.idx( [ 0, 1, 2, 3 ] ),
224+
array2fancy.idx( [ true, false, true, false ] ),
225+
array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) )
226+
];
227+
228+
for ( i = 0; i < values.length; i++ ) {
229+
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
230+
}
231+
t.end();
232+
233+
function badValue( value ) {
234+
return function badValue() {
235+
var v = y[ value ]; // eslint-disable-line no-unused-vars
236+
};
237+
}
238+
239+
function get() {
240+
return {
241+
'data': [],
242+
'type': 'beep',
243+
'dtype': 'generic'
244+
};
245+
}
246+
});
247+
248+
tape( 'the function returns an array-like object which throws an error when provided an unsupported array index (typed)', opts, function test( t ) {
249+
var values;
250+
var x;
251+
var y;
252+
var i;
253+
254+
x = new Int32Array( [ 1, 2, 3, 4 ] );
255+
y = array2fancy( x, {
256+
'cache': {
257+
'get': get
258+
}
259+
});
260+
261+
values = [
262+
array2fancy.idx( [ 0, 1, 2, 3 ] ),
263+
array2fancy.idx( [ true, false, true, false ] ),
264+
array2fancy.idx( new Uint8Array( [ 0, 1, 0, 1 ] ) )
265+
];
266+
267+
for ( i = 0; i < values.length; i++ ) {
268+
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
269+
}
270+
t.end();
271+
272+
function badValue( value ) {
273+
return function badValue() {
274+
var v = y[ value ]; // eslint-disable-line no-unused-vars
275+
};
276+
}
277+
278+
function get() {
279+
return {
280+
'data': [],
281+
'type': 'beep',
282+
'dtype': 'generic'
283+
};
284+
}
285+
});

0 commit comments

Comments
 (0)