Skip to content

Commit 0c8ebb7

Browse files
committed
style: add helper for formatting input bytes
1 parent 293091e commit 0c8ebb7

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/decoder.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ describe('lib/decoder', () => {
7878
}
7979
});
8080

81+
function formatInput(v: number[]): string {
82+
return v.length > 20
83+
? `[${v.slice(0, 10).join(',')},...] (${v.length} bytes)`
84+
: JSON.stringify(v);
85+
}
86+
8187
describe('decodeBytes()', () => {
8288
const testCases = [
8389
{ expected: Buffer.from(''), input: [0x90] },
@@ -107,10 +113,7 @@ describe('lib/decoder', () => {
107113
];
108114

109115
for (const tc of testCases) {
110-
const inputStr =
111-
tc.input.length > 20
112-
? `[${tc.input.slice(0, 10).join(',')},...] (${tc.input.length} bytes)`
113-
: JSON.stringify(tc.input);
116+
const inputStr = formatInput(tc.input);
114117
const expectedStr =
115118
tc.expected.length > 50
116119
? `<Buffer ${tc.expected.toString('hex', 0, 20)}... (${tc.expected.length} bytes)>`
@@ -353,10 +356,7 @@ describe('lib/decoder', () => {
353356
];
354357

355358
for (const tc of testCases) {
356-
const inputStr =
357-
tc.input.length > 20
358-
? `[${tc.input.slice(0, 10).join(',')},...] (${tc.input.length} bytes)`
359-
: JSON.stringify(tc.input);
359+
const inputStr = formatInput(tc.input);
360360
const expectedStr =
361361
tc.expected.length > 50
362362
? `'${tc.expected.substring(0, 20)}...' (${tc.expected.length} chars)`
@@ -445,10 +445,7 @@ describe('lib/decoder', () => {
445445
const testCases = generateLargeUintCases(128);
446446

447447
for (const tc of testCases) {
448-
const inputStr =
449-
tc.input.length > 10
450-
? `[${tc.input[0]},${tc.input[1]},... (${tc.input.length} bytes)`
451-
: JSON.stringify(tc.input);
448+
const inputStr = formatInput(tc.input);
452449

453450
it(`should decode ${inputStr} to ${tc.expected}`, () => {
454451
const decoder = new Decoder(Buffer.from(tc.input));

0 commit comments

Comments
 (0)