mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 1257877 - Remove UTF-16 support from TextEncoder tests to reflect a spec change. r=Ms2ger
This commit is contained in:
parent
160a5b6fb7
commit
251c1c9ceb
@ -15,13 +15,11 @@ test(function() {
|
||||
}, 'Default inputs');
|
||||
|
||||
|
||||
function testEncodeDecodeSample(encoding, string, bytes) {
|
||||
function testDecodeSample(encoding, string, bytes) {
|
||||
test(function() {
|
||||
var encoded = new TextEncoder(encoding).encode(string);
|
||||
assert_array_equals([].slice.call(encoded), bytes);
|
||||
assert_equals(new TextDecoder(encoding).decode(new Uint8Array(bytes)), string);
|
||||
assert_equals(new TextDecoder(encoding).decode(new Uint8Array(bytes).buffer), string);
|
||||
}, 'Encode/decode round trip: ' + encoding);
|
||||
}, 'Decode sample: ' + encoding);
|
||||
}
|
||||
|
||||
// z (ASCII U+007A), cent (Latin-1 U+00A2), CJK water (BMP U+6C34),
|
||||
@ -29,25 +27,29 @@ function testEncodeDecodeSample(encoding, string, bytes) {
|
||||
// byte-swapped BOM (non-character U+FFFE)
|
||||
var sample = 'z\xA2\u6C34\uD834\uDD1E\uF8FF\uDBFF\uDFFD\uFFFE';
|
||||
|
||||
testEncodeDecodeSample(
|
||||
'utf-8',
|
||||
sample,
|
||||
[0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4, 0xF0, 0x9D, 0x84, 0x9E, 0xEF, 0xA3, 0xBF, 0xF4, 0x8F, 0xBF, 0xBD, 0xEF, 0xBF, 0xBE]
|
||||
);
|
||||
test(function() {
|
||||
var encoding = 'utf-8';
|
||||
var string = sample;
|
||||
var bytes = [0x7A, 0xC2, 0xA2, 0xE6, 0xB0, 0xB4, 0xF0, 0x9D, 0x84, 0x9E, 0xEF, 0xA3, 0xBF, 0xF4, 0x8F, 0xBF, 0xBD, 0xEF, 0xBF, 0xBE];
|
||||
var encoded = new TextEncoder().encode(string);
|
||||
assert_array_equals([].slice.call(encoded), bytes);
|
||||
assert_equals(new TextDecoder(encoding).decode(new Uint8Array(bytes)), string);
|
||||
assert_equals(new TextDecoder(encoding).decode(new Uint8Array(bytes).buffer), string);
|
||||
}, 'Encode/decode round trip: utf-8');
|
||||
|
||||
testEncodeDecodeSample(
|
||||
testDecodeSample(
|
||||
'utf-16le',
|
||||
sample,
|
||||
[0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C, 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xF8, 0xFF, 0xDB, 0xFD, 0xDF, 0xFE, 0xFF]
|
||||
);
|
||||
|
||||
testEncodeDecodeSample(
|
||||
testDecodeSample(
|
||||
'utf-16be',
|
||||
sample,
|
||||
[0x00, 0x7A, 0x00, 0xA2, 0x6C, 0x34, 0xD8, 0x34, 0xDD, 0x1E, 0xF8, 0xFF, 0xDB, 0xFF, 0xDF, 0xFD, 0xFF, 0xFE]
|
||||
);
|
||||
|
||||
testEncodeDecodeSample(
|
||||
testDecodeSample(
|
||||
'utf-16',
|
||||
sample,
|
||||
[0x7A, 0x00, 0xA2, 0x00, 0x34, 0x6C, 0x34, 0xD8, 0x1E, 0xDD, 0xFF, 0xF8, 0xFF, 0xDB, 0xFD, 0xDF, 0xFE, 0xFF]
|
||||
|
@ -23,10 +23,6 @@ setup(function() {
|
||||
});
|
||||
|
||||
tests.forEach(function(input) {
|
||||
test(function() {
|
||||
assert_throws(new RangeError(), function() { new TextEncoder(input); });
|
||||
}, 'Invalid label ' + format_value(input) + ' should be rejected by TextEncoder.');
|
||||
|
||||
test(function() {
|
||||
assert_throws(new RangeError(), function() { new TextDecoder(input); });
|
||||
}, 'Invalid label ' + format_value(input) + ' should be rejected by TextDecoder.');
|
||||
|
@ -6,7 +6,6 @@
|
||||
<script>
|
||||
|
||||
test(function() {
|
||||
assert_throws(new RangeError(), function() { new TextEncoder('replacement'); });
|
||||
assert_throws(new RangeError(), function() { new TextDecoder('replacement'); });
|
||||
}, 'The "replacement" label should not be a known encoding.');
|
||||
|
||||
@ -16,7 +15,6 @@ encodings_table.forEach(function(section) {
|
||||
}).forEach(function(encoding) {
|
||||
encoding.labels.forEach(function(label) {
|
||||
test(function() {
|
||||
assert_throws(new RangeError(), function() { new TextEncoder(label); });
|
||||
assert_throws(new RangeError(), function() { new TextDecoder(label); });
|
||||
}, 'Label for "replacement" should be rejected by API: ' + label);
|
||||
});
|
||||
|
@ -38,7 +38,7 @@ interface TextDecoder {
|
||||
|
||||
// 8.2 Interface TextDecoder
|
||||
|
||||
[Constructor(optional DOMString utfLabel = "utf-8"),
|
||||
[Constructor,
|
||||
Exposed=Window,Worker]
|
||||
interface TextEncoder {
|
||||
readonly attribute DOMString encoding;
|
||||
|
@ -5,12 +5,23 @@
|
||||
<script src="resources/encodings.js"></script>
|
||||
<script>
|
||||
|
||||
var string = '\\x00123ABCabc\\x80\\xFF\\u0100\\u1000\\uFFFD\\uD800\\uDC00\\uDBFF\\uDFFF';
|
||||
var string = '\x00123ABCabc\x80\xFF\u0100\u1000\uFFFD\uD800\uDC00\uDBFF\uDFFF';
|
||||
var octets = {
|
||||
'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],
|
||||
'utf-16be': [0x00,0x00,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x41,0x00,0x42,
|
||||
0x00,0x43,0x00,0x61,0x00,0x62,0x00,0x63,0x00,0x80,0x00,0xFF,
|
||||
0x01,0x00,0x10,0x00,0xFF,0xFD,0xD8,0x00,0xDC,0x00,0xDB,0xFF,
|
||||
0xDF,0xFF]
|
||||
};
|
||||
|
||||
utf_encodings.forEach(function (encoding) {
|
||||
for (var len = 1; len <= 5; ++len) {
|
||||
test(function() {
|
||||
var encoded = new TextEncoder(encoding).encode(string);
|
||||
var encoded = octets[encoding] ||
|
||||
new TextEncoder(encoding).encode(string);
|
||||
|
||||
var out = '';
|
||||
var decoder = new TextDecoder(encoding);
|
||||
|
@ -6,20 +6,16 @@
|
||||
<script>
|
||||
|
||||
encodings_table.forEach(function(section) {
|
||||
section.encodings.filter(function(encoding) {
|
||||
return encoding.name !== 'replacement';
|
||||
}).forEach(function(encoding) {
|
||||
if (utf_encodings.indexOf(encoding.name) !== -1) {
|
||||
section.encodings.forEach(function(encoding) {
|
||||
if (encoding.name !== 'replacement') {
|
||||
test(function() {
|
||||
assert_equals(new TextDecoder(encoding.name).encoding, encoding.name);
|
||||
assert_equals(new TextEncoder(encoding.name).encoding, encoding.name);
|
||||
}, 'UTF encodings are supported for encode and decode: ' + encoding.name);
|
||||
} else {
|
||||
test(function() {
|
||||
assert_equals(new TextDecoder(encoding.name).encoding, encoding.name);
|
||||
assert_throws(new RangeError(), function() { new TextEncoder(encoding.name); });
|
||||
}, 'Non-UTF encodings supported only for decode, not encode: ' + encoding.name);
|
||||
}, 'Encoding argument supported for decode: ' + encoding.name);
|
||||
}
|
||||
|
||||
test(function() {
|
||||
assert_equals(new TextEncoder(encoding.name).encoding, 'utf-8');
|
||||
}, 'Encoding argument not considered for encode: ' + encoding.name);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user