Bug 1770047 [wpt PR 34117] - [Clipboard API] Clipboard Web Custom Formats implementat...
[gecko.git] / testing / web-platform / tests / encoding / textdecoder-fatal-streaming.any.js
blob0d58b2e1d7d8a1e90353b3e42e1da58bf7345c8f
1 // META: title=Encoding API: End-of-file
3 test(function() {
4     [
5         {encoding: 'utf-8', sequence: [0xC0]},
6         {encoding: 'utf-16le', sequence: [0x00]},
7         {encoding: 'utf-16be', sequence: [0x00]}
8     ].forEach(function(testCase) {
10         assert_throws_js(TypeError, function() {
11             var decoder = new TextDecoder(testCase.encoding, {fatal: true});
12             decoder.decode(new Uint8Array(testCase.sequence));
13         }, 'Unterminated ' + testCase.encoding + ' sequence should throw if fatal flag is set');
15         assert_equals(
16             new TextDecoder(testCase.encoding).decode(new Uint8Array([testCase.sequence])),
17             '\uFFFD',
18             'Unterminated UTF-8 sequence should emit replacement character if fatal flag is unset');
19     });
20 }, 'Fatal flag, non-streaming cases');
22 test(function() {
24     var decoder = new TextDecoder('utf-16le', {fatal: true});
25     var odd = new Uint8Array([0x00]);
26     var even = new Uint8Array([0x00, 0x00]);
28     assert_equals(decoder.decode(odd, {stream: true}), '');
29     assert_equals(decoder.decode(odd), '\u0000');
31     assert_throws_js(TypeError, function() {
32         decoder.decode(even, {stream: true});
33         decoder.decode(odd)
34     });
36     assert_throws_js(TypeError, function() {
37         decoder.decode(odd, {stream: true});
38         decoder.decode(even);
39     });
41     assert_equals(decoder.decode(even, {stream: true}), '\u0000');
42     assert_equals(decoder.decode(even), '\u0000');
44 }, 'Fatal flag, streaming cases');