| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,25 @@ assert.strictEqual(d.length, 0); | |||
| 41 | 41 | assert.strictEqual(b.offset, 0); | |
| 42 | 42 | } | |
| 43 | 43 | ||
| 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 | + | ||
| 44 | 61 | // Test creating a Buffer from a Uint32Array | |
| 62 | + // Note: it is implicitly interpreted as Array of integers modulo 256 | ||
| 45 | 63 | { | |
| 46 | 64 | const ui32 = new Uint32Array(4).fill(42); | |
| 47 | 65 | const e = Buffer.from(ui32); | |
@@ -50,11 +68,12 @@ assert.strictEqual(d.length, 0); | |||
| 50 | 68 | } | |
| 51 | 69 | } | |
| 52 | 70 | // Test creating a Buffer from a Uint32Array (old constructor) | |
| 71 | + // Note: it is implicitly interpreted as Array of integers modulo 256 | ||
| 53 | 72 | { | |
| 54 | 73 | const ui32 = new Uint32Array(4).fill(42); | |
| 55 | 74 | const e = Buffer(ui32); | |
| 56 | 75 | for (const [key, value] of e.entries()) { | |
| 57 | - assert.deepStrictEqual(value, ui32[key]); | ||
| 76 | + assert.strictEqual(value, ui32[key]); | ||
| 58 | 77 | } | |
| 59 | 78 | } | |
| 60 | 79 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,10 +47,10 @@ for (const ctor of intTypedConstructors) { | |||
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | 49 | { | |
| 50 | - const buf = new Uint16Array(10); | ||
| 51 | - const before = Buffer.from(buf).toString('hex'); | ||
| 50 | + const buf = Buffer.alloc(10); | ||
| 51 | + const before = buf.toString('hex'); | ||
| 52 | 52 | webcrypto.getRandomValues(buf); | |
| 53 | - const after = Buffer.from(buf).toString('hex'); | ||
| 53 | + const after = buf.toString('hex'); | ||
| 54 | 54 | assert.notStrictEqual(before, after); | |
| 55 | 55 | } | |
| 56 | 56 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments