| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cda5937 commit 9ac22cd
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,15 +8,11 @@ var assert = require('assert'); | |||
| 8 | 8 | var SD = require('string_decoder').StringDecoder; | |
| 9 | 9 | var encodings = ['base64', 'hex', 'utf8', 'utf16le', 'ucs2']; | |
| 10 | 10 | ||
| 11 | - var bufs = [ '☃💩', 'asdf' ].map(function(b) { | ||
| 12 | - return Buffer.from(b); | ||
| 13 | - }); | ||
| 11 | + const bufs = [ '☃💩', 'asdf' ].map((b) => Buffer.from(b)); | ||
| 14 | 12 | ||
| 15 | 13 | // also test just arbitrary bytes from 0-15. | |
| 16 | - for (var i = 1; i <= 16; i++) { | ||
| 17 | - var bytes = new Array(i).join('.').split('.').map(function(_, j) { | ||
| 18 | - return j + 0x78; | ||
| 19 | - }); | ||
| 14 | + for (let i = 1; i <= 16; i++) { | ||
| 15 | + const bytes = new Array(i).join('.').split('.').map((_, j) => j + 0x78); | ||
| 20 | 16 | bufs.push(Buffer.from(bytes)); | |
| 21 | 17 | } | |
| 22 | 18 | ||
@@ -25,7 +21,7 @@ encodings.forEach(testEncoding); | |||
| 25 | 21 | console.log('ok'); | |
| 26 | 22 | ||
| 27 | 23 | function testEncoding(encoding) { | |
| 28 | - bufs.forEach(function(buf) { | ||
| 24 | + bufs.forEach((buf) => { | ||
| 29 | 25 | testBuf(encoding, buf); | |
| 30 | 26 | }); | |
| 31 | 27 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,6 +107,14 @@ assert.strictEqual(decoder.write(Buffer.from('3DD8', 'hex')), ''); | |||
| 107 | 107 | assert.strictEqual(decoder.write(Buffer.from('4D', 'hex')), ''); | |
| 108 | 108 | assert.strictEqual(decoder.end(), '\ud83d'); | |
| 109 | 109 | ||
| 110 | + assert.throws(() => { | ||
| 111 | + new StringDecoder(1); | ||
| 112 | + }, /^Error: Unknown encoding: 1$/); | ||
| 113 | + | ||
| 114 | + assert.throws(() => { | ||
| 115 | + new StringDecoder('test'); | ||
| 116 | + }, /^Error: Unknown encoding: test$/); | ||
| 117 | + | ||
| 110 | 118 | // test verifies that StringDecoder will correctly decode the given input | |
| 111 | 119 | // buffer with the given encoding to the expected output. It will attempt all | |
| 112 | 120 | // possible ways to write() the input buffer, see writeSequences(). The | |
@@ -119,10 +127,10 @@ function test(encoding, input, expected, singleSequence) { | |||
| 119 | 127 | } else { | |
| 120 | 128 | sequences = [singleSequence]; | |
| 121 | 129 | } | |
| 122 | - sequences.forEach(function(sequence) { | ||
| 123 | - var decoder = new StringDecoder(encoding); | ||
| 124 | - var output = ''; | ||
| 125 | - sequence.forEach(function(write) { | ||
| 130 | + sequences.forEach((sequence) => { | ||
| 131 | + const decoder = new StringDecoder(encoding); | ||
| 132 | + let output = ''; | ||
| 133 | + sequence.forEach((write) => { | ||
| 126 | 134 | output += decoder.write(input.slice(write[0], write[1])); | |
| 127 | 135 | }); | |
| 128 | 136 | output += decoder.end(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments