|
| 1 | +<!doctype html> |
| 2 | +<script src=/resources/testharness.js></script> |
| 3 | +<script src=/resources/testharnessreport.js></script> |
| 4 | +<script src=resources/ranges.js></script> |
| 5 | +<script> |
| 6 | + const decode = (input, output, desc) => { |
| 7 | + test(function() { |
| 8 | + for (encoding of ["gb18030", "gbk"]) |
| 9 | + assert_equals(new TextDecoder(encoding).decode(new Uint8Array(input)), output) |
| 10 | + }, "gb18030 decoder: " + desc) |
| 11 | + } |
| 12 | + |
| 13 | + decode([115], "s", "ASCII"); |
| 14 | + decode([0x80], "\u20AC", "euro"); |
| 15 | + decode([0xFF], "\uFFFD", "initial byte out of accepted ranges"); |
| 16 | + decode([0x81], "\uFFFD", "end of queue, gb18030 first not 0"); |
| 17 | + decode([0x81, 0x28], "\ufffd(", "two bytes 0x81 0x28"); |
| 18 | + decode([0x81, 0x40], "\u4E02", "two bytes 0x81 0x40"); |
| 19 | + decode([0x81, 0x7E], "\u4E8A", "two bytes 0x81 0x7e"); |
| 20 | + decode([0x81, 0x7F], "\ufffd\u007f", "two bytes 0x81 0x7f"); |
| 21 | + decode([0x81, 0x80], "\u4E90", "two bytes 0x81 0x80"); |
| 22 | + decode([0x81, 0xFE], "\u4FA2", "two bytes 0x81 0xFE"); |
| 23 | + decode([0x81, 0xFF], "\ufffd", "two bytes 0x81 0xFF"); |
| 24 | + decode([0xFE, 0x40], "\uFA0C", "two bytes 0xFE 0x40"); |
| 25 | + decode([0xFE, 0xFE], "\uE4C5", "two bytes 0xFE 0xFE"); |
| 26 | + decode([0xFE, 0xFF], "\ufffd", "two bytes 0xFE 0xFF"); |
| 27 | + decode([0x81, 0x30], "\ufffd", "two bytes 0x81 0x30"); |
| 28 | + decode([0x81, 0x30, 0xFE], "\ufffd", "three bytes 0x81 0x30 0xFE"); |
| 29 | + decode([0x81, 0x30, 0xFF], "\ufffd0\ufffd", "three bytes 0x81 0x30 0xFF"); |
| 30 | + decode([0x81, 0x30, 0xFE, 0x29], "\ufffd0\ufffd)", "four bytes 0x81 0x30 0xFE 0x29"); |
| 31 | + decode([0xFE, 0x39, 0xFE, 0x39], "\ufffd", "four bytes 0xFE 0x39 0xFE 0x39"); |
| 32 | + decode([0x81, 0x35, 0xF4, 0x36], "\u1E3E", "pointer 7458"); |
| 33 | + decode([0x81, 0x35, 0xF4, 0x37], "\ue7c7", "pointer 7457"); |
| 34 | + decode([0x81, 0x35, 0xF4, 0x38], "\u1E40", "pointer 7459"); |
| 35 | + decode([0x84, 0x31, 0xA4, 0x39], "\uffff", "pointer 39419"); |
| 36 | + decode([0x84, 0x31, 0xA5, 0x30], "\ufffd", "pointer 39420"); |
| 37 | + decode([0x8F, 0x39, 0xFE, 0x39], "\ufffd", "pointer 189999"); |
| 38 | + decode([0x90, 0x30, 0x81, 0x30], "\u{10000}", "pointer 189000"); |
| 39 | + decode([0xE3, 0x32, 0x9A, 0x35], "\u{10FFFF}", "pointer 1237575"); |
| 40 | + decode([0xE3, 0x32, 0x9A, 0x36], "\ufffd", "pointer 1237576"); |
| 41 | + decode([0x83, 0x36, 0xC8, 0x30], "\uE7C8", "legacy ICU special case 1"); |
| 42 | + decode([0xA1, 0xAD], "\u2026", "legacy ICU special case 2"); |
| 43 | + decode([0xA1, 0xAB], "\uFF5E", "legacy ICU special case 3"); |
| 44 | + |
| 45 | + let i = 0; |
| 46 | + for (const range of ranges) { |
| 47 | + const pointer = range[0]; |
| 48 | + decode([ |
| 49 | + Math.floor(pointer / 12600) + 0x81, |
| 50 | + Math.floor((pointer % 12600) / 1260) + 0x30, |
| 51 | + Math.floor((pointer % 1260) / 10) + 0x81, |
| 52 | + pointer % 10 + 0x30 |
| 53 | + ], range[1], "range " + i++); |
| 54 | + } |
| 55 | +</script> |
0 commit comments