Skip to content

Commit acaeed2

Browse files
committed
test: document more Bun straming failures
1 parent 6c78a4e commit acaeed2

1 file changed

Lines changed: 44 additions & 43 deletions

File tree

tests/encoding/mistakes.test.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -530,53 +530,54 @@ describe('Common implementation mistakes', () => {
530530
t.assert.strictEqual(new TextDecoder().decode(u(0xed, 0xbf), { stream: true }), `${r}${r}`)
531531
})
532532

533-
// Deno and Servo are incorrect
534-
test('big5', (t) => {
535-
const u8 = Uint8Array.of(0xfe, 0x40)
536-
const str = new TextDecoder('big5').decode(u8)
537-
t.assert.strictEqual(str, '\u9442')
538-
539-
const d = new TextDecoder('big5')
540-
const chunks = [
541-
d.decode(u8.subarray(0, 1), { stream: true }),
542-
d.decode(Uint8Array.of(), { stream: true }),
543-
d.decode(u8.subarray(1), { stream: true }),
544-
d.decode(),
545-
]
546-
t.assert.strictEqual(chunks.join(''), str)
547-
})
533+
const vectors = {
534+
gbk: [[0x81, 0x82], '\u4E97'],
535+
gb18030: [[0x81, 0x82], '\u4E97'],
536+
big5: [[0xfe, 0x40], '\u9442'],
537+
shift_jis: [[0x81, 0x87], '\u221E'],
538+
'euc-kr': [[0x81, 0x41], '\uAC02'],
539+
'euc-jp': [[0xb0, 0xb0], '\u65ED'],
540+
'iso-2022-jp': [[0x2a, 0x1b], '*\uFFFD'],
541+
}
548542

549-
// Deno and Servo are incorrect
550-
test('shift_jis', (t) => {
551-
const u8 = Uint8Array.of(0x81, 0x87)
552-
const str = new TextDecoder('shift_jis').decode(u8)
553-
t.assert.strictEqual(str, '\u221E')
543+
for (const [encoding, [bytes, expected]] of Object.entries(vectors)) {
544+
test(encoding, (t) => {
545+
const u8 = Uint8Array.from(bytes)
546+
const str = new TextDecoder(encoding).decode(u8)
547+
t.assert.strictEqual(str, expected)
554548

555-
const d = new TextDecoder('shift_jis')
556-
const chunks = [
557-
d.decode(u8.subarray(0, 1), { stream: true }),
558-
d.decode(Uint8Array.of(), { stream: true }),
559-
d.decode(u8.subarray(1), { stream: true }),
560-
d.decode(),
561-
]
562-
t.assert.strictEqual(chunks.join(''), str)
563-
})
549+
// Bun is incorrect
550+
{
551+
const d = new TextDecoder(encoding)
552+
const chunks = [d.decode(u8.subarray(0, 1), { stream: true }), d.decode(u8.subarray(1))]
553+
t.assert.strictEqual(chunks.join(''), str)
554+
}
564555

565-
// Deno and Servo are incorrect
566-
test('euc-kr', (t) => {
567-
const u8 = Uint8Array.of(0x81, 0x41)
568-
const str = new TextDecoder('euc-kr').decode(u8)
569-
t.assert.strictEqual(str, '\uAC02')
556+
// Bun is incorrect
557+
{
558+
const d = new TextDecoder(encoding)
559+
const chunks = [
560+
d.decode(u8.subarray(0, 1), { stream: true }),
561+
d.decode(u8.subarray(1), { stream: true }),
562+
d.decode(),
563+
]
564+
t.assert.strictEqual(chunks.join(''), str)
565+
}
570566

571-
const d = new TextDecoder('euc-kr')
572-
const chunks = [
573-
d.decode(u8.subarray(0, 1), { stream: true }),
574-
d.decode(Uint8Array.of(), { stream: true }),
575-
d.decode(u8.subarray(1), { stream: true }),
576-
d.decode(),
577-
]
578-
t.assert.strictEqual(chunks.join(''), str)
579-
})
567+
// Deno, Servo and Bun are incorrect on big5, shift_jis, euc-kr
568+
// https://github.com/hsivonen/encoding_rs/issues/126
569+
{
570+
const d = new TextDecoder(encoding)
571+
const chunks = [
572+
d.decode(u8.subarray(0, 1), { stream: true }),
573+
d.decode(Uint8Array.of(), { stream: true }),
574+
d.decode(u8.subarray(1), { stream: true }),
575+
d.decode(),
576+
]
577+
t.assert.strictEqual(chunks.join(''), str)
578+
}
579+
})
580+
}
580581
})
581582

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

0 commit comments

Comments
 (0)