| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 17c4187 commit 741373c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,39 +5,45 @@ const Buffer = require('buffer').Buffer; | |||
| 5 | 5 | ||
| 6 | 6 | // Test hex strings and bad hex strings | |
| 7 | 7 | { | |
| 8 | - const buf1 = Buffer.alloc(4); | ||
| 9 | - assert.strictEqual(buf1.length, 4); | ||
| 10 | - assert.deepStrictEqual(buf1, new Buffer([0, 0, 0, 0])); | ||
| 11 | - assert.strictEqual(buf1.write('abcdxx', 0, 'hex'), 2); | ||
| 12 | - assert.deepStrictEqual(buf1, new Buffer([0xab, 0xcd, 0x00, 0x00])); | ||
| 13 | - assert.strictEqual(buf1.toString('hex'), 'abcd0000'); | ||
| 14 | - assert.strictEqual(buf1.write('abcdef01', 0, 'hex'), 4); | ||
| 15 | - assert.deepStrictEqual(buf1, new Buffer([0xab, 0xcd, 0xef, 0x01])); | ||
| 16 | - assert.strictEqual(buf1.toString('hex'), 'abcdef01'); | ||
| 8 | + const buf = Buffer.alloc(4); | ||
| 9 | + assert.strictEqual(buf.length, 4); | ||
| 10 | + assert.deepStrictEqual(buf, new Buffer([0, 0, 0, 0])); | ||
| 11 | + assert.strictEqual(buf.write('abcdxx', 0, 'hex'), 2); | ||
| 12 | + assert.deepStrictEqual(buf, new Buffer([0xab, 0xcd, 0x00, 0x00])); | ||
| 13 | + assert.strictEqual(buf.toString('hex'), 'abcd0000'); | ||
| 14 | + assert.strictEqual(buf.write('abcdef01', 0, 'hex'), 4); | ||
| 15 | + assert.deepStrictEqual(buf, new Buffer([0xab, 0xcd, 0xef, 0x01])); | ||
| 16 | + assert.strictEqual(buf.toString('hex'), 'abcdef01'); | ||
| 17 | 17 | ||
| 18 | - const buf2 = Buffer.from(buf1.toString('hex'), 'hex'); | ||
| 19 | - assert.strictEqual(buf1.toString('hex'), buf2.toString('hex')); | ||
| 18 | + const copy = Buffer.from(buf.toString('hex'), 'hex'); | ||
| 19 | + assert.strictEqual(buf.toString('hex'), copy.toString('hex')); | ||
| 20 | + } | ||
| 20 | 21 | ||
| 21 | - const buf3 = Buffer.alloc(5); | ||
| 22 | - assert.strictEqual(buf3.write('abcdxx', 1, 'hex'), 2); | ||
| 23 | - assert.strictEqual(buf3.toString('hex'), '00abcd0000'); | ||
| 22 | + { | ||
| 23 | + const buf = Buffer.alloc(5); | ||
| 24 | + assert.strictEqual(buf.write('abcdxx', 1, 'hex'), 2); | ||
| 25 | + assert.strictEqual(buf.toString('hex'), '00abcd0000'); | ||
| 26 | + } | ||
| 24 | 27 | ||
| 25 | - const buf4 = Buffer.alloc(4); | ||
| 26 | - assert.deepStrictEqual(buf4, new Buffer([0, 0, 0, 0])); | ||
| 27 | - assert.strictEqual(buf4.write('xxabcd', 0, 'hex'), 0); | ||
| 28 | - assert.deepStrictEqual(buf4, new Buffer([0, 0, 0, 0])); | ||
| 29 | - assert.strictEqual(buf4.write('xxab', 1, 'hex'), 0); | ||
| 30 | - assert.deepStrictEqual(buf4, new Buffer([0, 0, 0, 0])); | ||
| 31 | - assert.strictEqual(buf4.write('cdxxab', 0, 'hex'), 1); | ||
| 32 | - assert.deepStrictEqual(buf4, new Buffer([0xcd, 0, 0, 0])); | ||
| 28 | + { | ||
| 29 | + const buf = Buffer.alloc(4); | ||
| 30 | + assert.deepStrictEqual(buf, new Buffer([0, 0, 0, 0])); | ||
| 31 | + assert.strictEqual(buf.write('xxabcd', 0, 'hex'), 0); | ||
| 32 | + assert.deepStrictEqual(buf, new Buffer([0, 0, 0, 0])); | ||
| 33 | + assert.strictEqual(buf.write('xxab', 1, 'hex'), 0); | ||
| 34 | + assert.deepStrictEqual(buf, new Buffer([0, 0, 0, 0])); | ||
| 35 | + assert.strictEqual(buf.write('cdxxab', 0, 'hex'), 1); | ||
| 36 | + assert.deepStrictEqual(buf, new Buffer([0xcd, 0, 0, 0])); | ||
| 37 | + } | ||
| 33 | 38 | ||
| 34 | - const buf5 = Buffer.alloc(256); | ||
| 39 | + { | ||
| 40 | + const buf = Buffer.alloc(256); | ||
| 35 | 41 | for (let i = 0; i < 256; i++) | |
| 36 | - buf5[i] = i; | ||
| 42 | + buf[i] = i; | ||
| 37 | 43 | ||
| 38 | - const hex = buf5.toString('hex'); | ||
| 39 | - assert.deepStrictEqual(Buffer.from(hex, 'hex'), buf5); | ||
| 44 | + const hex = buf.toString('hex'); | ||
| 45 | + assert.deepStrictEqual(Buffer.from(hex, 'hex'), buf); | ||
| 40 | 46 | ||
| 41 | 47 | const badHex = hex.slice(0, 256) + 'xx' + hex.slice(256, 510); | |
| 42 | - assert.deepStrictEqual(Buffer.from(badHex, 'hex'), buf5.slice(0, 128)); | ||
| 48 | + assert.deepStrictEqual(Buffer.from(badHex, 'hex'), buf.slice(0, 128)); | ||
| 43 | 49 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments