Skip to content

Commit

Permalink
Fix for test failure: encoding to UTF-16 is implementation dependent,…
Browse files Browse the repository at this point in the history
… output may be either big or little endian. Therefore, encode explicitly to UTF-16LE.
  • Loading branch information
bnoordhuis committed Sep 23, 2010
1 parent c5c3784 commit a2ff960
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions test-big-buffer.js
@@ -1,23 +1,18 @@
var Iconv = require('iconv').Iconv,
assert = require('assert');

var iconv = new Iconv('UTF-8', 'UTF-16');
var iconv = new Iconv('UTF-8', 'UTF-16LE');

var utf8 = new Buffer(20000000);
for (var i = 0; i < utf8.length; i++) {
utf8[i] = 97 + i % 26; // cycle from 'a' to 'z'.
}
var utf16 = iconv.convert(utf8);

// 2 bytes per character + 2 bytes for BOM
assert.equal(utf16.length, utf8.length * 2 + 2);

// test for BOM
assert.equal(utf16[0], 0xff);
assert.equal(utf16[1], 0xfe);
assert.equal(utf16.length, utf8.length * 2);

for (i = 0; i < utf8.length; ++i) {
assert.equal(utf16[2 + i * 2], utf8[i]);
assert.equal(utf16[2 + i * 2 + 1], 0);
assert.equal(utf16[i * 2], utf8[i]);
assert.equal(utf16[i * 2 + 1], 0);
}

0 comments on commit a2ff960

Please sign in to comment.