diff options
author | Trevor Norris <trev.norris@gmail.com> | 2013-05-24 10:58:30 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2013-06-18 15:41:03 -0700 |
commit | 4b403588416e7928fbda31043d5e7aa56b5d87b0 (patch) | |
tree | b837e7e7bd0c5176080477d809465e8844234c6f /test/simple/test-buffer.js | |
parent | f4896491590032a42b892c59afd970f9ee031ab7 (diff) | |
download | node-new-4b403588416e7928fbda31043d5e7aa56b5d87b0.tar.gz |
buffer: implement new fill behavior
Old fill would take the char code of the first character and wrap around
the int to fit in the 127 range. Now fill will duplicate whatever string
is given through the entirety of the buffer.
Note: There is one bug around ending on a partial fill of any character
outside the ASCII range.
Diffstat (limited to 'test/simple/test-buffer.js')
-rw-r--r-- | test/simple/test-buffer.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index 19fa4eacb0..6975c8e4e5 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -120,6 +120,10 @@ for (var i = 0; i < b.length; i++) { assert.strictEqual(cntr, b[i]); } +// copy string longer than buffer length (failure will segfault) +var bb = new Buffer(10); +bb.fill('hello crazy world'); + var caught_error = null; @@ -637,6 +641,12 @@ for (var i = 0; i < 16; i++) assert.equal(0, b[i]); for (; i < 32; i++) assert.equal(1, b[i]); for (; i < b.length; i++) assert.equal(0, b[i]); +var buf = new Buffer(10); +buf.fill('abc'); +assert.equal(buf.toString(), 'abcabcabca'); +buf.fill('է'); +assert.equal(buf.toString(), 'էէէէէ'); + ['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) { var b = new Buffer(10); b.write('あいうえお', encoding); |