blob: 9b6d97fa79fc78743251dedc0016234c0c7030f1 [file] [log] [blame]
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
function testWithLength(length, index) {
shouldBe(length >= 1, true);
var array = [];
for (var i = 0; i < length; ++i)
array[i] = i & 0xff;
array[index] = 0xffef;
var string = String.fromCharCode.apply(String, array);
shouldBe(string.length, length);
for (var i = 0; i < length; ++i) {
if (index === i)
shouldBe(string[i], String.fromCharCode(0xffef));
else
shouldBe(string[i], String.fromCharCode(i & 0xff));
}
}
testWithLength(1e4, 1e4 - 1);
testWithLength(1e4, 1e3);
testWithLength(1, 0);
testWithLength(2, 1);
testWithLength(2, 0);