@@ -12,7 +12,7 @@ import { utf8WebPlatformSpecTests } from './data/utf8_wpt_error_cases';
1212
1313type ByteUtilTest < K extends keyof ByteUtils > = {
1414 name : string ;
15- inputs : Parameters < ByteUtils [ K ] > ;
15+ inputs : Parameters < ByteUtils [ K ] > | ( ( ) => Parameters < ByteUtils [ K ] > ) ;
1616 expectation : ( result : {
1717 web : boolean ;
1818 output : ReturnType < ByteUtils [ K ] > | null ;
@@ -500,6 +500,23 @@ const randomBytesTests: ByteUtilTest<'randomBytes'>[] = [
500500 }
501501 }
502502] ;
503+ const swap32Tests : ByteUtilTest < 'swap32' > [ ] = [
504+ {
505+ name : 'swaps byte order in-place' ,
506+ inputs : ( ) => [ Buffer . from ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ] ,
507+ expectation ( { output, error } ) {
508+ expect ( error ) . to . be . null ;
509+ expect ( output ) . to . deep . equal ( Buffer . from ( [ 4 , 3 , 2 , 1 , 8 , 7 , 6 , 5 ] ) ) ;
510+ }
511+ } ,
512+ {
513+ name : 'throws if buffer is not a multiple of 4 bytes' ,
514+ inputs : [ Buffer . from ( [ 1 , 2 , 3 ] ) ] ,
515+ expectation ( { error } ) {
516+ expect ( error ) . to . be . instanceOf ( RangeError ) ;
517+ }
518+ }
519+ ] ;
503520
504521const utils = new Map ( [
505522 [ 'nodeJsByteUtils' , nodeJsByteUtils ] ,
@@ -520,7 +537,8 @@ const table = new Map<keyof ByteUtils, ByteUtilTest<keyof ByteUtils>[]>([
520537 [ 'encodeUTF8Into' , fromUTF8Tests ] ,
521538 [ 'toUTF8' , toUTF8Tests ] ,
522539 [ 'utf8ByteLength' , utf8ByteLengthTests ] ,
523- [ 'randomBytes' , randomBytesTests ]
540+ [ 'randomBytes' , randomBytesTests ] ,
541+ [ 'swap32' , swap32Tests ]
524542] ) ;
525543
526544describe ( 'ByteUtils' , ( ) => {
@@ -790,7 +808,10 @@ describe('ByteUtils', () => {
790808 let error = null ;
791809
792810 try {
793- output = byteUtils [ utility ] . call ( null , ...test . inputs ) ;
811+ output = byteUtils [ utility ] . call (
812+ null ,
813+ ...( typeof test . inputs === 'function' ? test . inputs ( ) : test . inputs )
814+ ) ;
794815 } catch ( thrownError ) {
795816 error = thrownError ;
796817 }
0 commit comments