@@ -5,18 +5,30 @@ const common = require('../common');
55const assert = require ( 'assert' ) ;
66
77function testFastSwap16 ( ) {
8- const buf = Buffer . alloc ( 256 ) ;
9- buf . swap16 ( ) ;
8+ const buf = Buffer . from ( [ 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
9+ const expected = Buffer . from ( [ 0x02 , 0x01 , 0x04 , 0x03 ] ) ;
10+ const padded = Buffer . alloc ( 256 ) ;
11+ buf . copy ( padded ) ;
12+ padded . swap16 ( ) ;
13+ assert . deepStrictEqual ( padded . subarray ( 0 , 4 ) , expected ) ;
1014}
1115
1216function testFastSwap32 ( ) {
13- const buf = Buffer . alloc ( 256 ) ;
14- buf . swap32 ( ) ;
17+ const buf = Buffer . from ( [ 0x01 , 0x02 , 0x03 , 0x04 ] ) ;
18+ const expected = Buffer . from ( [ 0x04 , 0x03 , 0x02 , 0x01 ] ) ;
19+ const padded = Buffer . alloc ( 256 ) ;
20+ buf . copy ( padded ) ;
21+ padded . swap32 ( ) ;
22+ assert . deepStrictEqual ( padded . subarray ( 0 , 4 ) , expected ) ;
1523}
1624
1725function testFastSwap64 ( ) {
18- const buf = Buffer . alloc ( 256 ) ;
19- buf . swap64 ( ) ;
26+ const buf = Buffer . from ( [ 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 ] ) ;
27+ const expected = Buffer . from ( [ 0x08 , 0x07 , 0x06 , 0x05 , 0x04 , 0x03 , 0x02 , 0x01 ] ) ;
28+ const padded = Buffer . alloc ( 256 ) ;
29+ buf . copy ( padded ) ;
30+ padded . swap64 ( ) ;
31+ assert . deepStrictEqual ( padded . subarray ( 0 , 8 ) , expected ) ;
2032}
2133
2234eval ( '%PrepareFunctionForOptimization(Buffer.prototype.swap16)' ) ;
0 commit comments