@@ -41,7 +41,25 @@ assert.strictEqual(d.length, 0);
4141 assert . strictEqual ( b . offset , 0 ) ;
4242}
4343
44+ // Test creating a Buffer from a Uint8Array
45+ {
46+ const ui8 = new Uint8Array ( 4 ) . fill ( 42 ) ;
47+ const e = Buffer . from ( ui8 ) ;
48+ for ( const [ index , value ] of e . entries ( ) ) {
49+ assert . strictEqual ( value , ui8 [ index ] ) ;
50+ }
51+ }
52+ // Test creating a Buffer from a Uint8Array (old constructor)
53+ {
54+ const ui8 = new Uint8Array ( 4 ) . fill ( 42 ) ;
55+ const e = Buffer ( ui8 ) ;
56+ for ( const [ key , value ] of e . entries ( ) ) {
57+ assert . strictEqual ( value , ui8 [ key ] ) ;
58+ }
59+ }
60+
4461// Test creating a Buffer from a Uint32Array
62+ // Note: it is implicitly interpreted as Array of integers modulo 256
4563{
4664 const ui32 = new Uint32Array ( 4 ) . fill ( 42 ) ;
4765 const e = Buffer . from ( ui32 ) ;
@@ -50,11 +68,12 @@ assert.strictEqual(d.length, 0);
5068 }
5169}
5270// Test creating a Buffer from a Uint32Array (old constructor)
71+ // Note: it is implicitly interpreted as Array of integers modulo 256
5372{
5473 const ui32 = new Uint32Array ( 4 ) . fill ( 42 ) ;
5574 const e = Buffer ( ui32 ) ;
5675 for ( const [ key , value ] of e . entries ( ) ) {
57- assert . deepStrictEqual ( value , ui32 [ key ] ) ;
76+ assert . strictEqual ( value , ui32 [ key ] ) ;
5877 }
5978}
6079
0 commit comments