diff options
author | James M Snell <jasnell@gmail.com> | 2016-08-23 14:16:45 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-08-26 07:15:31 -0700 |
commit | 7053922c1a76ac56ef245923ec171b01cd90d2f4 (patch) | |
tree | 0464984232c835fe6e1d3ac2b429bdaaf77a6cbe /test/parallel/test-buffer-fill.js | |
parent | b3e7ac2605c18c041293cd3ab892c963e1145176 (diff) | |
download | android-node-v8-7053922c1a76ac56ef245923ec171b01cd90d2f4.tar.gz android-node-v8-7053922c1a76ac56ef245923ec171b01cd90d2f4.tar.bz2 android-node-v8-7053922c1a76ac56ef245923ec171b01cd90d2f4.zip |
test: clean up / refactor buffer tests, remove duplication
Remove duplication of buffer tests, separate out into separate
files, update and cleanup code, move to using strictEqual where
possible.
PR-URL: https://github.com/nodejs/node/pull/8256
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-fill.js')
-rw-r--r-- | test/parallel/test-buffer-fill.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js index 638fda819d..e5581b2d83 100644 --- a/test/parallel/test-buffer-fill.js +++ b/test/parallel/test-buffer-fill.js @@ -267,3 +267,50 @@ function testBufs(string, offset, length, encoding) { assert.deepStrictEqual(buf1.fill.apply(buf1, arguments), writeToFill.apply(null, arguments)); } + +// Make sure these throw. +assert.throws(() => Buffer.allocUnsafe(8).fill('a', -1)); +assert.throws(() => Buffer.allocUnsafe(8).fill('a', 0, 9)); + +// Make sure this doesn't hang indefinitely. +Buffer.allocUnsafe(8).fill(''); +Buffer.alloc(8, ''); + +{ + const buf = Buffer.alloc(64, 10); + for (let i = 0; i < buf.length; i++) + assert.strictEqual(buf[i], 10); + + buf.fill(11, 0, buf.length >> 1); + for (let i = 0; i < buf.length >> 1; i++) + assert.strictEqual(buf[i], 11); + for (let i = (buf.length >> 1) + 1; i < buf.length; i++) + assert.strictEqual(buf[i], 10); + + buf.fill('h'); + for (let i = 0; i < buf.length; i++) + assert.strictEqual('h'.charCodeAt(0), buf[i]); + + buf.fill(0); + for (let i = 0; i < buf.length; i++) + assert.strictEqual(0, buf[i]); + + buf.fill(null); + for (let i = 0; i < buf.length; i++) + assert.strictEqual(0, buf[i]); + + buf.fill(1, 16, 32); + for (let i = 0; i < 16; i++) + assert.strictEqual(0, buf[i]); + for (let i = 16; i < 32; i++) + assert.strictEqual(1, buf[i]); + for (let i = 32; i < buf.length; i++) + assert.strictEqual(0, buf[i]); +} + +{ + const buf = Buffer.alloc(10, 'abc'); + assert.strictEqual(buf.toString(), 'abcabcabca'); + buf.fill('է'); + assert.strictEqual(buf.toString(), 'էէէէէ'); +} |