utatane.tea@gmail.com | 9efa02e | 2016-06-07 17:23:11 +0000 | [diff] [blame] | 1 | function shouldBe(actual, expected) { |
| 2 | if (actual !== expected) |
| 3 | throw new Error('bad value: ' + actual); |
| 4 | } |
| 5 | |
| 6 | function toHighSurrogate(code) |
| 7 | { |
| 8 | return (code >> 10) + (0xD800 - (0x10000 >> 10)); |
| 9 | } |
| 10 | |
| 11 | function toLowSurrogate(code) |
| 12 | { |
| 13 | return (code & ((1 << 10) - 1)) + 0xDC00; |
| 14 | } |
| 15 | |
| 16 | for (var i = 0x10000; i < 0x10ffff; ++i) { |
| 17 | var high = toHighSurrogate(i); |
| 18 | var low = toLowSurrogate(i); |
| 19 | var str = String.fromCharCode(high, low); |
| 20 | shouldBe(unescape(escape(str)), str); |
| 21 | } |