|
1 | | -import { TextDecoder, TextEncoder, getBOMEncoding } from '@exodus/bytes/encoding.js' |
| 1 | +import { |
| 2 | + TextDecoder, |
| 3 | + TextEncoder, |
| 4 | + getBOMEncoding, |
| 5 | + legacyHookDecode, |
| 6 | +} from '@exodus/bytes/encoding.js' |
2 | 7 | import { fromHex } from '@exodus/bytes/hex.js' |
3 | 8 | import { test, describe } from 'node:test' |
4 | 9 | import unfinishedBytesFixtures from '../fixtures/text-encoding.unfinishedBytes.js' |
@@ -83,6 +88,40 @@ describe('encodings are ASCII supersets, except utf-16 and iso-2022-jp', () => { |
83 | 88 | } |
84 | 89 | }) |
85 | 90 |
|
| 91 | +describe('legacyHookDecode', () => { |
| 92 | + const fixtures = { |
| 93 | + replacement: [ |
| 94 | + ['', ''], |
| 95 | + ['00', '\uFFFD'], |
| 96 | + ['ff', '\uFFFD'], |
| 97 | + ['20', '\uFFFD'], |
| 98 | + ['2020', '\uFFFD'], |
| 99 | + // BOM takes preference |
| 100 | + ['efbbbf', ''], |
| 101 | + ['efbbbf2a', '*'], |
| 102 | + ['efbbbf202a', ' *'], |
| 103 | + ['fffe', ''], |
| 104 | + ['fffe2a20', '\u202A'], |
| 105 | + ['fffe2a', '\uFFFD'], |
| 106 | + ['fffe00d72a', '\uD700\uFFFD'], |
| 107 | + ['fffe00d82a', '\uFFFD\uFFFD'], |
| 108 | + ['feff', ''], |
| 109 | + ['feff202a', '\u202A'], |
| 110 | + ['feff20', '\uFFFD'], |
| 111 | + ['feffd70020', '\uD700\uFFFD'], |
| 112 | + ['feffd80820', '\uFFFD\uFFFD'], |
| 113 | + ], |
| 114 | + } |
| 115 | + |
| 116 | + for (const [encoding, data] of Object.entries(fixtures)) { |
| 117 | + test(encoding, (t) => { |
| 118 | + for (const [hex, string] of data) { |
| 119 | + t.assert.strictEqual(legacyHookDecode(fromHex(hex), encoding), string, `${hex}`) |
| 120 | + } |
| 121 | + }) |
| 122 | + } |
| 123 | +}) |
| 124 | + |
86 | 125 | test('getBOMEncoding', (t) => { |
87 | 126 | const fixtures = [ |
88 | 127 | [null, ''], |
|
0 commit comments