1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_6/String/codePointAt.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +var BUGNUMBER = 918879; 1.5 +var summary = 'String.prototype.codePointAt'; 1.6 + 1.7 +print(BUGNUMBER + ": " + summary); 1.8 + 1.9 +// Tests taken from: 1.10 +// https://github.com/mathiasbynens/String.prototype.codePointAt/blob/master/tests/tests.js 1.11 +assertEq(String.prototype.codePointAt.length, 1); 1.12 +assertEq(String.prototype.propertyIsEnumerable('codePointAt'), false); 1.13 + 1.14 +// String that starts with a BMP symbol 1.15 +assertEq('abc\uD834\uDF06def'.codePointAt(''), 0x61); 1.16 +assertEq('abc\uD834\uDF06def'.codePointAt('_'), 0x61); 1.17 +assertEq('abc\uD834\uDF06def'.codePointAt(), 0x61); 1.18 +assertEq('abc\uD834\uDF06def'.codePointAt(-Infinity), undefined); 1.19 +assertEq('abc\uD834\uDF06def'.codePointAt(-1), undefined); 1.20 +assertEq('abc\uD834\uDF06def'.codePointAt(-0), 0x61); 1.21 +assertEq('abc\uD834\uDF06def'.codePointAt(0), 0x61); 1.22 +assertEq('abc\uD834\uDF06def'.codePointAt(3), 0x1D306); 1.23 +assertEq('abc\uD834\uDF06def'.codePointAt(4), 0xDF06); 1.24 +assertEq('abc\uD834\uDF06def'.codePointAt(5), 0x64); 1.25 +assertEq('abc\uD834\uDF06def'.codePointAt(42), undefined); 1.26 +assertEq('abc\uD834\uDF06def'.codePointAt(Infinity), undefined); 1.27 +assertEq('abc\uD834\uDF06def'.codePointAt(Infinity), undefined); 1.28 +assertEq('abc\uD834\uDF06def'.codePointAt(NaN), 0x61); 1.29 +assertEq('abc\uD834\uDF06def'.codePointAt(false), 0x61); 1.30 +assertEq('abc\uD834\uDF06def'.codePointAt(null), 0x61); 1.31 +assertEq('abc\uD834\uDF06def'.codePointAt(undefined), 0x61); 1.32 + 1.33 +// String that starts with an astral symbol 1.34 +assertEq('\uD834\uDF06def'.codePointAt(''), 0x1D306); 1.35 +assertEq('\uD834\uDF06def'.codePointAt('1'), 0xDF06); 1.36 +assertEq('\uD834\uDF06def'.codePointAt('_'), 0x1D306); 1.37 +assertEq('\uD834\uDF06def'.codePointAt(), 0x1D306); 1.38 +assertEq('\uD834\uDF06def'.codePointAt(-1), undefined); 1.39 +assertEq('\uD834\uDF06def'.codePointAt(-0), 0x1D306); 1.40 +assertEq('\uD834\uDF06def'.codePointAt(0), 0x1D306); 1.41 +assertEq('\uD834\uDF06def'.codePointAt(1), 0xDF06); 1.42 +assertEq('\uD834\uDF06def'.codePointAt(42), undefined); 1.43 +assertEq('\uD834\uDF06def'.codePointAt(false), 0x1D306); 1.44 +assertEq('\uD834\uDF06def'.codePointAt(null), 0x1D306); 1.45 +assertEq('\uD834\uDF06def'.codePointAt(undefined), 0x1D306); 1.46 + 1.47 +// Lone high surrogates 1.48 +assertEq('\uD834abc'.codePointAt(''), 0xD834); 1.49 +assertEq('\uD834abc'.codePointAt('_'), 0xD834); 1.50 +assertEq('\uD834abc'.codePointAt(), 0xD834); 1.51 +assertEq('\uD834abc'.codePointAt(-1), undefined); 1.52 +assertEq('\uD834abc'.codePointAt(-0), 0xD834); 1.53 +assertEq('\uD834abc'.codePointAt(0), 0xD834); 1.54 +assertEq('\uD834abc'.codePointAt(false), 0xD834); 1.55 +assertEq('\uD834abc'.codePointAt(NaN), 0xD834); 1.56 +assertEq('\uD834abc'.codePointAt(null), 0xD834); 1.57 +assertEq('\uD834abc'.codePointAt(undefined), 0xD834); 1.58 + 1.59 +// Lone low surrogates 1.60 +assertEq('\uDF06abc'.codePointAt(''), 0xDF06); 1.61 +assertEq('\uDF06abc'.codePointAt('_'), 0xDF06); 1.62 +assertEq('\uDF06abc'.codePointAt(), 0xDF06); 1.63 +assertEq('\uDF06abc'.codePointAt(-1), undefined); 1.64 +assertEq('\uDF06abc'.codePointAt(-0), 0xDF06); 1.65 +assertEq('\uDF06abc'.codePointAt(0), 0xDF06); 1.66 +assertEq('\uDF06abc'.codePointAt(false), 0xDF06); 1.67 +assertEq('\uDF06abc'.codePointAt(NaN), 0xDF06); 1.68 +assertEq('\uDF06abc'.codePointAt(null), 0xDF06); 1.69 +assertEq('\uDF06abc'.codePointAt(undefined), 0xDF06); 1.70 + 1.71 +(function() { String.prototype.codePointAt.call(undefined); }, TypeError); 1.72 +assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(undefined, 4); }, TypeError); 1.73 +assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(null); }, TypeError); 1.74 +assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(null, 4); }, TypeError); 1.75 +assertEq(String.prototype.codePointAt.call(42, 0), 0x34); 1.76 +assertEq(String.prototype.codePointAt.call(42, 1), 0x32); 1.77 +assertEq(String.prototype.codePointAt.call({ 'toString': function() { return 'abc'; } }, 2), 0x63); 1.78 + 1.79 +assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(undefined); }, TypeError); 1.80 +assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(undefined, [4]); }, TypeError); 1.81 +assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(null); }, TypeError); 1.82 +assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(null, [4]); }, TypeError); 1.83 +assertEq(String.prototype.codePointAt.apply(42, [0]), 0x34); 1.84 +assertEq(String.prototype.codePointAt.apply(42, [1]), 0x32); 1.85 +assertEq(String.prototype.codePointAt.apply({ 'toString': function() { return 'abc'; } }, [2]), 0x63); 1.86 + 1.87 +reportCompare(0, 0, "ok");