Skip to content

Commit 8da4255

Browse files
committed
Add tests
1 parent eb7a1b4 commit 8da4255

File tree

1 file changed

+79
-0
lines changed
  • lib/node_modules/@stdlib/array/base/to-accessor-array/test

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' );
25+
var Complex128Array = require( '@stdlib/array/complex128' );
26+
var toAccessorArray = require( './../lib' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a function', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof toAccessorArray, 'function', 'main export is a function' );
34+
t.end();
35+
});
36+
37+
tape( 'the function throws an error if not provided an array-like object', function test( t ) {
38+
var values;
39+
var i;
40+
41+
values = [
42+
'5',
43+
3.14,
44+
-1,
45+
NaN,
46+
true,
47+
false,
48+
null,
49+
void 0,
50+
{},
51+
function noop() {}
52+
];
53+
for ( i = 0; i < values.length; i++ ) {
54+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
55+
}
56+
t.end();
57+
58+
function badValue( value ) {
59+
return function badValue() {
60+
return toAccessorArray( value );
61+
};
62+
}
63+
});
64+
65+
tape( 'if provided an array-like not supporting the accessor protocol, the function returns an array-like object supporting the accessor protocol', function test( t ) {
66+
var arr1 = [ 1, 2, 3 ];
67+
var arr2 = toAccessorArray( arr1 );
68+
t.strictEqual( isAccessorArray( arr2 ), true, 'returns expected value' );
69+
t.notEqual( arr1, arr2, 'returns new object' );
70+
t.end();
71+
});
72+
73+
tape( 'if provided an array-like object already supporting the accessor protocol, the function returns the input value', function test( t ) {
74+
var arr1 = new Complex128Array( 10 );
75+
var arr2 = toAccessorArray( arr1 );
76+
t.strictEqual( isAccessorArray( arr2 ), true, 'returns expected value' );
77+
t.strictEqual( arr1, arr2, 'returns expected value' );
78+
t.end();
79+
});

0 commit comments

Comments
 (0)