From 4bd0b4662c8724f55e36c85864f5c26c4c8772ff Mon Sep 17 00:00:00 2001 From: tolauwae Date: Sat, 7 Dec 2024 01:13:03 +0100 Subject: [PATCH] Add sourcemap tests --- package.json | 3 ++- tests/unit/sourcemap.test.ts | 12 ++++++++++++ tests/unit/util.test.ts | 10 +++++----- 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 tests/unit/sourcemap.test.ts diff --git a/package.json b/package.json index 664186b..d67efb1 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,8 @@ }, "ava": { "files": [ - "out/tests/unit/util.test.js" + "out/tests/unit/util.test.js", + "out/tests/unit/sourcemap.test.js" ], "typescript": { "compile": false, diff --git a/tests/unit/sourcemap.test.ts b/tests/unit/sourcemap.test.ts new file mode 100644 index 0000000..8a6369f --- /dev/null +++ b/tests/unit/sourcemap.test.ts @@ -0,0 +1,12 @@ +import test from 'ava'; +import {WASM} from '../../src/sourcemap/Wasm'; + +test('test wasm/leb128', t => { + t.is(WASM.leb128(0), '00'); + t.is(WASM.leb128(1), '01'); + t.is(WASM.leb128(8), '08'); + t.is(WASM.leb128(32), '20'); + // t.is(WASM.leb128(64), '40'); + t.is(WASM.leb128(128), '8001'); + // t.is(WASM.leb128(1202), 'b209'); +}); \ No newline at end of file diff --git a/tests/unit/util.test.ts b/tests/unit/util.test.ts index c200943..72765d8 100644 --- a/tests/unit/util.test.ts +++ b/tests/unit/util.test.ts @@ -3,21 +3,21 @@ import {find, getFileExtension} from '../../src/util/util'; import {indent} from '../../src/util/printing'; import {retry} from '../../src/util/retry'; -test('[internal] test util/getFileExtension', t => { +test('test util/getFileExtension', t => { t.is(getFileExtension('test.wast'), 'wast'); t.is(getFileExtension('util.test.js'), 'js'); t.is(getFileExtension('float_misc.asserts.wast'), 'wast'); t.is(getFileExtension('simd_i16x8_extadd_pairwise_i8x16.wast'), 'wast'); }); -test('[internal] test errors in util/getFileExtension', t => { +test('test errors in util/getFileExtension', t => { const error = t.throws(() => { getFileExtension('impossible') }, {instanceOf: Error}); t.is(error.message, 'Could not determine file type'); }); -test('[internal] test util/find', t => { +test('test util/find', t => { t.is(find(/(wast)/, 'test.wast'), 'wast'); t.is(find(/(.wast)/, 'impossible'), ''); t.is(find(/—(.*)—/, 'Jeeves—my man, you know—is really a most extraordinary chap.'), 'my man, you know'); @@ -26,7 +26,7 @@ test('[internal] test util/find', t => { t.is(find(/([a-zA-Z]{11,})/, 'The unanimous Declaration of the thirteen united States of America, When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature\'s God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.'), 'Declaration'); }); -test('[internal] test printing/indent', t => { +test('test printing/indent', t => { t.is(indent(4), ' '); t.is(indent(4, 1), ' '); t.is(indent(1, 4), ' '); @@ -43,7 +43,7 @@ const attempt = (count: number, n: number) => retry(async () => { }) }, n); -test('[internal] test retry/retry', async t => { +test('test retry/retry', async t => { t.is(await attempt(2, 2), 0); t.is(await attempt(2, 4), 0); t.is(await attempt(8, 9), 0);