mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
7f9eb4c29c
Add tests ported from Web Platform Tests. Graduate TextEncoder / TextDecoder from experimental PR-URL: https://github.com/nodejs/node/pull/15743 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
53 lines
1.1 KiB
JavaScript
53 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
// From: https://github.com/w3c/web-platform-tests/blob/fa9436d12c/encoding/textencoder-utf16-surrogates.html
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
TextDecoder,
|
|
TextEncoder
|
|
} = require('util');
|
|
|
|
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);
|