Skip to content

Commit 2ed91f8

Browse files
committed
test: use example from spec
1 parent a83e206 commit 2ed91f8

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

tests/encoding/mistakes.test.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,24 @@ describe('Common implementation mistakes', () => {
254254
test('Concatenating two ISO-2022-JP outputs is not always valid', (t) => {
255255
const fatal = new TextDecoder('iso-2022-jp', { fatal: true })
256256
const loose = new TextDecoder('iso-2022-jp')
257-
const a = u(0x1b, 0x24, 0x42, 0x30, 0x30, 0x1b, 0x28, 0x42) // switch to jis, select char, switch to ascii
258-
t.assert.strictEqual(fatal.decode(a), '\u65ED')
259-
t.assert.strictEqual(loose.decode(a), '\u65ED')
260-
t.assert.throws(() => fatal.decode(u(...a, ...a)))
261-
t.assert.strictEqual(loose.decode(u(...a, ...a)), '\u65ED\uFFFD\u65ED')
257+
258+
// Roman, example from spec
259+
{
260+
const a = u(0x1b, 0x28, 0x4a, 0x5c, 0x1b, 0x28, 0x42) // switch to Roman, select char, switch to ascii
261+
t.assert.strictEqual(fatal.decode(a), '\xA5')
262+
t.assert.strictEqual(loose.decode(a), '\xA5')
263+
t.assert.throws(() => fatal.decode(u(...a, ...a)))
264+
t.assert.strictEqual(loose.decode(u(...a, ...a)), '\xA5\uFFFD\xA5')
265+
}
266+
267+
// jis
268+
{
269+
const a = u(0x1b, 0x24, 0x42, 0x30, 0x30, 0x1b, 0x28, 0x42) // switch to jis, select char, switch to ascii
270+
t.assert.strictEqual(fatal.decode(a), '\u65ED')
271+
t.assert.strictEqual(loose.decode(a), '\u65ED')
272+
t.assert.throws(() => fatal.decode(u(...a, ...a)))
273+
t.assert.strictEqual(loose.decode(u(...a, ...a)), '\u65ED\uFFFD\u65ED')
274+
}
262275
})
263276
})
264277

0 commit comments

Comments
 (0)