mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
'use strict';
|
|
const common = require('../../common');
|
|
const assert = require('assert');
|
|
|
|
// Testing api calls for arrays
|
|
const test_array = require(`./build/${common.buildType}/test_array`);
|
|
|
|
const array = [
|
|
1,
|
|
9,
|
|
48,
|
|
13493,
|
|
9459324,
|
|
{ name: 'hello' },
|
|
[
|
|
'world',
|
|
'node',
|
|
'abi'
|
|
]
|
|
];
|
|
|
|
assert.throws(
|
|
() => {
|
|
test_array.TestGetElement(array, array.length + 1);
|
|
},
|
|
/^Error: assertion \(\(\(uint32_t\)index < length\)\) failed: Index out of bounds!$/
|
|
);
|
|
|
|
assert.throws(
|
|
() => {
|
|
test_array.TestGetElement(array, -2);
|
|
},
|
|
/^Error: assertion \(index >= 0\) failed: Invalid index\. Expects a positive integer\.$/
|
|
);
|
|
|
|
array.forEach(function(element, index) {
|
|
assert.strictEqual(test_array.TestGetElement(array, index), element);
|
|
});
|
|
|
|
|
|
assert.deepStrictEqual(test_array.New(array), array);
|
|
|
|
assert(test_array.TestHasElement(array, 0));
|
|
assert.strictEqual(test_array.TestHasElement(array, array.length + 1), false);
|
|
|
|
assert(test_array.NewWithLength(0) instanceof Array);
|
|
assert(test_array.NewWithLength(1) instanceof Array);
|
|
// check max allowed length for an array 2^32 -1
|
|
assert(test_array.NewWithLength(4294967295) instanceof Array);
|
|
|