OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Encoding API: TextEncoder labels and whitespace</title> |
| 3 <script src="../../../resources/testharness.js"></script> |
| 4 <script src="../../../resources/testharnessreport.js"></script> |
| 5 <script src="resources/shared.js"></script> |
| 6 <script> |
| 7 var tests = [], failure_tests = []; |
| 8 setup(function() { |
| 9 var whitespace = [' ', '\t', '\n', '\f', '\r']; |
| 10 var bad_whitespace = ['\u000B', '\u00A0', '\u2028', '\u2029']; |
| 11 encodings_table.forEach(function(section) { |
| 12 section.encodings.filter(function(encoding) { |
| 13 return utf_encodings.indexOf(encoding.name) !== -1; |
| 14 }).forEach(function(encoding) { |
| 15 var name = encoding.name; |
| 16 encoding.labels.forEach(function(label) { |
| 17 tests.push([label, encoding.name]); |
| 18 whitespace.forEach(function(ws) { |
| 19 tests.push([ws + label, encoding.name]); |
| 20 tests.push([label + ws, encoding.name]); |
| 21 tests.push([ws + label + ws, encoding.name]); |
| 22 }); |
| 23 bad_whitespace.forEach(function(ws) { |
| 24 failure_tests.push([ws + label, encoding.name]); |
| 25 failure_tests.push([label + ws, encoding.name]); |
| 26 failure_tests.push([ws + label + ws, encoding.name]); |
| 27 }); |
| 28 }); |
| 29 }); |
| 30 }); |
| 31 }); |
| 32 |
| 33 tests.forEach(function(t) { |
| 34 var input = t[0], output = t[1]; |
| 35 test(function() { |
| 36 assert_equals(new TextEncoder(input).encoding, output, |
| 37 'label for encoding should match'); |
| 38 assert_equals(new TextEncoder(input.toUpperCase()).encoding, output, |
| 39 'label matching should be case-insensitive'); |
| 40 }, format_value(input) + " => " + format_value(output)); |
| 41 }); |
| 42 |
| 43 failure_tests.forEach(function(t) { |
| 44 var input = t[0], output = t[1]; |
| 45 test(function() { |
| 46 assert_throws({name:'RangeError'}, |
| 47 function() { new TextEncoder(input); }, |
| 48 'non-ASCII whitespace should not be stripped'); |
| 49 }, format_value(input) + " => " + format_value(output)); |
| 50 }); |
| 51 </script> |
OLD | NEW |