mirror of
https://github.com/qntm/base65536
synced 2025-12-23 21:34:40 +01:00
Compare commits
5 Commits
3b9d85e1a6
...
b041f53463
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b041f53463 | ||
|
|
e7f4a80bea | ||
|
|
708b0a1dae | ||
|
|
e443c8583c | ||
|
|
17eaf0d06c |
7251
package-lock.json
generated
7251
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -11,11 +11,11 @@
|
|||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"types": "typings/index.d.ts",
|
"types": "typings/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"mocha": "c8 --100 mocha",
|
"unit": "c8 --100 mocha",
|
||||||
"standard": "standard",
|
"standard": "standard",
|
||||||
"tag": "node -e \"require('child_process').spawn('git', ['tag', `v${require('./package.json').version}`], { stdio: 'inherit' })\"",
|
"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",
|
"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": [
|
"keywords": [
|
||||||
"base64",
|
"base64",
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
import assert from 'node:assert'
|
import assert from 'node:assert/strict'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
import { paddingBlockStart, blockStarts, safeCodePoint, pairStrings } from '../scripts/gen.js'
|
import { paddingBlockStart, blockStarts, safeCodePoint, pairStrings } from '../scripts/gen.js'
|
||||||
|
|
||||||
describe('gen', () => {
|
describe('gen', () => {
|
||||||
it('generates the correct padding block', () => {
|
it('generates the correct padding block', () => {
|
||||||
assert.strictEqual(paddingBlockStart, 'ᔀ')
|
assert.equal(paddingBlockStart, 'ᔀ')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('generates the correct blocks', () => {
|
it('generates the correct blocks', () => {
|
||||||
assert.strictEqual(blockStarts,
|
assert.equal(blockStarts,
|
||||||
'㐀㔀㘀㜀㠀㤀㨀㬀㰀㴀㸀㼀䀀䄀䈀䌀' +
|
'㐀㔀㘀㜀㠀㤀㨀㬀㰀㴀㸀㼀䀀䄀䈀䌀' +
|
||||||
'䐀䔀䘀䜀䠀䤀䨀䬀䰀一伀倀儀刀匀吀' +
|
'䐀䔀䘀䜀䠀䤀䨀䬀䰀一伀倀儀刀匀吀' +
|
||||||
'唀嘀圀堀夀娀嬀尀崀帀开怀愀戀挀搀' +
|
'唀嘀圀堀夀娀嬀尀崀帀开怀愀戀挀搀' +
|
||||||
@ -43,13 +43,13 @@ describe('gen', () => {
|
|||||||
neutralBlockStart <= codePoint &&
|
neutralBlockStart <= codePoint &&
|
||||||
codePoint < neutralBlockStart + (1 << 8)
|
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', () => {
|
it('generates the right pair strings', () => {
|
||||||
assert.deepStrictEqual(pairStrings, [
|
assert.deepEqual(pairStrings, [
|
||||||
'㐀䳿一黿ꄀꏿꔀꗿ𐘀𐛿𒀀𒋿𓀀𓏿𔐀𔗿𖠀𖧿𠀀𨗿',
|
'㐀䳿一黿ꄀꏿꔀꗿ𐘀𐛿𒀀𒋿𓀀𓏿𔐀𔗿𖠀𖧿𠀀𨗿',
|
||||||
'ᔀᗿ'
|
'ᔀᗿ'
|
||||||
])
|
])
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import assert from 'node:assert'
|
import assert from 'node:assert/strict'
|
||||||
|
|
||||||
import fs from 'node:fs'
|
import fs from 'node:fs'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
import { globSync } from 'glob'
|
import { globSync } from 'glob'
|
||||||
@ -15,10 +16,10 @@ describe('base65536', () => {
|
|||||||
it(caseName, () => {
|
it(caseName, () => {
|
||||||
const uint8Array = new Uint8Array(fs.readFileSync(caseName + '.bin'))
|
const uint8Array = new Uint8Array(fs.readFileSync(caseName + '.bin'))
|
||||||
const text = fs.readFileSync(caseName + '.txt', 'utf8')
|
const text = fs.readFileSync(caseName + '.txt', 'utf8')
|
||||||
assert.strictEqual(encode(uint8Array), text)
|
assert.equal(encode(uint8Array), text)
|
||||||
assert.deepStrictEqual(decode(text), uint8Array)
|
assert.deepEqual(decode(text), uint8Array)
|
||||||
forms.forEach(form => {
|
forms.forEach(form => {
|
||||||
assert.strictEqual(text.normalize(form), text)
|
assert.equal(text.normalize(form), text)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -52,7 +53,7 @@ describe('base65536', () => {
|
|||||||
uint8Array[i] = fillUint8
|
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 str = encode(uint8Array)
|
||||||
const uint8Array2 = decode(str)
|
const uint8Array2 = decode(str)
|
||||||
const ascii2 = String.fromCharCode(...uint8Array2)
|
const ascii2 = String.fromCharCode(...uint8Array2)
|
||||||
assert.strictEqual(ascii2, 'some ASCII text')
|
assert.equal(ascii2, 'some ASCII text')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('bug', () => {
|
it('bug', () => {
|
||||||
@ -73,11 +74,11 @@ describe('base65536', () => {
|
|||||||
const str = encode(uint8Array)
|
const str = encode(uint8Array)
|
||||||
const uint8Array2 = decode(str)
|
const uint8Array2 = decode(str)
|
||||||
const ascii2 = String.fromCharCode(...uint8Array2)
|
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', () => {
|
it('round trip to demonstrate padding behaviour', () => {
|
||||||
assert.deepStrictEqual(encode(Uint8Array.from([0x00, 0x01, 0x02])), '㔀ᔂ')
|
assert.deepEqual(encode(Uint8Array.from([0x00, 0x01, 0x02])), '㔀ᔂ')
|
||||||
assert.deepStrictEqual(decode('㔀ᔂ'), Uint8Array.from([0x00, 0x01, 0x02]))
|
assert.deepEqual(decode('㔀ᔂ'), Uint8Array.from([0x00, 0x01, 0x02]))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user