Skip to content

Commit 741373c

Browse files
Fishrock123MylesBorins
authored andcommitted
test: clean up test-buffer-badhex
This test was recently (at the time of writing) introduced in 151d316 and could be cleaned up a bit. Refs: #7602 PR-URL: #7773 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Ilkka Myller <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 17c4187 commit 741373c

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

test/parallel/test-buffer-badhex.js

+33-27
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,45 @@ const Buffer = require('buffer').Buffer;
55

66
// Test hex strings and bad hex strings
77
{
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');
1717

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+
}
2021

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+
}
2427

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+
}
3338

34-
const buf5 = Buffer.alloc(256);
39+
{
40+
const buf = Buffer.alloc(256);
3541
for (let i = 0; i < 256; i++)
36-
buf5[i] = i;
42+
buf[i] = i;
3743

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);
4046

4147
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));
4349
}

0 commit comments

Comments
 (0)