michael@0: var BUGNUMBER = 918879; michael@0: var summary = 'String.prototype.codePointAt'; michael@0: michael@0: print(BUGNUMBER + ": " + summary); michael@0: michael@0: // Tests taken from: michael@0: // https://github.com/mathiasbynens/String.prototype.codePointAt/blob/master/tests/tests.js michael@0: assertEq(String.prototype.codePointAt.length, 1); michael@0: assertEq(String.prototype.propertyIsEnumerable('codePointAt'), false); michael@0: michael@0: // String that starts with a BMP symbol michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(''), 0x61); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt('_'), 0x61); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(), 0x61); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(-Infinity), undefined); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(-1), undefined); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(-0), 0x61); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(0), 0x61); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(3), 0x1D306); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(4), 0xDF06); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(5), 0x64); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(42), undefined); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(Infinity), undefined); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(Infinity), undefined); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(NaN), 0x61); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(false), 0x61); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(null), 0x61); michael@0: assertEq('abc\uD834\uDF06def'.codePointAt(undefined), 0x61); michael@0: michael@0: // String that starts with an astral symbol michael@0: assertEq('\uD834\uDF06def'.codePointAt(''), 0x1D306); michael@0: assertEq('\uD834\uDF06def'.codePointAt('1'), 0xDF06); michael@0: assertEq('\uD834\uDF06def'.codePointAt('_'), 0x1D306); michael@0: assertEq('\uD834\uDF06def'.codePointAt(), 0x1D306); michael@0: assertEq('\uD834\uDF06def'.codePointAt(-1), undefined); michael@0: assertEq('\uD834\uDF06def'.codePointAt(-0), 0x1D306); michael@0: assertEq('\uD834\uDF06def'.codePointAt(0), 0x1D306); michael@0: assertEq('\uD834\uDF06def'.codePointAt(1), 0xDF06); michael@0: assertEq('\uD834\uDF06def'.codePointAt(42), undefined); michael@0: assertEq('\uD834\uDF06def'.codePointAt(false), 0x1D306); michael@0: assertEq('\uD834\uDF06def'.codePointAt(null), 0x1D306); michael@0: assertEq('\uD834\uDF06def'.codePointAt(undefined), 0x1D306); michael@0: michael@0: // Lone high surrogates michael@0: assertEq('\uD834abc'.codePointAt(''), 0xD834); michael@0: assertEq('\uD834abc'.codePointAt('_'), 0xD834); michael@0: assertEq('\uD834abc'.codePointAt(), 0xD834); michael@0: assertEq('\uD834abc'.codePointAt(-1), undefined); michael@0: assertEq('\uD834abc'.codePointAt(-0), 0xD834); michael@0: assertEq('\uD834abc'.codePointAt(0), 0xD834); michael@0: assertEq('\uD834abc'.codePointAt(false), 0xD834); michael@0: assertEq('\uD834abc'.codePointAt(NaN), 0xD834); michael@0: assertEq('\uD834abc'.codePointAt(null), 0xD834); michael@0: assertEq('\uD834abc'.codePointAt(undefined), 0xD834); michael@0: michael@0: // Lone low surrogates michael@0: assertEq('\uDF06abc'.codePointAt(''), 0xDF06); michael@0: assertEq('\uDF06abc'.codePointAt('_'), 0xDF06); michael@0: assertEq('\uDF06abc'.codePointAt(), 0xDF06); michael@0: assertEq('\uDF06abc'.codePointAt(-1), undefined); michael@0: assertEq('\uDF06abc'.codePointAt(-0), 0xDF06); michael@0: assertEq('\uDF06abc'.codePointAt(0), 0xDF06); michael@0: assertEq('\uDF06abc'.codePointAt(false), 0xDF06); michael@0: assertEq('\uDF06abc'.codePointAt(NaN), 0xDF06); michael@0: assertEq('\uDF06abc'.codePointAt(null), 0xDF06); michael@0: assertEq('\uDF06abc'.codePointAt(undefined), 0xDF06); michael@0: michael@0: (function() { String.prototype.codePointAt.call(undefined); }, TypeError); michael@0: assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(undefined, 4); }, TypeError); michael@0: assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(null); }, TypeError); michael@0: assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(null, 4); }, TypeError); michael@0: assertEq(String.prototype.codePointAt.call(42, 0), 0x34); michael@0: assertEq(String.prototype.codePointAt.call(42, 1), 0x32); michael@0: assertEq(String.prototype.codePointAt.call({ 'toString': function() { return 'abc'; } }, 2), 0x63); michael@0: michael@0: assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(undefined); }, TypeError); michael@0: assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(undefined, [4]); }, TypeError); michael@0: assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(null); }, TypeError); michael@0: assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(null, [4]); }, TypeError); michael@0: assertEq(String.prototype.codePointAt.apply(42, [0]), 0x34); michael@0: assertEq(String.prototype.codePointAt.apply(42, [1]), 0x32); michael@0: assertEq(String.prototype.codePointAt.apply({ 'toString': function() { return 'abc'; } }, [2]), 0x63); michael@0: michael@0: reportCompare(0, 0, "ok");