Files
node/test/parallel/test-whatwg-encoding-textencoder-utf16-surrogates.js
T
Joyee Cheung 2b91c2b5ee 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>
2018-12-29 19:20:24 +08:00

50 lines
1.1 KiB
JavaScript

'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');
const assert = require('assert');
const bad = [
{
input: '\uD800',
expected: '\uFFFD',
name: 'lone surrogate lead'
},
{
input: '\uDC00',
expected: '\uFFFD',
name: 'lone surrogate trail'
},
{
input: '\uD800\u0000',
expected: '\uFFFD\u0000',
name: 'unmatched surrogate lead'
},
{
input: '\uDC00\u0000',
expected: '\uFFFD\u0000',
name: 'unmatched surrogate trail'
},
{
input: '\uDC00\uD800',
expected: '\uFFFD\uFFFD',
name: 'swapped surrogate pair'
},
{
input: '\uD834\uDD1E',
expected: '\uD834\uDD1E',
name: 'properly encoded MUSICAL SYMBOL G CLEF (U+1D11E)'
}
];
bad.forEach((t) => {
const encoded = new TextEncoder().encode(t.input);
const decoded = new TextDecoder().decode(encoded);
assert.strictEqual(decoded, t.expected);
});
assert.strictEqual(new TextEncoder().encode().length, 0);