diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:30:52 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:30:52 -0800 |
commit | 8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2 (patch) | |
tree | 11425ea0b299d6fb89c6d3618a22d97d5bf68d0f /JavaScriptCore/tests/mozilla/ecma_3/Date | |
parent | 648161bb0edfc3d43db63caed5cc5213bc6cb78f (diff) | |
download | external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.zip external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.tar.gz external_webkit-8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'JavaScriptCore/tests/mozilla/ecma_3/Date')
-rw-r--r-- | JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.3.js | 149 | ||||
-rw-r--r-- | JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.4.js | 194 | ||||
-rw-r--r-- | JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.5.js | 94 | ||||
-rw-r--r-- | JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.6.js | 149 | ||||
-rw-r--r-- | JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.7.js | 211 | ||||
-rw-r--r-- | JavaScriptCore/tests/mozilla/ecma_3/Date/shell.js | 676 |
6 files changed, 1473 insertions, 0 deletions
diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.3.js b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.3.js new file mode 100644 index 0000000..a68cb89 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.3.js @@ -0,0 +1,149 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: 15.9.5.3.js + ECMA Section: 15.9.5.3 Date.prototype.toDateString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "date" + portion of the Date in the current time zone in a convenient, + human-readable form. We can't test the content of the string, + but can verify that the string is parsable by Date.parse + + The toDateString function is not generic; it generates a runtime error + if its 'this' value is not a Date object. Therefore it cannot be transferred + to other kinds of objects for use as a method. + + Author: pschwartau@netscape.com + Date: 14 november 2000 (adapted from ecma/Date/15.9.5.2.js) +*/ + + var SECTION = "15.9.5.3"; + var VERSION = "ECMA_3"; + var TITLE = "Date.prototype.toDateString()"; + + var status = ''; + var actual = ''; + var expect = ''; + + + startTest(); + writeHeaderToLog( SECTION + " "+ TITLE); + + +//----------------------------------------------------------------------------------------------------- + var testcases = new Array(); +//----------------------------------------------------------------------------------------------------- + + + // first, some generic tests - + + status = "typeof (now.toDateString())"; + actual = typeof (now.toDateString()); + expect = "string"; + addTestCase(); + + status = "Date.prototype.toDateString.length"; + actual = Date.prototype.toDateString.length; + expect = 0; + addTestCase(); + + /* Date.parse is accurate to the second; valueOf() to the millisecond. + Here we expect them to coincide, as we expect a time of exactly midnight - */ + status = "(Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0"; + actual = (Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0; + expect = true; + addTestCase(); + + + + // 1970 + addDateTestCase(0); + addDateTestCase(TZ_ADJUST); + + + // 1900 + addDateTestCase(TIME_1900); + addDateTestCase(TIME_1900 - TZ_ADJUST); + + + // 2000 + addDateTestCase(TIME_2000); + addDateTestCase(TIME_2000 - TZ_ADJUST); + + + // 29 Feb 2000 + addDateTestCase(UTC_29_FEB_2000); + addDateTestCase(UTC_29_FEB_2000 - 1000); + addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + + + // 2005 + addDateTestCase(UTC_1_JAN_2005); + addDateTestCase(UTC_1_JAN_2005 - 1000); + addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); + + + +//----------------------------------------------------------------------------------------------------- + test(); +//----------------------------------------------------------------------------------------------------- + + +function addTestCase() +{ + testcases[tc++] = new TestCase( SECTION, status, expect, actual); +} + + +function addDateTestCase(date_given_in_milliseconds) +{ + var givenDate = new Date(date_given_in_milliseconds); + + status = 'Date.parse(' + givenDate + ').toDateString())'; + actual = Date.parse(givenDate.toDateString()); + expect = Date.parse(midnight(givenDate)); + addTestCase(); +} + + +function midnight(givenDate) +{ + // midnight on the given date - + return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate()); +} + + +function test() +{ + for ( tc=0; tc < testcases.length; tc++ ) + { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description + " = " + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return (testcases); +}
\ No newline at end of file diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.4.js b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.4.js new file mode 100644 index 0000000..abff98a --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.4.js @@ -0,0 +1,194 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: 15.9.5.4.js + ECMA Section: 15.9.5.4 Date.prototype.toTimeString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "time" + portion of the Date in the current time zone in a convenient, + human-readable form. We test the content of the string by checking + that d.toDateString() + d.toTimeString() == d.toString() + + Author: pschwartau@netscape.com + Date: 14 november 2000 + Revised: 07 january 2002 because of a change in JS Date format: + + See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) + See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) +*/ +//----------------------------------------------------------------------------- + var SECTION = "15.9.5.4"; + var VERSION = "ECMA_3"; + var TITLE = "Date.prototype.toTimeString()"; + + var status = ''; + var actual = ''; + var expect = ''; + var givenDate; + var year = ''; + var regexp = ''; + var reducedDateString = ''; + var hopeThisIsTimeString = ''; + var cnEmptyString = ''; + var cnERR ='OOPS! FATAL ERROR: no regexp match in extractTimeString()'; + + + + startTest(); + writeHeaderToLog( SECTION + " "+ TITLE); + + +//----------------------------------------------------------------------------------------------------- + var testcases = new Array(); +//----------------------------------------------------------------------------------------------------- + + + // first, a couple of generic tests - + + status = "typeof (now.toTimeString())"; + actual = typeof (now.toTimeString()); + expect = "string"; + addTestCase(); + + status = "Date.prototype.toTimeString.length"; + actual = Date.prototype.toTimeString.length; + expect = 0; + addTestCase(); + + + + + // 1970 + addDateTestCase(0); + addDateTestCase(TZ_ADJUST); + + + // 1900 + addDateTestCase(TIME_1900); + addDateTestCase(TIME_1900 - TZ_ADJUST); + + + // 2000 + addDateTestCase(TIME_2000); + addDateTestCase(TIME_2000 - TZ_ADJUST); + + + // 29 Feb 2000 + addDateTestCase(UTC_29_FEB_2000); + addDateTestCase(UTC_29_FEB_2000 - 1000); + addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + + + // Now + addDateTestCase( TIME_NOW); + addDateTestCase( TIME_NOW - TZ_ADJUST); + + + // 2005 + addDateTestCase(UTC_1_JAN_2005); + addDateTestCase(UTC_1_JAN_2005 - 1000); + addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); + + + +//----------------------------------------------------------------------------------------------------- + test(); +//----------------------------------------------------------------------------------------------------- + + +function addTestCase() +{ + testcases[tc++] = new TestCase( SECTION, status, expect, actual); +} + + +function addDateTestCase(date_given_in_milliseconds) +{ + givenDate = new Date(date_given_in_milliseconds); + + status = '(' + givenDate + ').toTimeString()'; + actual = givenDate.toTimeString(); + expect = extractTimeString(givenDate); + addTestCase(); +} + + +/* + * As of 2002-01-07, the format for JavaScript dates changed. + * See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) + * See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) + * + * WAS: Mon Jan 07 13:40:34 GMT-0800 (Pacific Standard Time) 2002 + * NOW: Mon Jan 07 2002 13:40:34 GMT-0800 (Pacific Standard Time) + * + * Thus, use a regexp of the form /date.toDateString()(.*)$/ + * to capture the TimeString into the first backreference - + */ +function extractTimeString(date) +{ + regexp = new RegExp(date.toDateString() + '(.*)' + '$'); + + try + { + hopeThisIsTimeString = date.toString().match(regexp)[1]; + } + catch(e) + { + return cnERR; + } + + // trim any leading or trailing spaces - + return trimL(trimR(hopeThisIsTimeString)); + } + + +function trimL(s) +{ + if (!s) {return cnEmptyString;}; + for (var i = 0; i!=s.length; i++) {if (s[i] != ' ') {break;}} + return s.substring(i); +} + + +function trimR(s) +{ + if (!s) {return cnEmptyString;}; + for (var i = (s.length - 1); i!=-1; i--) {if (s[i] != ' ') {break;}} + return s.substring(0, i+1); +} + + +function test() +{ + for ( tc=0; tc < testcases.length; tc++ ) + { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description + " = " + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return (testcases); +} diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.5.js b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.5.js new file mode 100644 index 0000000..c16002b --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.5.js @@ -0,0 +1,94 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: 15.9.5.5.js + ECMA Section: 15.9.5.5 Date.prototype.toLocaleString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "date" + portion of the Date in the current time zone in a convenient, + human-readable form. We can't test the content of the string, + but can verify that the object returned is a string. + + The toLocaleString function is not generic; it generates a runtime error + if its 'this' value is not a Date object. Therefore it cannot be transferred + to other kinds of objects for use as a method. + + Author: pschwartau@netscape.com + Date: 14 november 2000 +*/ + + var SECTION = "15.9.5.5"; + var VERSION = "ECMA_3"; + var TITLE = "Date.prototype.toLocaleString()"; + + var status = ''; + var actual = ''; + var expect = ''; + + + startTest(); + writeHeaderToLog( SECTION + " "+ TITLE); + + +//----------------------------------------------------------------------------------------------------- + var testcases = new Array(); +//----------------------------------------------------------------------------------------------------- + + + // first, some generic tests - + + status = "typeof (now.toLocaleString())"; + actual = typeof (now.toLocaleString()); + expect = "string"; + addTestCase(); + + status = "Date.prototype.toLocaleString.length"; + actual = Date.prototype.toLocaleString.length; + expect = 0; + addTestCase(); + +//----------------------------------------------------------------------------------------------------- + test(); +//----------------------------------------------------------------------------------------------------- + + +function addTestCase() +{ + testcases[tc++] = new TestCase( SECTION, status, expect, actual); +} + + +function test() +{ + for ( tc=0; tc < testcases.length; tc++ ) + { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description + " = " + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return (testcases); +}
\ No newline at end of file diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.6.js b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.6.js new file mode 100644 index 0000000..073d828 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.6.js @@ -0,0 +1,149 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: 15.9.5.6.js + ECMA Section: 15.9.5.6 Date.prototype.toLocaleDateString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "date" + portion of the Date in the current time zone in a convenient, + human-readable form. We can't test the content of the string, + but can verify that the string is parsable by Date.parse + + The toLocaleDateString function is not generic; it generates a runtime error + if its 'this' value is not a Date object. Therefore it cannot be transferred + to other kinds of objects for use as a method. + + Author: pschwartau@netscape.com + Date: 14 november 2000 +*/ + + var SECTION = "15.9.5.6"; + var VERSION = "ECMA_3"; + var TITLE = "Date.prototype.toLocaleDateString()"; + + var status = ''; + var actual = ''; + var expect = ''; + + + startTest(); + writeHeaderToLog( SECTION + " "+ TITLE); + + +//----------------------------------------------------------------------------------------------------- + var testcases = new Array(); +//----------------------------------------------------------------------------------------------------- + + + // first, some generic tests - + + status = "typeof (now.toLocaleDateString())"; + actual = typeof (now.toLocaleDateString()); + expect = "string"; + addTestCase(); + + status = "Date.prototype.toLocaleDateString.length"; + actual = Date.prototype.toLocaleDateString.length; + expect = 0; + addTestCase(); + + /* Date.parse is accurate to the second; valueOf() to the millisecond. + Here we expect them to coincide, as we expect a time of exactly midnight - */ + status = "(Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0"; + actual = (Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0; + expect = true; + addTestCase(); + + + + // 1970 + addDateTestCase(0); + addDateTestCase(TZ_ADJUST); + + + // 1900 + addDateTestCase(TIME_1900); + addDateTestCase(TIME_1900 - TZ_ADJUST); + + + // 2000 + addDateTestCase(TIME_2000); + addDateTestCase(TIME_2000 - TZ_ADJUST); + + + // 29 Feb 2000 + addDateTestCase(UTC_29_FEB_2000); + addDateTestCase(UTC_29_FEB_2000 - 1000); + addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + + + // 2005 + addDateTestCase(UTC_1_JAN_2005); + addDateTestCase(UTC_1_JAN_2005 - 1000); + addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); + + + +//----------------------------------------------------------------------------------------------------- + test(); +//----------------------------------------------------------------------------------------------------- + + +function addTestCase() +{ + testcases[tc++] = new TestCase( SECTION, status, expect, actual); +} + + +function addDateTestCase(date_given_in_milliseconds) +{ + var givenDate = new Date(date_given_in_milliseconds); + + status = 'Date.parse(' + givenDate + ').toLocaleDateString())'; + actual = Date.parse(givenDate.toLocaleDateString()); + expect = Date.parse(midnight(givenDate)); + addTestCase(); +} + + +function midnight(givenDate) +{ + // midnight on the given date - + return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate()); +} + + +function test() +{ + for ( tc=0; tc < testcases.length; tc++ ) + { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description + " = " + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return (testcases); +}
\ No newline at end of file diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.7.js b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.7.js new file mode 100644 index 0000000..14b2574 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Date/15.9.5.7.js @@ -0,0 +1,211 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/** + File Name: 15.9.5.7.js + ECMA Section: 15.9.5.7 Date.prototype.toLocaleTimeString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "time" + portion of the Date in the current time zone in a convenient, + human-readable form. We test the content of the string by checking + that d.toDateString() + d.toLocaleTimeString() == d.toString() + + The only headache is that as of this writing the "GMT ..." portion of + d.toString() is NOT included in d.toLocaleTimeString() as it is in + d.toTimeString(). So we have to take that into account. + + Author: pschwartau@netscape.com + Date: 14 november 2000 + Revised: 07 january 2002 because of a change in JS Date format: + + See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) + See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) +*/ +//----------------------------------------------------------------------------- + var SECTION = "15.9.5.7"; + var VERSION = "ECMA_3"; + var TITLE = "Date.prototype.toLocaleTimeString()"; + + var status = ''; + var actual = ''; + var expect = ''; + var givenDate; + var year = ''; + var regexp = ''; + var TimeString = ''; + var reducedDateString = ''; + var hopeThisIsLocaleTimeString = ''; + var cnERR ='OOPS! FATAL ERROR: no regexp match in extractLocaleTimeString()'; + + + startTest(); + writeHeaderToLog( SECTION + " "+ TITLE); + + +//----------------------------------------------------------------------------------------------------- + var testcases = new Array(); +//----------------------------------------------------------------------------------------------------- + + + // first, a couple generic tests - + + status = "typeof (now.toLocaleTimeString())"; + actual = typeof (now.toLocaleTimeString()); + expect = "string"; + addTestCase(); + + status = "Date.prototype.toLocaleTimeString.length"; + actual = Date.prototype.toLocaleTimeString.length; + expect = 0; + addTestCase(); + + + + + // 1970 + addDateTestCase(0); + addDateTestCase(TZ_ADJUST); + + + // 1900 + addDateTestCase(TIME_1900); + addDateTestCase(TIME_1900 - TZ_ADJUST); + + + // 2000 + addDateTestCase(TIME_2000); + addDateTestCase(TIME_2000 - TZ_ADJUST); + + + // 29 Feb 2000 + addDateTestCase(UTC_29_FEB_2000); + addDateTestCase(UTC_29_FEB_2000 - 1000); + addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + + + // Now + addDateTestCase( TIME_NOW); + addDateTestCase( TIME_NOW - TZ_ADJUST); + + + // 2005 + addDateTestCase(UTC_1_JAN_2005); + addDateTestCase(UTC_1_JAN_2005 - 1000); + addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); + + + +//----------------------------------------------------------------------------------------------------- + test(); +//----------------------------------------------------------------------------------------------------- + + +function addTestCase() +{ + testcases[tc++] = new TestCase( SECTION, status, expect, actual); +} + + +function addDateTestCase(date_given_in_milliseconds) +{ + givenDate = new Date(date_given_in_milliseconds); + + status = '(' + givenDate + ').toLocaleTimeString()'; + actual = givenDate.toLocaleTimeString(); + expect = extractLocaleTimeString(givenDate); + addTestCase(); +} + + +/* + * As of 2002-01-07, the format for JavaScript dates changed. + * See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) + * See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) + * + * WAS: Mon Jan 07 13:40:34 GMT-0800 (Pacific Standard Time) 2002 + * NOW: Mon Jan 07 2002 13:40:34 GMT-0800 (Pacific Standard Time) + * + * So first, use a regexp of the form /date.toDateString()(.*)$/ + * to capture the TimeString into the first backreference. + * + * Then remove the GMT string from TimeString (see introduction above) + */ +function extractLocaleTimeString(date) +{ + regexp = new RegExp(date.toDateString() + '(.*)' + '$'); + try + { + TimeString = date.toString().match(regexp)[1]; + } + catch(e) + { + return cnERR; + } + + /* + * Now remove the GMT part of the TimeString. + * Guard against dates with two "GMT"s, like: + * Jan 01 00:00:00 GMT+0000 (GMT Standard Time) + */ + regexp= /([^G]*)GMT.*/; + try + { + hopeThisIsLocaleTimeString = TimeString.match(regexp)[1]; + } + catch(e) + { + return TimeString; + } + + // trim any leading or trailing spaces - + return trimL(trimR(hopeThisIsLocaleTimeString)); +} + + +function trimL(s) +{ + if (!s) {return cnEmptyString;}; + for (var i = 0; i!=s.length; i++) {if (s[i] != ' ') {break;}} + return s.substring(i); +} + +function trimR(s) +{ + for (var i = (s.length - 1); i!=-1; i--) {if (s[i] != ' ') {break;}} + return s.substring(0, i+1); +} + + +function test() +{ + for ( tc=0; tc < testcases.length; tc++ ) + { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description + " = " + testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + stopTest(); + return (testcases); +} diff --git a/JavaScriptCore/tests/mozilla/ecma_3/Date/shell.js b/JavaScriptCore/tests/mozilla/ecma_3/Date/shell.js new file mode 100644 index 0000000..43721a7 --- /dev/null +++ b/JavaScriptCore/tests/mozilla/ecma_3/Date/shell.js @@ -0,0 +1,676 @@ +/* The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla Communicator client code, released March + * 31, 1998. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * + */ +/* + * JavaScript shared functions file for running the tests in either + * stand-alone JavaScript engine. To run a test, first load this file, + * then load the test script. + */ + +var completed = false; +var testcases; +var tc = 0; + +SECTION = ""; +VERSION = ""; +BUGNUMBER = ""; + +/* + * constant strings + */ +var GLOBAL = "[object global]"; +var PASSED = " PASSED!" +var FAILED = " FAILED! expected: "; +var DEBUG = false; + + +/* +* Wrapper for test case constructor that doesn't require the SECTION argument. + */ +function AddTestCase( description, expect, actual ) +{ + testcases[tc++] = new TestCase( SECTION, description, expect, actual ); +} + + +/* + * TestCase constructor +*/ +function TestCase( n, d, e, a ) +{ + this.name = n; + this.description = d; + this.expect = e; + this.actual = a; + this.passed = true; + this.reason = ""; + this.bugnumber = BUGNUMBER; + this.passed = getTestCaseResult( this.expect, this.actual ); + if ( DEBUG ) {writeLineToLog("added " + this.description);} +} + + +/* + * Set up test environment. +*/ +function startTest() +{ + if ( version ) + { + // JavaScript 1.3 is supposed to be compliant ECMA version 1.0 + if (VERSION == "ECMA_1" ) {version ("130");} + if (VERSION == "JS_1.3" ) {version ( "130");} + if (VERSION == "JS_1.2" ) {version ( "120");} + if (VERSION == "JS_1.1" ) {version( "110");} + + // for ECMA version 2.0, we will leave the JavaScript version + // to the default ( for now ). + } + + // print out bugnumber + if ( BUGNUMBER ) + { + writeLineToLog ("BUGNUMBER: " + BUGNUMBER ); + } + + testcases = new Array(); + tc = 0; +} + + +function test() +{ + for ( tc=0; tc < testcases.length; tc++ ) + { + testcases[tc].passed = writeTestCaseResult( + testcases[tc].expect, + testcases[tc].actual, + testcases[tc].description +" = "+ testcases[tc].actual ); + + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; + } + + stopTest(); + return ( testcases ); +} + + +/* + * Compare expected result to the actual result and figure out whether + * the test case passed. + */ +function getTestCaseResult(expect, actual ) +{ + //because ( NaN == NaN ) always returns false, need to do + //a special compare to see if we got the right result. + if ( actual != actual ) + { + if ( typeof actual == "object" ) {actual = "NaN object";} + else {actual = "NaN number";} + } + + if ( expect != expect ) + { + if ( typeof expect == "object" ) {expect = "NaN object";} + else {expect = "NaN number";} + } + + var passed = ( expect == actual ) ? true : false; + + // if both objects are numbers, need to replace w/ IEEE standard for rounding + if ( !passed && typeof(actual) == "number" && typeof(expect) == "number" ) + { + if ( Math.abs(actual-expect) < 0.0000001 ) {passed = true;} + } + + //verify type is the same + if ( typeof(expect) != typeof(actual) ) {passed = false;} + + return passed; +} + + +/* + * Begin printing functions. These functions use the shell's print function. +* When running tests in the browser, override these functions with functions +* that use document.write. + */ +function writeTestCaseResult( expect, actual, string ) +{ + var passed = getTestCaseResult(expect, actual ); + writeFormattedResult( expect, actual, string, passed ); + return passed; +} + + +function writeFormattedResult( expect, actual, string, passed ) +{ + var s = string ; + s += ( passed ) ? PASSED : FAILED + expect; + writeLineToLog( s); + return passed; +} + + +function writeLineToLog( string ) +{ + print( string ); +} + + +function writeHeaderToLog( string ) +{ + print( string ); +} +/* End of printing functions */ + + +/* + * When running in the shell, run the garbage collector after the test has completed. + */ +function stopTest() +{ + var gc; + if ( gc != undefined ) + { + gc(); + } +} + + +/* + * Convenience function for displaying failed test cases. + * Useful when running tests manually. +*/ +function getFailedCases() +{ + for (var i = 0; i < testcases.length; i++ ) + { + if ( !testcases[i].passed ) + { + print( testcases[i].description + " = " + testcases[i].actual + " expected: " + testcases[i].expect ); + } + } +} + + + /* + * Date constants and functions used by tests in Date suite +*/ +var msPerDay = 86400000; +var HoursPerDay = 24; +var MinutesPerHour = 60; +var SecondsPerMinute = 60; +var msPerSecond = 1000; +var msPerMinute = 60000; // msPerSecond * SecondsPerMinute +var msPerHour = 3600000; // msPerMinute * MinutesPerHour +var TZ_DIFF = getTimeZoneDiff(); +var TZ_ADJUST = TZ_DIFF * msPerHour; +var TIME_1970 = 0; +var TIME_2000 = 946684800000; +var TIME_1900 = -2208988800000; +var UTC_29_FEB_2000 = TIME_2000 + 31*msPerDay + 28*msPerDay; +var UTC_1_JAN_2005 = TIME_2000 + TimeInYear(2000) + TimeInYear(2001) + + TimeInYear(2002) + TimeInYear(2003) + TimeInYear(2004); +var now = new Date(); +var TIME_NOW = now.valueOf(); //valueOf() is to accurate to the millisecond + //Date.parse() is accurate only to the second + + + +/* + * Originally, the test suite used a hard-coded value TZ_DIFF = -8. + * But that was only valid for testers in the Pacific Standard Time Zone! + * We calculate the proper number dynamically for any tester. We just + * have to be careful to use a date not subject to Daylight Savings Time... +*/ +function getTimeZoneDiff() +{ + return -((new Date(2000, 1, 1)).getTimezoneOffset())/60; +} + + +function Day( t) +{ + return ( Math.floor( t/msPerDay ) ); +} + + +function DaysInYear( y ) +{ + if ( y % 4 != 0 ) {return 365;} + + if ( (y%4 == 0) && (y%100 != 0) ) {return 366;} + + if ( (y%100 == 0) && (y%400 != 0) ) {return 365;} + + if ( (y%400 == 0)){return 366;} + else {return "ERROR: DaysInYear(" + y + ") case not covered";} +} + + +function TimeInYear( y ) +{ + return ( DaysInYear(y) * msPerDay ); +} + + +function DayNumber( t ) +{ + return ( Math.floor( t / msPerDay ) ); +} + + +function TimeWithinDay( t ) +{ + if ( t < 0 ) {return ( (t%msPerDay) + msPerDay );} + else {return ( t % msPerDay );} +} + + +function YearNumber( t ) +{ +} + + +function TimeFromYear( y ) +{ + return ( msPerDay * DayFromYear(y) ); +} + + +function DayFromYear( y ) +{ + return ( 365*(y-1970) + Math.floor((y-1969)/4) - Math.floor((y-1901)/100) + + Math.floor((y-1601)/400) ); +} + + +function InLeapYear( t ) +{ + if ( DaysInYear(YearFromTime(t)) == 365 ) {return 0;} + + if ( DaysInYear(YearFromTime(t)) == 366 ) {return 1;} + else {return "ERROR: InLeapYear(" + t + ") case not covered";} +} + + +function YearFromTime( t ) +{ + t =Number( t ); + var sign = ( t < 0 ) ? -1 : 1; + var year = ( sign < 0 ) ? 1969 : 1970; + + for (var timeToTimeZero = t; ; ) + { + // subtract the current year's time from the time that's left. + timeToTimeZero -= sign * TimeInYear(year) + + // if there's less than the current year's worth of time left, then break. + if ( sign < 0 ) + { + if ( sign * timeToTimeZero <= 0 ) {break;} + else {year += sign;} + } + else + { + if ( sign * timeToTimeZero < 0 ) {break;} + else {year += sign;} + } + } + + return ( year ); +} + + +function MonthFromTime( t ) +{ + var day = DayWithinYear( t ); + var leap = InLeapYear(t); + + // I know I could use switch but I'd rather not until it's part of ECMA + if ( (0 <= day) && (day < 31) ) {return 0;} + if ( (31 <= day) && (day < (59+leap) )) {return 1;} + if ( ((59+leap) <= day) && (day < (90+leap) )) {return 2;} + if ( ((90+leap) <= day) && (day < (120+leap) )) {return 3;} + if ( ((120+leap) <= day) && (day < (151+leap) )) {return 4;} + if ( ((151+leap) <= day) && (day < (181+leap) )) {return 5;} + if ( ((181+leap) <= day) && (day < (212+leap) )) {return 6;} + if ( ((212+leap) <= day) && (day < (243+leap)) ) {return 7;} + if ( ((243+leap) <= day) && (day < (273+leap) )) {return 8;} + if ( ((273+leap) <= day) && (day < (304+leap)) ) {return 9;} + if ( ((304+leap) <= day) && (day < (334+leap)) ) {return 10;} + if ( ((334+leap) <= day) && (day < (365+leap)) ) {return 11;} + else {return "ERROR: MonthFromTime(" + t + ") not known";} +} + + +function DayWithinYear( t ) +{ + return(Day(t) - DayFromYear(YearFromTime(t)) ); +} + + +function DateFromTime( t ) +{ + var day = DayWithinYear(t); + var month = MonthFromTime(t); + + if ( month == 0) {return ( day + 1 );} + if ( month == 1) {return ( day - 30 );} + if ( month == 2) {return ( day - 58 - InLeapYear(t) );} + if ( month == 3) {return ( day - 89 - InLeapYear(t));} + if ( month == 4) {return ( day - 119 - InLeapYear(t));} + if ( month == 5) {return ( day - 150 - InLeapYear(t));} + if ( month == 6) {return ( day - 180 - InLeapYear(t));} + if ( month == 7) {return ( day - 211 - InLeapYear(t));} + if ( month == 8) {return ( day - 242 - InLeapYear(t));} + if ( month == 9) {return ( day - 272 - InLeapYear(t));} + if ( month == 10) {return ( day - 303 - InLeapYear(t));} + if ( month == 11) {return ( day - 333 - InLeapYear(t));} + return ("ERROR: DateFromTime("+t+") not known" ); +} + + +function WeekDay( t ) +{ + var weekday = (Day(t)+4)%7; + return( weekday < 0 ? 7+weekday : weekday ); +} + + +// missing daylight savings time adjustment + + +function HourFromTime( t ) +{ + var h = Math.floor( t / msPerHour )%HoursPerDay; + return ( (h<0) ? HoursPerDay + h : h ); +} + + +function MinFromTime( t ) +{ + var min = Math.floor( t / msPerMinute )%MinutesPerHour; + return( (min < 0 ) ? MinutesPerHour + min : min ); +} + + +function SecFromTime( t ) +{ + var sec = Math.floor( t / msPerSecond )%SecondsPerMinute; + return ( (sec < 0 ) ? SecondsPerMinute + sec : sec ); +} + + +function msFromTime( t ) +{ + var ms = t%msPerSecond; + return ( (ms < 0 ) ? msPerSecond + ms : ms ); +} + + +function LocalTZA() +{ + return ( TZ_DIFF * msPerHour ); +} + + +function UTC( t ) +{ + return ( t - LocalTZA() - DaylightSavingTA(t - LocalTZA()) ); +} + + +function DaylightSavingTA( t ) +{ + t = t - LocalTZA(); + + var dst_start = GetSecondSundayInMarch(t) + 2*msPerHour; + var dst_end = GetFirstSundayInNovember(t) + 2*msPerHour; + + if ( t >= dst_start && t < dst_end ) {return msPerHour;} + else {return 0;} + + // Daylight Savings Time starts on the first Sunday in April at 2:00AM in PST. + // Other time zones will need to override this function. + +print( new Date( UTC(dst_start + LocalTZA())) ); +return UTC(dst_start + LocalTZA()); +} + +function GetFirstSundayInApril( t ) { + var year = YearFromTime(t); + var leap = InLeapYear(t); + + var april = TimeFromYear(year) + TimeInMonth(0, leap) + TimeInMonth(1,leap) + + TimeInMonth(2,leap); + + for ( var first_sunday = april; WeekDay(first_sunday) > 0; + first_sunday += msPerDay ) + { + ; + } + + return first_sunday; +} +function GetLastSundayInOctober( t ) { + var year = YearFromTime(t); + var leap = InLeapYear(t); + + for ( var oct = TimeFromYear(year), m = 0; m < 9; m++ ) { + oct += TimeInMonth(m, leap); + } + for ( var last_sunday = oct + 30*msPerDay; WeekDay(last_sunday) > 0; + last_sunday -= msPerDay ) + { + ; + } + return last_sunday; +} + +// Added these two functions because DST rules changed for the US. +function GetSecondSundayInMarch( t ) { + var year = YearFromTime(t); + var leap = InLeapYear(t); + + var march = TimeFromYear(year) + TimeInMonth(0, leap) + TimeInMonth(1,leap); + + var sundayCount = 0; + var flag = true; + for ( var second_sunday = march; flag; second_sunday += msPerDay ) + { + if (WeekDay(second_sunday) == 0) { + if(++sundayCount == 2) + flag = false; + } + } + + return second_sunday; +} +function GetFirstSundayInNovember( t ) { + var year = YearFromTime(t); + var leap = InLeapYear(t); + + for ( var nov = TimeFromYear(year), m = 0; m < 10; m++ ) { + nov += TimeInMonth(m, leap); + } + for ( var first_sunday = nov; WeekDay(first_sunday) > 0; + first_sunday += msPerDay ) + { + ; + } + return first_sunday; +} + + +function LocalTime( t ) +{ + return ( t + LocalTZA() + DaylightSavingTA(t) ); +} + + +function MakeTime( hour, min, sec, ms ) +{ + if ( isNaN(hour) || isNaN(min) || isNaN(sec) || isNaN(ms) ){return Number.NaN;} + + hour = ToInteger(hour); + min = ToInteger( min); + sec = ToInteger( sec); + ms = ToInteger( ms ); + + return( (hour*msPerHour) + (min*msPerMinute) + (sec*msPerSecond) + ms ); +} + + +function MakeDay( year, month, date ) +{ + if ( isNaN(year) || isNaN(month) || isNaN(date)) {return Number.NaN;} + + year = ToInteger(year); + month = ToInteger(month); + date = ToInteger(date ); + + var sign = ( year < 1970 ) ? -1 : 1; + var t = ( year < 1970 ) ? 1 : 0; + var y = ( year < 1970 ) ? 1969 : 1970; + + var result5 = year + Math.floor( month/12 ); + var result6= month%12; + + if ( year < 1970 ) + { + for ( y = 1969; y >= year; y += sign ) + { + t += sign * TimeInYear(y); + } + } + else + { + for ( y = 1970 ; y < year; y += sign ) + { + t += sign * TimeInYear(y); + } + } + + var leap = InLeapYear( t ); + + for ( var m = 0; m < month; m++) + { + t += TimeInMonth( m, leap ); + } + + if ( YearFromTime(t) != result5 ) {return Number.NaN;} + if ( MonthFromTime(t) != result6 ) {return Number.NaN;} + if ( DateFromTime(t) != 1 ){return Number.NaN;} + + return ( (Day(t)) + date - 1 ); +} + + +function TimeInMonth( month, leap ) +{ + // Jan 0 Feb 1 Mar 2 Apr 3 May 4 June 5 Jul 6 Aug 7 Sep 8 Oct 9 Nov 10 Dec11 + + // April June September November + if ( month == 3 || month == 5 || month == 8 || month == 10 ) {return ( 30*msPerDay );} + + // all the rest + if ( month == 0 || month == 2 || month == 4 || month == 6 || + month == 7 || month == 9 || month == 11 ) {return ( 31*msPerDay );} + + // save February + return ( (leap == 0) ? 28*msPerDay : 29*msPerDay ); +} + + +function MakeDate( day, time ) +{ + if (day == Number.POSITIVE_INFINITY || + day == Number.NEGATIVE_INFINITY || + day == Number.NaN ) + { + return Number.NaN; + } + + if ( time == Number.POSITIVE_INFINITY || + time == Number.POSITIVE_INFINITY || + day == Number.NaN) + { + return Number.NaN; + } + + return ( day * msPerDay ) + time; +} + + +function TimeClip( t ) +{ + if ( isNaN( t )) {return ( Number.NaN);} + if ( Math.abs( t ) > 8.64e15 ) {return ( Number.NaN);} + + return ( ToInteger( t ) ); +} + + +function ToInteger( t ) +{ + t = Number( t ); + + if ( isNaN( t )) {return ( Number.NaN);} + + if ( t == 0 || t == -0 || + t == Number.POSITIVE_INFINITY || + t == Number.NEGATIVE_INFINITY) + { + return 0; + } + + var sign = ( t < 0 ) ? -1 : 1; + + return ( sign * Math.floor( Math.abs( t ) ) ); +} + + +function Enumerate( o ) +{ + var p; + for ( p in o ) {print( p + ": " + o[p] );} +} + + +/* these functions are useful for running tests manually in Rhino */ + +function GetContext() +{ + return Packages.com.netscape.javascript.Context.getCurrentContext(); +} + + +function OptLevel( i ) +{ + i = Number(i); + var cx = GetContext(); + cx.setOptimizationLevel(i); +} + +/* end of Rhino functions */ + |