summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-12-20 14:20:31 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-12-29 19:20:24 +0800
commit74a9221f6f2f706b8eb4eda7c73cbb65a0b3cfb7 (patch)
treeb933d2f1018304965d15ec2db10099e749691fc3 /test
parent8a60be4f0fd6a8f6591b7d591e20960fc4372fe4 (diff)
downloadandroid-node-v8-74a9221f6f2f706b8eb4eda7c73cbb65a0b3cfb7.tar.gz
android-node-v8-74a9221f6f2f706b8eb4eda7c73cbb65a0b3cfb7.tar.bz2
android-node-v8-74a9221f6f2f706b8eb4eda7c73cbb65a0b3cfb7.zip
test: split test-whatwg-encoding-textdecoder.js
Split test-whatwg-encoding-textdecoder.js into: - `test-whatwg-encoding-custom-textdecoder.js` which tests Node.js-specific behaviors - `test-whatwg-encoding-custom-textdecoder-api-invalid-label.js` which is a customized version of the WPT counterpart - `test-whatwg-encoding-custom-api-basics.js` which is the part of `test-whatwg-encoding-api-basics.js` that can be run without ICU - `test-whatwg-encoding-api-basics.js` which can be replaced with WPT later. PR-URL: https://github.com/nodejs/node/pull/25155 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-whatwg-encoding-api-basics.js74
-rw-r--r--test/parallel/test-whatwg-encoding-custom-api-basics.js61
-rw-r--r--test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js40
-rw-r--r--test/parallel/test-whatwg-encoding-custom-textdecoder.js (renamed from test/parallel/test-whatwg-encoding-textdecoder.js)105
4 files changed, 178 insertions, 102 deletions
diff --git a/test/parallel/test-whatwg-encoding-api-basics.js b/test/parallel/test-whatwg-encoding-api-basics.js
new file mode 100644
index 0000000000..8abaee8171
--- /dev/null
+++ b/test/parallel/test-whatwg-encoding-api-basics.js
@@ -0,0 +1,74 @@
+'use strict';
+
+// From: https://github.com/w3c/web-platform-tests/blob/master/encoding/api-basics.html
+// TODO(joyeecheung): replace this with WPT
+
+const common = require('../common');
+
+if (!common.hasIntl)
+ common.skip('missing Intl');
+
+const assert = require('assert');
+
+function testDecodeSample(encoding, string, bytes) {
+ assert.strictEqual(
+ new TextDecoder(encoding).decode(new Uint8Array(bytes)),
+ string);
+ assert.strictEqual(
+ new TextDecoder(encoding).decode(new Uint8Array(bytes).buffer),
+ string);
+}
+
+// `z` (ASCII U+007A), cent (Latin-1 U+00A2), CJK water (BMP U+6C34),
+// G-Clef (non-BMP U+1D11E), PUA (BMP U+F8FF), PUA (non-BMP U+10FFFD)
+// byte-swapped BOM (non-character U+FFFE)
+const sample = 'z\xA2\u6C34\uD834\uDD1E\uF8FF\uDBFF\uDFFD\uFFFE';
+
+{
+ const encoding = 'utf-8';
+ const string = sample;
+ const bytes = [
+ 0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4,
+ 0xF0, 0x9D, 0x84, 0x9E, 0xEF, 0xA3,
+ 0xBF, 0xF4, 0x8F, 0xBF, 0xBD, 0xEF,
+ 0xBF, 0xBE
+ ];
+ const encoded = new TextEncoder().encode(string);
+ assert.deepStrictEqual([].slice.call(encoded), bytes);
+ assert.strictEqual(
+ new TextDecoder(encoding).decode(new Uint8Array(bytes)),
+ string);
+ assert.strictEqual(
+ new TextDecoder(encoding).decode(new Uint8Array(bytes).buffer),
+ string);
+}
+
+testDecodeSample(
+ 'utf-16le',
+ sample,
+ [
+ 0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C,
+ 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xF8,
+ 0xFF, 0xDB, 0xFD, 0xDF, 0xFE, 0xFF
+ ]
+);
+
+testDecodeSample(
+ 'utf-16be',
+ sample,
+ [
+ 0x00, 0x7A, 0x00, 0xA2, 0x6C, 0x34,
+ 0xD8, 0x34, 0xDD, 0x1E, 0xF8, 0xFF,
+ 0xDB, 0xFF, 0xDF, 0xFD, 0xFF, 0xFE
+ ]
+);
+
+testDecodeSample(
+ 'utf-16',
+ sample,
+ [
+ 0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C,
+ 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xF8,
+ 0xFF, 0xDB, 0xFD, 0xDF, 0xFE, 0xFF
+ ]
+);
diff --git a/test/parallel/test-whatwg-encoding-custom-api-basics.js b/test/parallel/test-whatwg-encoding-custom-api-basics.js
new file mode 100644
index 0000000000..c39bce5d74
--- /dev/null
+++ b/test/parallel/test-whatwg-encoding-custom-api-basics.js
@@ -0,0 +1,61 @@
+'use strict';
+
+// From: https://github.com/w3c/web-platform-tests/blob/master/encoding/api-basics.html
+// This is the part that can be run without ICU
+
+require('../common');
+
+const assert = require('assert');
+
+function testDecodeSample(encoding, string, bytes) {
+ assert.strictEqual(
+ new TextDecoder(encoding).decode(new Uint8Array(bytes)),
+ string);
+ assert.strictEqual(
+ new TextDecoder(encoding).decode(new Uint8Array(bytes).buffer),
+ string);
+}
+
+// `z` (ASCII U+007A), cent (Latin-1 U+00A2), CJK water (BMP U+6C34),
+// G-Clef (non-BMP U+1D11E), PUA (BMP U+F8FF), PUA (non-BMP U+10FFFD)
+// byte-swapped BOM (non-character U+FFFE)
+const sample = 'z\xA2\u6C34\uD834\uDD1E\uF8FF\uDBFF\uDFFD\uFFFE';
+
+{
+ const encoding = 'utf-8';
+ const string = sample;
+ const bytes = [
+ 0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4,
+ 0xF0, 0x9D, 0x84, 0x9E, 0xEF, 0xA3,
+ 0xBF, 0xF4, 0x8F, 0xBF, 0xBD, 0xEF,
+ 0xBF, 0xBE
+ ];
+ const encoded = new TextEncoder().encode(string);
+ assert.deepStrictEqual([].slice.call(encoded), bytes);
+ assert.strictEqual(
+ new TextDecoder(encoding).decode(new Uint8Array(bytes)),
+ string);
+ assert.strictEqual(
+ new TextDecoder(encoding).decode(new Uint8Array(bytes).buffer),
+ string);
+}
+
+testDecodeSample(
+ 'utf-16le',
+ sample,
+ [
+ 0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C,
+ 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xF8,
+ 0xFF, 0xDB, 0xFD, 0xDF, 0xFE, 0xFF
+ ]
+);
+
+testDecodeSample(
+ 'utf-16',
+ sample,
+ [
+ 0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C,
+ 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xF8,
+ 0xFF, 0xDB, 0xFD, 0xDF, 0xFE, 0xFF
+ ]
+);
diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js
new file mode 100644
index 0000000000..aabd3fe5c4
--- /dev/null
+++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-api-invalid-label.js
@@ -0,0 +1,40 @@
+'use strict';
+// From: https://github.com/w3c/web-platform-tests/blob/master/encoding/api-invalid-label.html
+// With the twist that we specifically test for Node.js error codes
+
+const common = require('../common');
+
+[
+ 'utf-8',
+ 'unicode-1-1-utf-8',
+ 'utf8',
+ 'utf-16be',
+ 'utf-16le',
+ 'utf-16'
+].forEach((i) => {
+ ['\u0000', '\u000b', '\u00a0', '\u2028', '\u2029'].forEach((ws) => {
+ common.expectsError(
+ () => new TextDecoder(`${ws}${i}`),
+ {
+ code: 'ERR_ENCODING_NOT_SUPPORTED',
+ type: RangeError
+ }
+ );
+
+ common.expectsError(
+ () => new TextDecoder(`${i}${ws}`),
+ {
+ code: 'ERR_ENCODING_NOT_SUPPORTED',
+ type: RangeError
+ }
+ );
+
+ common.expectsError(
+ () => new TextDecoder(`${ws}${i}${ws}`),
+ {
+ code: 'ERR_ENCODING_NOT_SUPPORTED',
+ type: RangeError
+ }
+ );
+ });
+});
diff --git a/test/parallel/test-whatwg-encoding-textdecoder.js b/test/parallel/test-whatwg-encoding-custom-textdecoder.js
index 55afd34a02..ceee5b9cbb 100644
--- a/test/parallel/test-whatwg-encoding-textdecoder.js
+++ b/test/parallel/test-whatwg-encoding-custom-textdecoder.js
@@ -1,4 +1,7 @@
// Flags: --expose-internals
+
+// This tests Node.js-specific behaviors of TextDecoder
+
'use strict';
const common = require('../common');
@@ -167,72 +170,6 @@ if (common.hasIntl) {
});
}
-// From: https://github.com/w3c/web-platform-tests/blob/master/encoding/api-basics.html
-function testDecodeSample(encoding, string, bytes) {
- assert.strictEqual(
- new TextDecoder(encoding).decode(new Uint8Array(bytes)),
- string);
- assert.strictEqual(
- new TextDecoder(encoding).decode(new Uint8Array(bytes).buffer),
- string);
-}
-
-// `z` (ASCII U+007A), cent (Latin-1 U+00A2), CJK water (BMP U+6C34),
-// G-Clef (non-BMP U+1D11E), PUA (BMP U+F8FF), PUA (non-BMP U+10FFFD)
-// byte-swapped BOM (non-character U+FFFE)
-const sample = 'z\xA2\u6C34\uD834\uDD1E\uF8FF\uDBFF\uDFFD\uFFFE';
-
-{
- const encoding = 'utf-8';
- const string = sample;
- const bytes = [
- 0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4,
- 0xF0, 0x9D, 0x84, 0x9E, 0xEF, 0xA3,
- 0xBF, 0xF4, 0x8F, 0xBF, 0xBD, 0xEF,
- 0xBF, 0xBE
- ];
- const encoded = new TextEncoder().encode(string);
- assert.deepStrictEqual([].slice.call(encoded), bytes);
- assert.strictEqual(
- new TextDecoder(encoding).decode(new Uint8Array(bytes)),
- string);
- assert.strictEqual(
- new TextDecoder(encoding).decode(new Uint8Array(bytes).buffer),
- string);
-}
-
-testDecodeSample(
- 'utf-16le',
- sample,
- [
- 0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C,
- 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xF8,
- 0xFF, 0xDB, 0xFD, 0xDF, 0xFE, 0xFF
- ]
-);
-
-if (common.hasIntl) {
- testDecodeSample(
- 'utf-16be',
- sample,
- [
- 0x00, 0x7A, 0x00, 0xA2, 0x6C, 0x34,
- 0xD8, 0x34, 0xDD, 0x1E, 0xF8, 0xFF,
- 0xDB, 0xFF, 0xDF, 0xFD, 0xFF, 0xFE
- ]
- );
-}
-
-testDecodeSample(
- 'utf-16',
- sample,
- [
- 0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C,
- 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xF8,
- 0xFF, 0xDB, 0xFD, 0xDF, 0xFE, 0xFF
- ]
-);
-
{
common.expectsError(
() => new TextDecoder('utf-8', 1),
@@ -242,39 +179,3 @@ testDecodeSample(
}
);
}
-
-// From: https://github.com/w3c/web-platform-tests/blob/master/encoding/api-invalid-label.html
-[
- 'utf-8',
- 'unicode-1-1-utf-8',
- 'utf8',
- 'utf-16be',
- 'utf-16le',
- 'utf-16'
-].forEach((i) => {
- ['\u0000', '\u000b', '\u00a0', '\u2028', '\u2029'].forEach((ws) => {
- common.expectsError(
- () => new TextDecoder(`${ws}${i}`),
- {
- code: 'ERR_ENCODING_NOT_SUPPORTED',
- type: RangeError
- }
- );
-
- common.expectsError(
- () => new TextDecoder(`${i}${ws}`),
- {
- code: 'ERR_ENCODING_NOT_SUPPORTED',
- type: RangeError
- }
- );
-
- common.expectsError(
- () => new TextDecoder(`${ws}${i}${ws}`),
- {
- code: 'ERR_ENCODING_NOT_SUPPORTED',
- type: RangeError
- }
- );
- });
-});