|
28 | 28 | '\u02e4\u0064\u12e4\u0030\u3045' |
29 | 29 | ); |
30 | 30 |
|
| 31 | +function testBits(bits, expected, singleSequence) { |
| 32 | + let buf = Buffer.from(bits.split(' ').map(b => parseInt(b, 2))); |
| 33 | + let exp = buf.toString('utf-8'); |
| 34 | + if (expected) assert.strictEqual(exp, expected); |
| 35 | + test('utf-8', buf, exp, singleSequence); |
| 36 | +} |
| 37 | +testBits('10111000 01000001', '\ufffdA'); |
| 38 | +//fails: testBits('11101100 01000001', '\ufffdA'); |
| 39 | +testBits('11101100 10111000 01000001', '\ufffd\ufffdA'); // why two U+FFFD? |
| 40 | +testBits('11000001 10000001 01000001', '\ufffd\ufffdA'); |
| 41 | +test('utf-8', Buffer.from('F09D908D', 'hex'), '\ud835\udc0d'); |
| 42 | +//CESU-8 not supported: test('utf-8', Buffer.from('EDA0B5EDB08D', 'hex'), '\ud835\udc0d'); |
| 43 | + |
31 | 44 | // UCS-2 |
32 | 45 | test('ucs2', Buffer.from('ababc', 'ucs2'), 'ababc'); |
33 | 46 |
|
@@ -98,6 +111,7 @@ function test(encoding, input, expected, singleSequence) { |
98 | 111 | sequence.forEach(function(write) { |
99 | 112 | output += decoder.write(input.slice(write[0], write[1])); |
100 | 113 | }); |
| 114 | + output += decoder.end(); |
101 | 115 | process.stdout.write('.'); |
102 | 116 | if (output !== expected) { |
103 | 117 | var message = |
|
0 commit comments