diff --git a/package.json b/package.json index c8a7116..208da75 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "types": "index.d.ts", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "npm run build && node --test", "build": "tsc -p .", "build:pub": "tsc -p ./tsconfig.pub.json", "build:clean": "git clean -dfx -e node_modules -e .vscode", diff --git a/test/base32.test.cjs b/test/base32.test.cjs new file mode 100644 index 0000000..cd58159 --- /dev/null +++ b/test/base32.test.cjs @@ -0,0 +1,26 @@ +const assert = require('node:assert/strict'); +const { describe, it } = require('node:test'); + +const { base32Encode } = require('../build/utils/base32.js'); + +describe('base32Encode', () => { + it('encodes empty buffers without padding', () => { + assert.equal(base32Encode(Buffer.alloc(0)), ''); + }); + + it('encodes RFC 4648 test vectors', () => { + const vectors = [ + ['', ''], + ['f', 'MY======'], + ['fo', 'MZXQ===='], + ['foo', 'MZXW6==='], + ['foob', 'MZXW6YQ='], + ['fooba', 'MZXW6YTB'], + ['foobar', 'MZXW6YTBOI======'], + ]; + + for (const [input, expected] of vectors) { + assert.equal(base32Encode(Buffer.from(input, 'utf8')), expected); + } + }); +});