1
0
mirror of https://github.com/qntm/base65536 synced 2025-12-23 05:34:40 +01:00

Compare commits

...

5 Commits

Author SHA1 Message Date
qntm
b041f53463
Update index.test.js (#111) 2025-12-22 00:44:41 +00:00
qntm
e7f4a80bea
Update gen.test.js (#110) 2025-12-22 00:10:08 +00:00
qntm
708b0a1dae
Update package.json (#109) 2025-12-21 23:45:37 +00:00
qntm
e443c8583c
Rename gen.spec.js to gen.test.js (#108)
* Rename gen.spec.js to gen.test.js

* Rename index.spec.js to index.test.js
2025-12-21 23:32:17 +00:00
qntm
17eaf0d06c
Delete package-lock.json 2025-12-21 22:53:14 +00:00
4 changed files with 17 additions and 7267 deletions

7251
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,11 +11,11 @@
"main": "src/index.js",
"types": "typings/index.d.ts",
"scripts": {
"mocha": "c8 --100 mocha",
"unit": "c8 --100 mocha",
"standard": "standard",
"tag": "node -e \"require('child_process').spawn('git', ['tag', `v${require('./package.json').version}`], { stdio: 'inherit' })\"",
"tag-and-publish": "npm run tag && git push --tags && npm publish && npm version patch --no-git-tag-version && git add . && git commit -m \"Bump patch\" && git push",
"test": "npm run standard && npm run mocha"
"test": "npm run standard && npm run unit"
},
"keywords": [
"base64",

View File

@ -1,14 +1,14 @@
import assert from 'node:assert'
import assert from 'node:assert/strict'
import { describe, it } from 'mocha'
import { paddingBlockStart, blockStarts, safeCodePoint, pairStrings } from '../scripts/gen.js'
describe('gen', () => {
it('generates the correct padding block', () => {
assert.strictEqual(paddingBlockStart, 'ᔀ')
assert.equal(paddingBlockStart, 'ᔀ')
})
it('generates the correct blocks', () => {
assert.strictEqual(blockStarts,
assert.equal(blockStarts,
'㐀㔀㘀㜀㠀㤀㨀㬀㰀㴀㸀㼀䀀䄀䈀䌀' +
'䐀䔀䘀䜀䠀䤀䨀䬀䰀一伀倀儀刀匀吀' +
'唀嘀圀堀夀娀嬀尀崀帀开怀愀戀挀搀' +
@ -43,13 +43,13 @@ describe('gen', () => {
neutralBlockStart <= codePoint &&
codePoint < neutralBlockStart + (1 << 8)
)
assert.strictEqual(safeCodePoint.eastAsianWidth(codePoint), isInNeutralBlock ? 'N' : 'W')
assert.equal(safeCodePoint.eastAsianWidth(codePoint), isInNeutralBlock ? 'N' : 'W')
}
})
})
it('generates the right pair strings', () => {
assert.deepStrictEqual(pairStrings, [
assert.deepEqual(pairStrings, [
'㐀䳿一黿ꄀꏿꔀꗿ𐘀𐛿𒀀𒋿𓀀𓏿𔐀𔗿𖠀𖧿𠀀𨗿',
'ᔀᗿ'
])

View File

@ -1,4 +1,5 @@
import assert from 'node:assert'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import { describe, it } from 'mocha'
import { globSync } from 'glob'
@ -15,10 +16,10 @@ describe('base65536', () => {
it(caseName, () => {
const uint8Array = new Uint8Array(fs.readFileSync(caseName + '.bin'))
const text = fs.readFileSync(caseName + '.txt', 'utf8')
assert.strictEqual(encode(uint8Array), text)
assert.deepStrictEqual(decode(text), uint8Array)
assert.equal(encode(uint8Array), text)
assert.deepEqual(decode(text), uint8Array)
forms.forEach(form => {
assert.strictEqual(text.normalize(form), text)
assert.equal(text.normalize(form), text)
})
})
})
@ -52,7 +53,7 @@ describe('base65536', () => {
uint8Array[i] = fillUint8
}
assert.deepStrictEqual(uint8Array, decode(encode(uint8Array)))
assert.deepEqual(uint8Array, decode(encode(uint8Array)))
})
})
}
@ -64,7 +65,7 @@ describe('base65536', () => {
const str = encode(uint8Array)
const uint8Array2 = decode(str)
const ascii2 = String.fromCharCode(...uint8Array2)
assert.strictEqual(ascii2, 'some ASCII text')
assert.equal(ascii2, 'some ASCII text')
})
it('bug', () => {
@ -73,11 +74,11 @@ describe('base65536', () => {
const str = encode(uint8Array)
const uint8Array2 = decode(str)
const ascii2 = String.fromCharCode(...uint8Array2)
assert.strictEqual(ascii2, 'what the heck is up')
assert.equal(ascii2, 'what the heck is up')
})
it('round trip to demonstrate padding behaviour', () => {
assert.deepStrictEqual(encode(Uint8Array.from([0x00, 0x01, 0x02])), '㔀ᔂ')
assert.deepStrictEqual(decode('㔀ᔂ'), Uint8Array.from([0x00, 0x01, 0x02]))
assert.deepEqual(encode(Uint8Array.from([0x00, 0x01, 0x02])), '㔀ᔂ')
assert.deepEqual(decode('㔀ᔂ'), Uint8Array.from([0x00, 0x01, 0x02]))
})
})