js/src/tests/js1_5/extensions/toLocaleFormat-01.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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 //-----------------------------------------------------------------------------
michael@0 7 var BUGNUMBER = 291494;
michael@0 8 var summary = 'Date.prototype.toLocaleFormat extension';
michael@0 9 var actual = '';
michael@0 10 var expect = '';
michael@0 11 var temp;
michael@0 12
michael@0 13 /*
michael@0 14 * SpiderMonkey only.
michael@0 15 *
michael@0 16 * When the output of toLocaleFormat exceeds 100 bytes toLocaleFormat
michael@0 17 * defaults to using toString to produce the result.
michael@0 18 */
michael@0 19
michael@0 20 enterFunc ('test');
michael@0 21 printBugNumber(BUGNUMBER);
michael@0 22 printStatus (summary);
michael@0 23
michael@0 24 var date = new Date("06/05/2005 00:00:00 GMT-0000");
michael@0 25
michael@0 26 expect = date.getTimezoneOffset() > 0 ? 'Sat' : 'Sun';
michael@0 27 actual = date.toLocaleFormat('%a');
michael@0 28 reportCompare(expect, actual, 'Date.toLocaleFormat("%a")');
michael@0 29
michael@0 30 expect = date.getTimezoneOffset() > 0 ? 'Saturday' : 'Sunday';
michael@0 31 actual = date.toLocaleFormat('%A');
michael@0 32 reportCompare(expect, actual, 'Date.toLocaleFormat("%A")');
michael@0 33
michael@0 34 expect = 'Jun';
michael@0 35 actual = date.toLocaleFormat('%b');
michael@0 36 reportCompare(expect, actual, 'Date.toLocaleFormat("%b")');
michael@0 37
michael@0 38 expect = 'June';
michael@0 39 actual = date.toLocaleFormat('%B');
michael@0 40 reportCompare(expect, actual, 'Date.toLocaleFormat("%B")');
michael@0 41
michael@0 42 expect = (date.getTimezoneOffset() > 0) ? '04' : '05';
michael@0 43 actual = date.toLocaleFormat('%d');
michael@0 44 reportCompare(expect, actual, 'Date.toLocaleFormat("%d")');
michael@0 45
michael@0 46 expect = '0';
michael@0 47 actual = String((Number(date.toLocaleFormat('%H')) +
michael@0 48 date.getTimezoneOffset()/60) % 24);
michael@0 49 reportCompare(expect, actual, 'Date.toLocaleFormat(%H)');
michael@0 50
michael@0 51 expect = '12';
michael@0 52 actual = String(Number(date.toLocaleFormat('%I')) +
michael@0 53 date.getTimezoneOffset()/60);
michael@0 54 reportCompare(expect, actual, 'Date.toLocaleFormat(%I)');
michael@0 55
michael@0 56 expect = String(155 + ((date.getTimezoneOffset() > 0) ? 0 : 1));
michael@0 57 actual = date.toLocaleFormat('%j');
michael@0 58 reportCompare(expect, actual, 'Date.toLocaleFormat("%j")');
michael@0 59
michael@0 60 expect = '06';
michael@0 61 actual = date.toLocaleFormat('%m');
michael@0 62 reportCompare(expect, actual, 'Date.toLocaleFormat("%m")');
michael@0 63
michael@0 64 expect = '00';
michael@0 65 actual = date.toLocaleFormat('%M');
michael@0 66 reportCompare(expect, actual, 'Date.toLocaleFormat("%M")');
michael@0 67
michael@0 68 expect = true;
michael@0 69 temp = date.toLocaleFormat('%p');
michael@0 70 actual = temp == 'AM' || date.toLocaleFormat('%p') == 'PM';
michael@0 71 reportCompare(expect, actual, 'Date.toLocaleFormat("%p") is AM or PM');
michael@0 72
michael@0 73 expect = '00';
michael@0 74 actual = date.toLocaleFormat('%S');
michael@0 75 reportCompare(expect, actual, 'Date.toLocaleFormat("%S")');
michael@0 76
michael@0 77 expect = String(22 + ((date.getTimezoneOffset() > 0) ? 0 : 1));
michael@0 78 actual = date.toLocaleFormat('%U');
michael@0 79 reportCompare(expect, actual, 'Date.toLocaleFormat("%U")');
michael@0 80
michael@0 81 expect = String((6 + ((date.getTimezoneOffset() > 0) ? 0 : 1))%7);
michael@0 82 actual = date.toLocaleFormat('%w');
michael@0 83 reportCompare(expect, actual, 'Date.toLocaleFormat("%w")');
michael@0 84
michael@0 85 expect = '22';
michael@0 86 actual = date.toLocaleFormat('%W');
michael@0 87 reportCompare(expect, actual, 'Date.toLocaleFormat("%W")');
michael@0 88
michael@0 89 expect = '05';
michael@0 90 actual = date.toLocaleFormat('%y');
michael@0 91 reportCompare(expect, actual, 'Date.toLocaleFormat("%y")');
michael@0 92
michael@0 93 expect = '2005';
michael@0 94 actual = date.toLocaleFormat('%Y');
michael@0 95 reportCompare(expect, actual, 'Date.toLocaleFormat("%Y")');
michael@0 96
michael@0 97 expect = '%';
michael@0 98 actual = date.toLocaleFormat('%%');
michael@0 99 reportCompare(expect, actual, 'Date.toLocaleFormat("%%")');
michael@0 100
michael@0 101
michael@0 102 expect = '1899 99';
michael@0 103 temp='%Y %y';
michael@0 104 actual = new Date(0, 0, 0, 13, 14, 15, 0).toLocaleFormat(temp);
michael@0 105 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 106
michael@0 107 expect = '1899189918991899189918991899189918991899189918991899189918991899189918991899189918991899';
michael@0 108 temp = '%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 109 actual = new Date(0, 0, 0, 13, 14, 15, 0).toLocaleFormat(temp);
michael@0 110 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 111
michael@0 112 expect = 'xxx189918991899189918991899189918991899189918991899189918991899189918991899189918991899189918991899';
michael@0 113 temp = 'xxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 114 actual = new Date(0, 0, 0, 13, 14, 15, 0).toLocaleFormat(temp);
michael@0 115 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 116
michael@0 117 expect = new Date(0, 0, 0, 13, 14, 15, 0).toString();
michael@0 118 temp = 'xxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 119 actual = new Date(0, 0, 0, 13, 14, 15, 0).toLocaleFormat(temp);
michael@0 120 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 121
michael@0 122 expect = 'xxxx189918991899189918991899189918991899';
michael@0 123 temp = 'xxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 124 actual = new Date(0, 0, 0, 13, 14, 15, 0).toLocaleFormat(temp);
michael@0 125 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 126
michael@0 127
michael@0 128 expect = '-51 49';
michael@0 129 temp = '%Y %y';
michael@0 130 actual = new Date(-51, 0).toLocaleFormat(temp);
michael@0 131 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 132
michael@0 133 expect = '-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51';
michael@0 134 temp = '%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 135 actual = new Date(-51, 0).toLocaleFormat(temp);
michael@0 136 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 137
michael@0 138 expect = 'xxx-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51-51';
michael@0 139 temp = 'xxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 140 actual = new Date(-51, 0).toLocaleFormat(temp);
michael@0 141 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 142
michael@0 143 expect = new Date(-51, 0).toString();
michael@0 144 temp = 'xxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 145 actual = new Date(-51, 0).toLocaleFormat(temp);
michael@0 146 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 147
michael@0 148
michael@0 149 expect = '1851 51';
michael@0 150 temp = '%Y %y';
michael@0 151 actual = new Date(1851, 0).toLocaleFormat(temp);
michael@0 152 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 153
michael@0 154 expect = '1851185118511851185118511851185118511851185118511851185118511851185118511851185118511851';
michael@0 155 temp = '%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 156 actual = new Date(1851, 0).toLocaleFormat(temp);
michael@0 157 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 158
michael@0 159 expect = 'xxx185118511851185118511851185118511851185118511851185118511851185118511851185118511851185118511851';
michael@0 160 temp = 'xxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 161 actual = new Date(1851, 0).toLocaleFormat(temp);
michael@0 162 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 163
michael@0 164 expect = new Date(1851, 0).toString();
michael@0 165 temp = 'xxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 166 actual = new Date(1851, 0).toLocaleFormat(temp);
michael@0 167 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 168
michael@0 169
michael@0 170 expect = '-1 99';
michael@0 171 temp = '%Y %y';
michael@0 172 actual = new Date(-1, 0).toLocaleFormat(temp);
michael@0 173 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 174
michael@0 175 expect = '-100 00';
michael@0 176 temp = '%Y %y';
michael@0 177 actual = new Date(-100, 0).toLocaleFormat(temp);
michael@0 178 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 179
michael@0 180 expect = '1900 00';
michael@0 181 temp = '%Y %y';
michael@0 182 actual = new Date(0, 0).toLocaleFormat(temp);
michael@0 183 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 184
michael@0 185 expect = '1901 01';
michael@0 186 temp = '%Y %y';
michael@0 187 actual = new Date(1, 0).toLocaleFormat(temp);
michael@0 188 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 189
michael@0 190 expect = '1970 70';
michael@0 191 temp = '%Y %y';
michael@0 192 actual = new Date(1970, 0).toLocaleFormat(temp);
michael@0 193 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 194
michael@0 195
michael@0 196 expect = new Date(32767, 0).toString();
michael@0 197 temp = 'xxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 198 actual = new Date(32767, 0).toLocaleFormat(temp);
michael@0 199 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 200
michael@0 201 expect = '32767327673276732767327673276732767327673276732767327673276732767327673276732767327673276732767';
michael@0 202 temp = '%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 203 actual = new Date(32767, 0).toLocaleFormat(temp);
michael@0 204 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 205
michael@0 206 expect = 'xxxx32767327673276732767327673276732767327673276732767327673276732767327673276732767327673276732767';
michael@0 207 temp = 'xxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 208 actual = new Date(32767, 0).toLocaleFormat(temp);
michael@0 209 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 210
michael@0 211 expect = new Date(32767, 0).toString();
michael@0 212 temp = 'xxxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 213 actual = new Date(32767, 0).toLocaleFormat(temp);
michael@0 214 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 215
michael@0 216
michael@0 217 expect = '-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999';
michael@0 218 temp = '%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 219 actual = new Date(-9999, 0).toLocaleFormat(temp);
michael@0 220 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 221
michael@0 222 expect = 'xxxx-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999-9999';
michael@0 223 temp = 'xxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 224 actual = new Date(-9999, 0).toLocaleFormat(temp);
michael@0 225 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');
michael@0 226
michael@0 227 expect = new Date(-9999, 0).toString();
michael@0 228 temp = 'xxxx%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y%Y';
michael@0 229 actual = new Date(-9999, 0).toLocaleFormat(temp);
michael@0 230 reportCompare(expect, actual, 'Date.toLocaleFormat("'+temp+'")');

mercurial