summaryrefslogtreecommitdiff
path: root/test/parallel/test-buffer-fill.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2016-12-06 02:19:57 +0100
committerAnna Henningsen <anna@addaleax.net>2016-12-12 16:58:40 +0100
commit9ee915be76f9e4cc8bc43020a721a03257f9b984 (patch)
treef56973f121eb0644b8f0310c0dcd812e5d9491ba /test/parallel/test-buffer-fill.js
parentf418a227677a2801eaa1ceb084d64bd16e17fc45 (diff)
downloadandroid-node-v8-9ee915be76f9e4cc8bc43020a721a03257f9b984.tar.gz
android-node-v8-9ee915be76f9e4cc8bc43020a721a03257f9b984.tar.bz2
android-node-v8-9ee915be76f9e4cc8bc43020a721a03257f9b984.zip
buffer: handle UCS2 `.fill()` properly on BE
There was a byte-order mismatch for `buffer#fill` on big-endian platforms. Weirdly, the tests seemed to expect that wrong behaviour. PR-URL: https://github.com/nodejs/node/pull/9837 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'test/parallel/test-buffer-fill.js')
-rw-r--r--test/parallel/test-buffer-fill.js23
1 files changed, 10 insertions, 13 deletions
diff --git a/test/parallel/test-buffer-fill.js b/test/parallel/test-buffer-fill.js
index 4272d68694..68b8bbd69c 100644
--- a/test/parallel/test-buffer-fill.js
+++ b/test/parallel/test-buffer-fill.js
@@ -2,13 +2,11 @@
require('../common');
const assert = require('assert');
-const os = require('os');
const SIZE = 28;
const buf1 = Buffer.allocUnsafe(SIZE);
const buf2 = Buffer.allocUnsafe(SIZE);
-
// Default encoding
testBufs('abc');
testBufs('\u0222aa');
@@ -112,8 +110,7 @@ testBufs('\u0222aa', 8, 1, 'ucs2');
testBufs('a\u0234b\u0235c\u0236', 4, -1, 'ucs2');
testBufs('a\u0234b\u0235c\u0236', 4, 1, 'ucs2');
testBufs('a\u0234b\u0235c\u0236', 12, 1, 'ucs2');
-assert.strictEqual(Buffer.allocUnsafe(1).fill('\u0222', 'ucs2')[0],
- os.endianness() === 'LE' ? 0x22 : 0x02);
+assert.strictEqual(Buffer.allocUnsafe(1).fill('\u0222', 'ucs2')[0], 0x22);
// HEX
@@ -259,15 +256,6 @@ function writeToFill(string, offset, end, encoding) {
}
} while (offset < buf2.length);
- // Correction for UCS2 operations.
- if (os.endianness() === 'BE' && encoding === 'ucs2') {
- for (var i = 0; i < buf2.length; i += 2) {
- var tmp = buf2[i];
- buf2[i] = buf2[i + 1];
- buf2[i + 1] = tmp;
- }
- }
-
return buf2;
}
@@ -406,3 +394,12 @@ assert.throws(() => {
});
buf.fill('');
}, /^RangeError: out of range index$/);
+
+
+assert.deepStrictEqual(
+ Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'),
+ Buffer.from('61006200610062006100620061006200', 'hex'));
+
+assert.deepStrictEqual(
+ Buffer.allocUnsafeSlow(15).fill('ab', 'utf16le'),
+ Buffer.from('610062006100620061006200610062', 'hex'));