-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: split encoding tests where some cases can be run without ICU
Split the following tests: - `test-whatwg-encoding-textdecoder-utf16-surrogates.js` - `test-whatwg-encoding-textdecoder-ignorebom.js` - `test-whatwg-encoding-textdecoder-streaming.js` Each into two files: one that can be run without ICU and one that has to be run with ICU. The latter can be replaced with WPT later. PR-URL: #25155 Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
deceb26
commit be42182
Showing
6 changed files
with
82 additions
and
11 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
test/parallel/test-whatwg-encoding-custom-textdecoder-ignorebom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
// From: https://github.com/w3c/web-platform-tests/blob/7f567fa29c/encoding/textdecoder-ignorebom.html | ||
// This is the part that can be run without ICU | ||
|
||
require('../common'); | ||
|
||
const assert = require('assert'); | ||
|
||
const cases = [ | ||
{ | ||
encoding: 'utf-8', | ||
bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63] | ||
}, | ||
{ | ||
encoding: 'utf-16le', | ||
bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00] | ||
} | ||
]; | ||
|
||
cases.forEach((testCase) => { | ||
const BOM = '\uFEFF'; | ||
let decoder = new TextDecoder(testCase.encoding, { ignoreBOM: true }); | ||
const bytes = new Uint8Array(testCase.bytes); | ||
assert.strictEqual(decoder.decode(bytes), `${BOM}abc`); | ||
decoder = new TextDecoder(testCase.encoding, { ignoreBOM: false }); | ||
assert.strictEqual(decoder.decode(bytes), 'abc'); | ||
decoder = new TextDecoder(testCase.encoding); | ||
assert.strictEqual(decoder.decode(bytes), 'abc'); | ||
}); |
38 changes: 38 additions & 0 deletions
38
test/parallel/test-whatwg-encoding-custom-textdecoder-streaming.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
// From: https://github.com/w3c/web-platform-tests/blob/fa9436d12c/encoding/textdecoder-streaming.html | ||
// This is the part that can be run without ICU | ||
|
||
require('../common'); | ||
|
||
const assert = require('assert'); | ||
|
||
const string = | ||
'\x00123ABCabc\x80\xFF\u0100\u1000\uFFFD\uD800\uDC00\uDBFF\uDFFF'; | ||
const octets = { | ||
'utf-8': [ | ||
0x00, 0x31, 0x32, 0x33, 0x41, 0x42, 0x43, 0x61, 0x62, 0x63, 0xc2, 0x80, | ||
0xc3, 0xbf, 0xc4, 0x80, 0xe1, 0x80, 0x80, 0xef, 0xbf, 0xbd, 0xf0, 0x90, | ||
0x80, 0x80, 0xf4, 0x8f, 0xbf, 0xbf], | ||
'utf-16le': [ | ||
0x00, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x41, 0x00, 0x42, 0x00, | ||
0x43, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x80, 0x00, 0xFF, 0x00, | ||
0x00, 0x01, 0x00, 0x10, 0xFD, 0xFF, 0x00, 0xD8, 0x00, 0xDC, 0xFF, 0xDB, | ||
0xFF, 0xDF] | ||
}; | ||
|
||
Object.keys(octets).forEach((encoding) => { | ||
for (let len = 1; len <= 5; ++len) { | ||
const encoded = octets[encoding]; | ||
const decoder = new TextDecoder(encoding); | ||
let out = ''; | ||
for (let i = 0; i < encoded.length; i += len) { | ||
const sub = []; | ||
for (let j = i; j < encoded.length && j < i + len; ++j) | ||
sub.push(encoded[j]); | ||
out += decoder.decode(new Uint8Array(sub), { stream: true }); | ||
} | ||
out += decoder.decode(); | ||
assert.strictEqual(out, string); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 7 additions & 10 deletions
17
test/parallel/test-whatwg-encoding-textdecoder-ignorebom.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters