Skip to content

Commit 4b758ba

Browse files
committed
test: add cases on which Deno/Servo fail to mistakes
1 parent 221afc3 commit 4b758ba

1 file changed

Lines changed: 49 additions & 1 deletion

File tree

tests/encoding/mistakes.test.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe('Common implementation mistakes', () => {
464464
test('utf-8', (t) => {
465465
const u8 = Uint8Array.of(0xf0, 0xc3, 0x80, 42, 42)
466466
const str = new TextDecoder().decode(u8)
467-
t.assert.strictEqual(new TextDecoder().decode(u8), '\uFFFD\xC0**')
467+
t.assert.strictEqual(str, '\uFFFD\xC0**')
468468

469469
const d = new TextDecoder()
470470
const chunks = [
@@ -474,6 +474,54 @@ describe('Common implementation mistakes', () => {
474474
]
475475
t.assert.strictEqual(chunks.join(''), str)
476476
})
477+
478+
// Deno and Servo are incorrect
479+
test('big5', (t) => {
480+
const u8 = Uint8Array.of(0xfe, 0x40)
481+
const str = new TextDecoder('big5').decode(u8)
482+
t.assert.strictEqual(str, '\u9442')
483+
484+
const d = new TextDecoder('big5')
485+
const chunks = [
486+
d.decode(u8.subarray(0, 1), { stream: true }),
487+
d.decode(Uint8Array.of(), { stream: true }),
488+
d.decode(u8.subarray(1), { stream: true }),
489+
d.decode(),
490+
]
491+
t.assert.strictEqual(chunks.join(''), str)
492+
})
493+
494+
// Deno and Servo are incorrect
495+
test('shift_jis', (t) => {
496+
const u8 = Uint8Array.of(0x81, 0x87)
497+
const str = new TextDecoder('shift_jis').decode(u8)
498+
t.assert.strictEqual(str, '\u221E')
499+
500+
const d = new TextDecoder('shift_jis')
501+
const chunks = [
502+
d.decode(u8.subarray(0, 1), { stream: true }),
503+
d.decode(Uint8Array.of(), { stream: true }),
504+
d.decode(u8.subarray(1), { stream: true }),
505+
d.decode(),
506+
]
507+
t.assert.strictEqual(chunks.join(''), str)
508+
})
509+
510+
// Deno and Servo are incorrect
511+
test('euc-kr', (t) => {
512+
const u8 = Uint8Array.of(0x81, 0x41)
513+
const str = new TextDecoder('euc-kr').decode(u8)
514+
t.assert.strictEqual(str, '\uAC02')
515+
516+
const d = new TextDecoder('euc-kr')
517+
const chunks = [
518+
d.decode(u8.subarray(0, 1), { stream: true }),
519+
d.decode(Uint8Array.of(), { stream: true }),
520+
d.decode(u8.subarray(1), { stream: true }),
521+
d.decode(),
522+
]
523+
t.assert.strictEqual(chunks.join(''), str)
524+
})
477525
})
478526

479527
describe('fatal stream', () => {

0 commit comments

Comments
 (0)