Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit be42182

Browse filesBrowse files
joyeecheungtargos
authored andcommitted
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 <jasnell@gmail.com>
1 parent deceb26 commit be42182
Copy full SHA for be42182
Expand file treeCollapse file tree

6 files changed

+82
-11
lines changed
Open diff view settings
Collapse file
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
// From: https://github.com/w3c/web-platform-tests/blob/7f567fa29c/encoding/textdecoder-ignorebom.html
4+
// This is the part that can be run without ICU
5+
6+
require('../common');
7+
8+
const assert = require('assert');
9+
10+
const cases = [
11+
{
12+
encoding: 'utf-8',
13+
bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63]
14+
},
15+
{
16+
encoding: 'utf-16le',
17+
bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00]
18+
}
19+
];
20+
21+
cases.forEach((testCase) => {
22+
const BOM = '\uFEFF';
23+
let decoder = new TextDecoder(testCase.encoding, { ignoreBOM: true });
24+
const bytes = new Uint8Array(testCase.bytes);
25+
assert.strictEqual(decoder.decode(bytes), `${BOM}abc`);
26+
decoder = new TextDecoder(testCase.encoding, { ignoreBOM: false });
27+
assert.strictEqual(decoder.decode(bytes), 'abc');
28+
decoder = new TextDecoder(testCase.encoding);
29+
assert.strictEqual(decoder.decode(bytes), 'abc');
30+
});
Collapse file
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
// From: https://github.com/w3c/web-platform-tests/blob/fa9436d12c/encoding/textdecoder-streaming.html
4+
// This is the part that can be run without ICU
5+
6+
require('../common');
7+
8+
const assert = require('assert');
9+
10+
const string =
11+
'\x00123ABCabc\x80\xFF\u0100\u1000\uFFFD\uD800\uDC00\uDBFF\uDFFF';
12+
const octets = {
13+
'utf-8': [
14+
0x00, 0x31, 0x32, 0x33, 0x41, 0x42, 0x43, 0x61, 0x62, 0x63, 0xc2, 0x80,
15+
0xc3, 0xbf, 0xc4, 0x80, 0xe1, 0x80, 0x80, 0xef, 0xbf, 0xbd, 0xf0, 0x90,
16+
0x80, 0x80, 0xf4, 0x8f, 0xbf, 0xbf],
17+
'utf-16le': [
18+
0x00, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x41, 0x00, 0x42, 0x00,
19+
0x43, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00, 0x80, 0x00, 0xFF, 0x00,
20+
0x00, 0x01, 0x00, 0x10, 0xFD, 0xFF, 0x00, 0xD8, 0x00, 0xDC, 0xFF, 0xDB,
21+
0xFF, 0xDF]
22+
};
23+
24+
Object.keys(octets).forEach((encoding) => {
25+
for (let len = 1; len <= 5; ++len) {
26+
const encoded = octets[encoding];
27+
const decoder = new TextDecoder(encoding);
28+
let out = '';
29+
for (let i = 0; i < encoded.length; i += len) {
30+
const sub = [];
31+
for (let j = i; j < encoded.length && j < i + len; ++j)
32+
sub.push(encoded[j]);
33+
out += decoder.decode(new Uint8Array(sub), { stream: true });
34+
}
35+
out += decoder.decode();
36+
assert.strictEqual(out, string);
37+
}
38+
});
Collapse file

‎…encoding-textdecoder-utf16-surrogates.js‎ ‎…g-custom-textdecoder-utf16-surrogates.js‎test/parallel/test-whatwg-encoding-textdecoder-utf16-surrogates.js renamed to test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js test/parallel/test-whatwg-encoding-textdecoder-utf16-surrogates.js renamed to test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
// From: https://github.com/w3c/web-platform-tests/blob/39a67e2fff/encoding/textdecoder-utf16-surrogates.html
4+
// With the twist that we specifically test for Node.js error codes
45

56
const common = require('../common');
67

@@ -43,7 +44,7 @@ const bad = [
4344
];
4445

4546
bad.forEach((t) => {
46-
47+
// TODO(joyeecheung): remove this when WPT is ported
4748
assert.strictEqual(
4849
new TextDecoder(t.encoding).decode(new Uint8Array(t.input)),
4950
t.expected);
Collapse file

‎test/parallel/test-whatwg-encoding-textdecoder-ignorebom.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-encoding-textdecoder-ignorebom.js
+7-10Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
'use strict';
22

33
// From: https://github.com/w3c/web-platform-tests/blob/7f567fa29c/encoding/textdecoder-ignorebom.html
4+
// TODO(joyeecheung): replace this with WPT
45

56
const common = require('../common');
67

8+
if (!common.hasIntl)
9+
common.skip('missing Intl');
10+
711
const assert = require('assert');
812

913
const cases = [
1014
{
1115
encoding: 'utf-8',
12-
bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63],
13-
skipNoIntl: false
16+
bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63]
1417
},
1518
{
1619
encoding: 'utf-16le',
17-
bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00],
18-
skipNoIntl: false
20+
bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00]
1921
},
2022
{
2123
encoding: 'utf-16be',
22-
bytes: [0xFE, 0xFF, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63],
23-
skipNoIntl: true
24+
bytes: [0xFE, 0xFF, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63]
2425
}
2526
];
2627

2728
cases.forEach((testCase) => {
28-
if (testCase.skipNoIntl && !common.hasIntl) {
29-
console.log(`skipping ${testCase.encoding} because missing Intl`);
30-
return; // skipping
31-
}
3229
const BOM = '\uFEFF';
3330
let decoder = new TextDecoder(testCase.encoding, { ignoreBOM: true });
3431
const bytes = new Uint8Array(testCase.bytes);
Collapse file

‎test/parallel/test-whatwg-encoding-textdecoder-streaming.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-encoding-textdecoder-streaming.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
'use strict';
22

33
// From: https://github.com/w3c/web-platform-tests/blob/fa9436d12c/encoding/textdecoder-streaming.html
4+
// TODO(joyeecheung): replace this with WPT
45

56
const common = require('../common');
67

8+
if (!common.hasIntl)
9+
common.skip('missing Intl');
10+
711
const assert = require('assert');
812

913
const string =
Collapse file

‎test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
// From: https://github.com/w3c/web-platform-tests/blob/fa9436d12c/encoding/textencoder-utf16-surrogates.html
4+
// TODO(joyeecheung): replace this with WPT
45

56
require('../common');
67

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.