GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — buffer/test/from-string.js at master · ExplodingCabbage/buffer Expand file tree/ Copy pathfrom-string.jsMore file actions 131 lines (106 loc) · 3.18 KB / Copy pathfrom-string.jsFile metadata and controls131 lines (106 loc) · 3.18 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 const B = require('../').Buffer const test = require('tape') test('detect utf16 surrogate pairs', function (t) { const text = '\uD83D\uDE38' + '\uD83D\uDCAD' + '\uD83D\uDC4D' const buf = new B(text) t.equal(text, buf.toString()) t.end() }) test('detect utf16 surrogate pairs over U+20000 until U+10FFFF', function (t) { const text = '\uD842\uDFB7' + '\uD93D\uDCAD' + '\uDBFF\uDFFF' const buf = new B(text) t.equal(text, buf.toString()) t.end() }) test('replace orphaned utf16 surrogate lead code point', function (t) { const text = '\uD83D\uDE38' + '\uD83D' + '\uD83D\uDC4D' const buf = new B(text) t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d])) t.end() }) test('replace orphaned utf16 surrogate trail code point', function (t) { const text = '\uD83D\uDE38' + '\uDCAD' + '\uD83D\uDC4D' const buf = new B(text) t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d])) t.end() }) test('do not write partial utf16 code units', function (t) { const f = new B([0, 0, 0, 0, 0]) t.equal(f.length, 5) const size = f.write('あいうえお', 'utf16le') t.equal(size, 4) t.deepEqual(f, new B([0x42, 0x30, 0x44, 0x30, 0x00])) t.end() }) test('handle partial utf16 code points when encoding to utf8 the way node does', function (t) { const text = '\uD83D\uDE38' + '\uD83D\uDC4D' let buf = new B(8) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xf0, 0x9f, 0x91, 0x8d])) buf = new B(7) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00, 0x00])) buf = new B(6) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00])) buf = new B(5) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00])) buf = new B(4) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8])) buf = new B(3) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x00, 0x00, 0x00])) buf = new B(2) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x00, 0x00])) buf = new B(1) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x00])) t.end() }) test('handle invalid utf16 code points when encoding to utf8 the way node does', function (t) { const text = 'a' + '\uDE38\uD83D' + 'b' let buf = new B(8) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd, 0x62])) buf = new B(7) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd])) buf = new B(6) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0x00, 0x00])) buf = new B(5) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0x00])) buf = new B(4) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd])) buf = new B(3) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x61, 0x00, 0x00])) buf = new B(2) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x61, 0x00])) buf = new B(1) buf.fill(0) buf.write(text) t.deepEqual(buf, new B([0x61])) t.end() }) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |