diff --git a/test/utils.js b/test/utils.js index f8dd003..4efce10 100644 --- a/test/utils.js +++ b/test/utils.js @@ -21,3 +21,34 @@ export function json(path) { return require('./' + file + '.json'); // in this form so that bundler can glob this } } + + +const TYPE_TEST_BASE = [ + null, + [1, 2, 3], + { a: 1, b: 2, c: 3 }, + NaN, + 0.1234, + 1.0000000000001, + 10e9999, + new Uint32Array([1, 2, 3]), + 100n, + new Set([1, 2, 3]), + new Uint8ClampedArray([1, 2, 3]), + new Int16Array([1, 2, 3]), + new ArrayBuffer(100), + new DataView(new ArrayBuffer(100)), + { constructor: { name: 'Uint8Array' }, length: '1e30' }, + () => {}, + async () => {}, + class Test {}, +]; +const TYPE_TEST_NOT_STR = [ + ' 1 2 3 4 5', + '010203040x', + 'abcdefgh', + '1 2 3 4 5 ', + 'bee', + new String('1234'), +]; +export const TYPE_TEST = { hex: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_STR), bytes: TYPE_TEST_BASE.concat(TYPE_TEST_NOT_STR) }; diff --git a/test/utils.test.js b/test/utils.test.js new file mode 100644 index 0000000..659c7d9 --- /dev/null +++ b/test/utils.test.js @@ -0,0 +1,28 @@ +import { throws } from 'node:assert'; +import { describe, should } from 'micro-should'; +import { bytesToHex, hexToBytes } from '../esm/abstract/utils.js'; +import { TYPE_TEST } from './utils.js'; + +// Here goes test for tests... +describe('Tests', () => { + should('hexToBytes', () => { + for (let v of TYPE_TEST.hex) { + throws(() => { + hexToBytes(v); + }); + } + }); + should('bytesToHex', () => { + for (let v of TYPE_TEST.bytes) { + throws(() => { + bytesToHex(v); + }); + } + }); +}); + +// ESM is broken. +import url from 'node:url'; +if (import.meta.url === url.pathToFileURL(process.argv[1]).href) { + should.run(); +}