@@ -78,6 +78,12 @@ describe('lib/decoder', () => {
78
78
}
79
79
} ) ;
80
80
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
+
81
87
describe ( 'decodeBytes()' , ( ) => {
82
88
const testCases = [
83
89
{ expected : Buffer . from ( '' ) , input : [ 0x90 ] } ,
@@ -107,10 +113,7 @@ describe('lib/decoder', () => {
107
113
] ;
108
114
109
115
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 ) ;
114
117
const expectedStr =
115
118
tc . expected . length > 50
116
119
? `<Buffer ${ tc . expected . toString ( 'hex' , 0 , 20 ) } ... (${ tc . expected . length } bytes)>`
@@ -353,10 +356,7 @@ describe('lib/decoder', () => {
353
356
] ;
354
357
355
358
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 ) ;
360
360
const expectedStr =
361
361
tc . expected . length > 50
362
362
? `'${ tc . expected . substring ( 0 , 20 ) } ...' (${ tc . expected . length } chars)`
@@ -445,10 +445,7 @@ describe('lib/decoder', () => {
445
445
const testCases = generateLargeUintCases ( 128 ) ;
446
446
447
447
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 ) ;
452
449
453
450
it ( `should decode ${ inputStr } to ${ tc . expected } ` , ( ) => {
454
451
const decoder = new Decoder ( Buffer . from ( tc . input ) ) ;
0 commit comments