diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-20 14:31:35 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-29 19:20:24 +0800 |
commit | 2b91c2b5ee01114e8ea435cb6e8211f9bf2f2f0a (patch) | |
tree | 24d6c3ed9aee7f98680110d29370b1a76ead4a75 /test | |
parent | ab02d380e5aca7cb304c4660e2071ae4dd841461 (diff) | |
download | android-node-v8-2b91c2b5ee01114e8ea435cb6e8211f9bf2f2f0a.tar.gz android-node-v8-2b91c2b5ee01114e8ea435cb6e8211f9bf2f2f0a.tar.bz2 android-node-v8-2b91c2b5ee01114e8ea435cb6e8211f9bf2f2f0a.zip |
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: 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-custom-textdecoder-ignorebom.js | 30 | ||||
-rw-r--r-- | test/parallel/test-whatwg-encoding-custom-textdecoder-streaming.js | 38 | ||||
-rw-r--r-- | test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js (renamed from test/parallel/test-whatwg-encoding-textdecoder-utf16-surrogates.js) | 3 | ||||
-rw-r--r-- | test/parallel/test-whatwg-encoding-textdecoder-ignorebom.js | 17 | ||||
-rw-r--r-- | test/parallel/test-whatwg-encoding-textdecoder-streaming.js | 4 | ||||
-rw-r--r-- | test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js | 1 |
6 files changed, 82 insertions, 11 deletions
diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder-ignorebom.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-ignorebom.js new file mode 100644 index 0000000000..9f6368dcd5 --- /dev/null +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-ignorebom.js @@ -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'); +}); diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder-streaming.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-streaming.js new file mode 100644 index 0000000000..5484929326 --- /dev/null +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-streaming.js @@ -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); + } +}); diff --git a/test/parallel/test-whatwg-encoding-textdecoder-utf16-surrogates.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js index 163cccf9bb..3af83e01b0 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder-utf16-surrogates.js +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-utf16-surrogates.js @@ -1,6 +1,7 @@ 'use strict'; // From: https://github.com/w3c/web-platform-tests/blob/39a67e2fff/encoding/textdecoder-utf16-surrogates.html +// With the twist that we specifically test for Node.js error codes const common = require('../common'); @@ -43,7 +44,7 @@ const bad = [ ]; bad.forEach((t) => { - + // TODO(joyeecheung): remove this when WPT is ported assert.strictEqual( new TextDecoder(t.encoding).decode(new Uint8Array(t.input)), t.expected); diff --git a/test/parallel/test-whatwg-encoding-textdecoder-ignorebom.js b/test/parallel/test-whatwg-encoding-textdecoder-ignorebom.js index 72fe498cd0..7421965c9f 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder-ignorebom.js +++ b/test/parallel/test-whatwg-encoding-textdecoder-ignorebom.js @@ -1,34 +1,31 @@ 'use strict'; // From: https://github.com/w3c/web-platform-tests/blob/7f567fa29c/encoding/textdecoder-ignorebom.html +// TODO(joyeecheung): replace this with WPT const common = require('../common'); +if (!common.hasIntl) + common.skip('missing Intl'); + const assert = require('assert'); const cases = [ { encoding: 'utf-8', - bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63], - skipNoIntl: false + bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63] }, { encoding: 'utf-16le', - bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00], - skipNoIntl: false + bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00] }, { encoding: 'utf-16be', - bytes: [0xFE, 0xFF, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63], - skipNoIntl: true + bytes: [0xFE, 0xFF, 0x00, 0x61, 0x00, 0x62, 0x00, 0x63] } ]; cases.forEach((testCase) => { - if (testCase.skipNoIntl && !common.hasIntl) { - console.log(`skipping ${testCase.encoding} because missing Intl`); - return; // skipping - } const BOM = '\uFEFF'; let decoder = new TextDecoder(testCase.encoding, { ignoreBOM: true }); const bytes = new Uint8Array(testCase.bytes); diff --git a/test/parallel/test-whatwg-encoding-textdecoder-streaming.js b/test/parallel/test-whatwg-encoding-textdecoder-streaming.js index 69186accb5..acc39a74e5 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder-streaming.js +++ b/test/parallel/test-whatwg-encoding-textdecoder-streaming.js @@ -1,9 +1,13 @@ 'use strict'; // From: https://github.com/w3c/web-platform-tests/blob/fa9436d12c/encoding/textdecoder-streaming.html +// TODO(joyeecheung): replace this with WPT const common = require('../common'); +if (!common.hasIntl) + common.skip('missing Intl'); + const assert = require('assert'); const string = diff --git a/test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js b/test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js index 808acf31eb..453b49e5b9 100644 --- a/test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js +++ b/test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js @@ -1,6 +1,7 @@ 'use strict'; // From: https://github.com/w3c/web-platform-tests/blob/fa9436d12c/encoding/textencoder-utf16-surrogates.html +// TODO(joyeecheung): replace this with WPT require('../common'); |