-
-
Notifications
You must be signed in to change notification settings - Fork 810
/
Copy pathtest.polyfill.js
54 lines (44 loc) · 1.11 KB
/
test.polyfill.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
// MODULES //
var tape = require( 'tape' );
var isBuffer = require( '@stdlib/assert/is-buffer' );
var allocUnsafe = require( './../lib/polyfill.js' );
// TESTS //
tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof allocUnsafe, 'function', 'main export is a function' );
t.end();
});
tape( 'the function throws an error if not provided a nonnegative integer', function test( t ) {
var values;
var i;
values = [
'5',
-5,
3.14,
NaN,
true,
false,
null,
void 0,
[],
[ 1, 2, 3, 4 ],
{},
function noop() {}
];
for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
}
t.end();
function badValue( value ) {
return function badValue() {
allocUnsafe( value );
};
}
});
tape( 'the function (unsafely) allocates a buffer having a specified number of bytes', function test( t ) {
var buf = allocUnsafe( 1000 );
t.strictEqual( isBuffer( buf ), true, 'returns a buffer' );
t.strictEqual( buf.length, 1000, 'has expected length' );
t.end();
});