Skip to content

Commit 1e19cc6

Browse files
committed
test: add legacyHookDecode tests
1 parent 03320c1 commit 1e19cc6

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/encoding/generic.test.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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'
27
import { fromHex } from '@exodus/bytes/hex.js'
38
import { test, describe } from 'node:test'
49
import unfinishedBytesFixtures from '../fixtures/text-encoding.unfinishedBytes.js'
@@ -83,6 +88,40 @@ describe('encodings are ASCII supersets, except utf-16 and iso-2022-jp', () => {
8388
}
8489
})
8590

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+
86125
test('getBOMEncoding', (t) => {
87126
const fixtures = [
88127
[null, ''],

0 commit comments

Comments
 (0)