js/src/tests/ecma_6/String/codePointAt.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 var BUGNUMBER = 918879;
michael@0 2 var summary = 'String.prototype.codePointAt';
michael@0 3
michael@0 4 print(BUGNUMBER + ": " + summary);
michael@0 5
michael@0 6 // Tests taken from:
michael@0 7 // https://github.com/mathiasbynens/String.prototype.codePointAt/blob/master/tests/tests.js
michael@0 8 assertEq(String.prototype.codePointAt.length, 1);
michael@0 9 assertEq(String.prototype.propertyIsEnumerable('codePointAt'), false);
michael@0 10
michael@0 11 // String that starts with a BMP symbol
michael@0 12 assertEq('abc\uD834\uDF06def'.codePointAt(''), 0x61);
michael@0 13 assertEq('abc\uD834\uDF06def'.codePointAt('_'), 0x61);
michael@0 14 assertEq('abc\uD834\uDF06def'.codePointAt(), 0x61);
michael@0 15 assertEq('abc\uD834\uDF06def'.codePointAt(-Infinity), undefined);
michael@0 16 assertEq('abc\uD834\uDF06def'.codePointAt(-1), undefined);
michael@0 17 assertEq('abc\uD834\uDF06def'.codePointAt(-0), 0x61);
michael@0 18 assertEq('abc\uD834\uDF06def'.codePointAt(0), 0x61);
michael@0 19 assertEq('abc\uD834\uDF06def'.codePointAt(3), 0x1D306);
michael@0 20 assertEq('abc\uD834\uDF06def'.codePointAt(4), 0xDF06);
michael@0 21 assertEq('abc\uD834\uDF06def'.codePointAt(5), 0x64);
michael@0 22 assertEq('abc\uD834\uDF06def'.codePointAt(42), undefined);
michael@0 23 assertEq('abc\uD834\uDF06def'.codePointAt(Infinity), undefined);
michael@0 24 assertEq('abc\uD834\uDF06def'.codePointAt(Infinity), undefined);
michael@0 25 assertEq('abc\uD834\uDF06def'.codePointAt(NaN), 0x61);
michael@0 26 assertEq('abc\uD834\uDF06def'.codePointAt(false), 0x61);
michael@0 27 assertEq('abc\uD834\uDF06def'.codePointAt(null), 0x61);
michael@0 28 assertEq('abc\uD834\uDF06def'.codePointAt(undefined), 0x61);
michael@0 29
michael@0 30 // String that starts with an astral symbol
michael@0 31 assertEq('\uD834\uDF06def'.codePointAt(''), 0x1D306);
michael@0 32 assertEq('\uD834\uDF06def'.codePointAt('1'), 0xDF06);
michael@0 33 assertEq('\uD834\uDF06def'.codePointAt('_'), 0x1D306);
michael@0 34 assertEq('\uD834\uDF06def'.codePointAt(), 0x1D306);
michael@0 35 assertEq('\uD834\uDF06def'.codePointAt(-1), undefined);
michael@0 36 assertEq('\uD834\uDF06def'.codePointAt(-0), 0x1D306);
michael@0 37 assertEq('\uD834\uDF06def'.codePointAt(0), 0x1D306);
michael@0 38 assertEq('\uD834\uDF06def'.codePointAt(1), 0xDF06);
michael@0 39 assertEq('\uD834\uDF06def'.codePointAt(42), undefined);
michael@0 40 assertEq('\uD834\uDF06def'.codePointAt(false), 0x1D306);
michael@0 41 assertEq('\uD834\uDF06def'.codePointAt(null), 0x1D306);
michael@0 42 assertEq('\uD834\uDF06def'.codePointAt(undefined), 0x1D306);
michael@0 43
michael@0 44 // Lone high surrogates
michael@0 45 assertEq('\uD834abc'.codePointAt(''), 0xD834);
michael@0 46 assertEq('\uD834abc'.codePointAt('_'), 0xD834);
michael@0 47 assertEq('\uD834abc'.codePointAt(), 0xD834);
michael@0 48 assertEq('\uD834abc'.codePointAt(-1), undefined);
michael@0 49 assertEq('\uD834abc'.codePointAt(-0), 0xD834);
michael@0 50 assertEq('\uD834abc'.codePointAt(0), 0xD834);
michael@0 51 assertEq('\uD834abc'.codePointAt(false), 0xD834);
michael@0 52 assertEq('\uD834abc'.codePointAt(NaN), 0xD834);
michael@0 53 assertEq('\uD834abc'.codePointAt(null), 0xD834);
michael@0 54 assertEq('\uD834abc'.codePointAt(undefined), 0xD834);
michael@0 55
michael@0 56 // Lone low surrogates
michael@0 57 assertEq('\uDF06abc'.codePointAt(''), 0xDF06);
michael@0 58 assertEq('\uDF06abc'.codePointAt('_'), 0xDF06);
michael@0 59 assertEq('\uDF06abc'.codePointAt(), 0xDF06);
michael@0 60 assertEq('\uDF06abc'.codePointAt(-1), undefined);
michael@0 61 assertEq('\uDF06abc'.codePointAt(-0), 0xDF06);
michael@0 62 assertEq('\uDF06abc'.codePointAt(0), 0xDF06);
michael@0 63 assertEq('\uDF06abc'.codePointAt(false), 0xDF06);
michael@0 64 assertEq('\uDF06abc'.codePointAt(NaN), 0xDF06);
michael@0 65 assertEq('\uDF06abc'.codePointAt(null), 0xDF06);
michael@0 66 assertEq('\uDF06abc'.codePointAt(undefined), 0xDF06);
michael@0 67
michael@0 68 (function() { String.prototype.codePointAt.call(undefined); }, TypeError);
michael@0 69 assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(undefined, 4); }, TypeError);
michael@0 70 assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(null); }, TypeError);
michael@0 71 assertThrowsInstanceOf(function() { String.prototype.codePointAt.call(null, 4); }, TypeError);
michael@0 72 assertEq(String.prototype.codePointAt.call(42, 0), 0x34);
michael@0 73 assertEq(String.prototype.codePointAt.call(42, 1), 0x32);
michael@0 74 assertEq(String.prototype.codePointAt.call({ 'toString': function() { return 'abc'; } }, 2), 0x63);
michael@0 75
michael@0 76 assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(undefined); }, TypeError);
michael@0 77 assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(undefined, [4]); }, TypeError);
michael@0 78 assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(null); }, TypeError);
michael@0 79 assertThrowsInstanceOf(function() { String.prototype.codePointAt.apply(null, [4]); }, TypeError);
michael@0 80 assertEq(String.prototype.codePointAt.apply(42, [0]), 0x34);
michael@0 81 assertEq(String.prototype.codePointAt.apply(42, [1]), 0x32);
michael@0 82 assertEq(String.prototype.codePointAt.apply({ 'toString': function() { return 'abc'; } }, [2]), 0x63);
michael@0 83
michael@0 84 reportCompare(0, 0, "ok");

mercurial