diff --git a/test/utils.js b/test/utils.js index fa52869..603d8a7 100644 --- a/test/utils.js +++ b/test/utils.js @@ -23,14 +23,19 @@ const TYPE_TEST_BASE = [ new Uint32Array([1, 2, 3]), 100n, new Set([1, 2, 3]), + new Map([['aa', 'bb']]), new Uint8ClampedArray([1, 2, 3]), new Int16Array([1, 2, 3]), + new Float32Array([1]), + new BigInt64Array([1n, 2n, 3n]), new ArrayBuffer(100), new DataView(new ArrayBuffer(100)), { constructor: { name: 'Uint8Array' }, length: '1e30' }, () => {}, async () => {}, class Test {}, + Symbol.for('a'), + new Proxy(new Uint8Array(), {}), ]; const TYPE_TEST_OPT = [ @@ -47,7 +52,8 @@ const TYPE_TEST_OPT = [ const TYPE_TEST_NOT_BOOL = [false, true]; const TYPE_TEST_NOT_BYTES = ['', 'test', '1', new Uint8Array([]), new Uint8Array([1, 2, 3])]; -const TYPE_TEST_NOT_STR = [ +const TYPE_TEST_NOT_HEX = [ + '0xbe', ' 1 2 3 4 5', '010203040x', 'abcdefgh', @@ -58,15 +64,17 @@ const TYPE_TEST_NOT_STR = [ const TYPE_TEST_NOT_INT = [-0.0, 0, 1]; const TYPE_TEST = { - int: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_BOOL).concat(TYPE_TEST_NOT_BYTES), - bytes: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_INT).concat(TYPE_TEST_NOT_BOOL), - boolean: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_INT).concat(TYPE_TEST_NOT_BYTES), - hex: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_INT, TYPE_TEST_NOT_BOOL, TYPE_TEST_NOT_STR), + int: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_BOOL, TYPE_TEST_NOT_BYTES), + bytes: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_INT, TYPE_TEST_NOT_BOOL), + boolean: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_INT, TYPE_TEST_NOT_BYTES), + hex: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_INT, TYPE_TEST_NOT_BOOL, TYPE_TEST_NOT_HEX), opts: TYPE_TEST_OPT, - hash: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_BOOL) - .concat(TYPE_TEST_NOT_INT) - .concat(TYPE_TEST_NOT_BYTES) - .concat(TYPE_TEST_OPT), + hash: TYPE_TEST_BASE.concat( + TYPE_TEST_NOT_BOOL, + TYPE_TEST_NOT_INT, + TYPE_TEST_NOT_BYTES, + TYPE_TEST_OPT + ), }; function median(list) { diff --git a/test/utils.test.js b/test/utils.test.js index 336acbe..0ee999a 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -5,21 +5,27 @@ const { TYPE_TEST } = require('./utils'); const { byteSwap, byteSwapIfBE, byteSwap32, isLE, hexToBytes, bytesToHex } = require('../utils'); describe('utils', () => { + const staticHexVectors = [ + { bytes: Uint8Array.from([]), hex: '' }, + { bytes: Uint8Array.from([0xbe]), hex: 'be' }, + { bytes: Uint8Array.from([0xca, 0xfe]), hex: 'cafe' }, + { bytes: Uint8Array.from(new Array(1024).fill(0x69)), hex: '69'.repeat(1024) }, + ]; should('hexToBytes', () => { + for (let v of staticHexVectors) deepStrictEqual(hexToBytes(v.hex), v.bytes); for (let v of TYPE_TEST.hex) { - throws(() => { - hexToBytes(v); - }); + throws(() => hexToBytes(v)); } }); should('bytesToHex', () => { + for (let v of staticHexVectors) deepStrictEqual(bytesToHex(v.bytes), v.hex); for (let v of TYPE_TEST.bytes) { - throws(() => { - bytesToHex(v); - }); + throws(() => bytesToHex(v)); } }); +}); +describe('utils etc', () => { // Here goes test for tests... should(`Test generator`, () => { deepStrictEqual(