Bug 1018311 part 3 - Add tests. r=luke

This commit is contained in:
Jan de Mooij 2014-06-03 13:15:26 +02:00
Родитель 50c08461e0
Коммит bd37da5350
2 изменённых файлов: 104 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,73 @@
function testSubstrLatin1() {
var s1 = toLatin1("abcdefghijklmnopqrstuvwxyz12345678900000a");
// Static strings.
assertEq(s1.substr(s1.length - 1), "a");
assertEq(s1.substr(s1.length - 2), "0a");
assertEq(s1.substr(26, 3), "123");
// (Fat) inline strings.
var s2 = s1.substr(3, 5);
assertEq(isLatin1(s2), true);
assertEq(s2, "defgh");
s2 = s1.substr(0, 20);
assertEq(isLatin1(s2), true);
assertEq(s2, "abcdefghijklmnopqrst");
// Dependent string.
s2 = s1.substr(1, s1.length - 2);
assertEq(isLatin1(s2), true);
assertEq(s2.length, 39);
assertEq(s2, "bcdefghijklmnopqrstuvwxyz12345678900000");
s2 = s2.substr(2).substr(1);
assertEq(isLatin1(s2), true);
assertEq(s2, "efghijklmnopqrstuvwxyz12345678900000");
}
testSubstrLatin1();
function testSubstrTwoByte() {
// Two byte string.
var s1 = "abcdefghijklmnopqrstuvwxyz12345678900000a\u1480";
assertEq(isLatin1(s1), false);
// Static string.
var s2 = s1.substr(28, 1);
assertEq(s2, "3");
// Inline string.
s2 = s1.substr(3, 5);
assertEq(s2, "defgh");
// Dependent string.
s2 = s1.substr(2);
assertEq(isLatin1(s2), false);
assertEq(s2, "cdefghijklmnopqrstuvwxyz12345678900000a\u1480");
s2 = s2.substr(2).substr(1);
assertEq(isLatin1(s2), false);
assertEq(s2, "fghijklmnopqrstuvwxyz12345678900000a\u1480");
}
testSubstrTwoByte();
function testSubstring() {
var s1 = toLatin1("abcdefghijklmnopqrstuvwxyz123456789000ab");
var s2 = s1.substring(1, 8);
assertEq(isLatin1(s2), true);
assertEq(s2, "bcdefgh");
s2 = s1.substring(0, s1.length - 1);
assertEq(isLatin1(s2), true);
assertEq(s2, "abcdefghijklmnopqrstuvwxyz123456789000a");
}
testSubstring();
function testSlice() {
var s1 = toLatin1("abcdefghijklmnopqrstuvwxyz123456789000ABC");
var s2 = s1.slice(1, 8);
assertEq(isLatin1(s2), true);
assertEq(s2, "bcdefgh");
s2 = s1.slice(0, -2);
assertEq(isLatin1(s2), true);
assertEq(s2, "abcdefghijklmnopqrstuvwxyz123456789000A");
}
testSlice();

Просмотреть файл

@ -0,0 +1,31 @@
var s1 = toLatin1("abcdefg12345");
var s2 = toLatin1('foo"bar');
function test() {
assertEq(s1.valueOf(), s1);
assertEq(s1.bold(), "<b>abcdefg12345</b>");
assertEq(s1.fontsize("twoByte\u1400"), '<font size="twoByte\u1400">abcdefg12345</font>');
assertEq(s1.anchor(s1), '<a name="abcdefg12345">abcdefg12345</a>');
assertEq(s1.link(s2), '<a href="foo&quot;bar">abcdefg12345</a>');
assertEq(s1.concat("abc"), "abcdefg12345abc");
var s3 = s1.concat(s1, s1);
assertEq(isLatin1(s3), true);
assertEq(s3, "abcdefg12345abcdefg12345abcdefg12345");
s3 = s1.concat("twoByte\u1400");
assertEq(isLatin1(s3), false);
assertEq(s3, "abcdefg12345twoByte\u1400");
assertEq(s1.codePointAt(3), 100);
assertEq(s1.codePointAt(10), 52);
assertEq(s1.codePointAt(12), undefined);
s3 = s1.repeat(5);
assertEq(s3, "abcdefg12345abcdefg12345abcdefg12345abcdefg12345abcdefg12345");
assertEq(isLatin1(s3), true);
}
test();
test();