diff options
Diffstat (limited to 'js/src/tests/test262/intl402/ch12/12.3')
14 files changed, 279 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.1.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.1.js new file mode 100644 index 000000000..1755dd64b --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.1.js @@ -0,0 +1,14 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.DateTimeFormat.prototype.constructor is the + * Intl.DateTimeFormat. + * @author: Roozbeh Pournader + */ + +if (Intl.DateTimeFormat.prototype.constructor !== Intl.DateTimeFormat) { + $ERROR("Intl.DateTimeFormat.prototype.constructor is not the same as " + + "Intl.DateTimeFormat"); +} + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.2_1_a_L15.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_1_a_L15.js new file mode 100644 index 000000000..2fb768d09 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_1_a_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the function returned by Intl.DateTimeFormat.prototype.format + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(new Intl.DateTimeFormat().format, true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.2_1_c.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_1_c.js new file mode 100644 index 000000000..d4b9f891f --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_1_c.js @@ -0,0 +1,34 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that format function is bound to its Intl.DateTimeFormat. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var dates = [new Date(), new Date(0), new Date(Date.parse("1989-11-09T17:57:00Z"))]; +var locales = [undefined, ["de"], ["th-u-ca-gregory-nu-thai"], ["en"], ["ja-u-ca-japanese"], ["ar-u-ca-islamicc-nu-arab"]]; +var options = [ + undefined, + {hour12: false}, + {month: "long", day: "numeric", hour: "2-digit", minute: "2-digit"} +]; + +locales.forEach(function (locales) { + options.forEach(function (options) { + var formatObj = new Intl.DateTimeFormat(locales, options); + var formatFunc = formatObj.format; + dates.forEach(function (date) { + var referenceFormatted = formatObj.format(date); + var formatted = formatFunc(date); + if (referenceFormatted !== formatted) { + $ERROR("format function produces different result than format method for locales " + + locales + "; options: " + (options ? JSON.stringify(options) : options) + + " : " + formatted + " vs. " + referenceFormatted + "."); + } + }); + }); +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.2_FDT_1.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_FDT_1.js new file mode 100644 index 000000000..d643d7928 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_FDT_1.js @@ -0,0 +1,26 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that format handles non-finite values correctly. + * @author Norbert Lindenberg + */ + +var invalidValues = [NaN, Infinity, -Infinity]; + +var format = new Intl.DateTimeFormat(); + +invalidValues.forEach(function (value) { + var error; + try { + var result = format.format(value); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Invalid value " + value + " was not rejected."); + } else if (error.name !== "RangeError") { + $ERROR("Invalid value " + value + " was rejected with wrong error " + error.name + "."); + } +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js new file mode 100644 index 000000000..f13878403 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_FDT_7_a_iv.js @@ -0,0 +1,32 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that format uses a proleptic Gregorian calendar with no year 0. + * @author Norbert Lindenberg + */ + +var dates = [ + 0, // January 1, 1970 + -62151602400000, // in June 1 BC + -8640000000000000 // beginning of ECMAScript time +]; + +var format = new Intl.DateTimeFormat(["en-US"], {year: "numeric", month: "long", timeZone: "UTC"}); + +// this test requires a Gregorian calendar, which we usually find in the US +if (format.resolvedOptions().calendar !== "gregory") { + $ERROR("Internal error: Didn't find Gregorian calendar"); +} + +dates.forEach(function (date) { + var year = new Date(date).getUTCFullYear(); + var expectedYear = year <= 0 ? 1 - year : year; + var expectedYearString = expectedYear.toLocaleString(["en-US"], {useGrouping: false}); + var dateString = format.format(date); + if (dateString.indexOf(expectedYearString) === -1) { + $ERROR("Formatted year doesn't contain expected year – expected " + + expectedYearString + ", got " + dateString + "."); + } +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.2_L15.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_L15.js new file mode 100644 index 000000000..73d309e26 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the getter for Intl.DateTimeFormat.prototype.format + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format").get , true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.2_TLT_2.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_TLT_2.js new file mode 100644 index 000000000..bf0a8ed36 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_TLT_2.js @@ -0,0 +1,16 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the behavior of a Record is not affected by adversarial + * changes to Object.prototype. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +taintProperties(["weekday", "era", "year", "month", "day", "hour", "minute", "second", "inDST"]); + +var format = new Intl.DateTimeFormat(); +var time = format.format(); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.3.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.3.js new file mode 100644 index 000000000..b5735c350 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.3.js @@ -0,0 +1,52 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that the object returned by Intl.DateTimeFormat.prototype.resolvedOptions + * has the right properties. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var actual = new Intl.DateTimeFormat().resolvedOptions(); + +var actual2 = new Intl.DateTimeFormat().resolvedOptions(); +if (actual2 === actual) { + $ERROR("resolvedOptions returned the same object twice."); +} + +// source: CLDR file common/bcp47/calendar.xml; version CLDR 21. +var calendars = [ + "buddhist", + "chinese", + "coptic", + "ethioaa", + "ethiopic", + "gregory", + "hebrew", + "indian", + "islamic", + "islamicc", + "iso8601", + "japanese", + "persian", + "roc" +]; + +// this assumes the default values where the specification provides them +mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag); +mustHaveProperty(actual, "calendar", calendars); +mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem); +mustHaveProperty(actual, "timeZone", [undefined]); +mustNotHaveProperty(actual, "weekday"); +mustNotHaveProperty(actual, "era"); +mustHaveProperty(actual, "year", ["2-digit", "numeric"]); +mustHaveProperty(actual, "month", ["2-digit", "numeric", "narrow", "short", "long"]); +mustHaveProperty(actual, "day", ["2-digit", "numeric"]); +mustNotHaveProperty(actual, "hour"); +mustNotHaveProperty(actual, "minute"); +mustNotHaveProperty(actual, "second"); +mustNotHaveProperty(actual, "timeZoneName"); +mustNotHaveProperty(actual, "hour12"); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3.3_L15.js b/js/src/tests/test262/intl402/ch12/12.3/12.3.3_L15.js new file mode 100644 index 000000000..1b4079ebe --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.3_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.DateTimeFormat.prototype.resolvedOptions + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Intl.DateTimeFormat.prototype.resolvedOptions, true, false, [], 0); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3_L15.js b/js/src/tests/test262/intl402/ch12/12.3/12.3_L15.js new file mode 100644 index 000000000..55f1c16ca --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3_L15.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.DateTimeFormat.prototype + * meets the requirements for built-in objects defined by the introduction of + * chapter 15 of the ECMAScript Language Specification. + * @author Norbert Lindenberg + */ + +$INCLUDE("testBuiltInObject.js"); + +testBuiltInObject(Intl.DateTimeFormat.prototype, false, false, ["constructor", "format", "resolvedOptions"]); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3_a.js b/js/src/tests/test262/intl402/ch12/12.3/12.3_a.js new file mode 100644 index 000000000..e1d795b91 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3_a.js @@ -0,0 +1,16 @@ +// Copyright 2012 Google Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.DateTimeFormat.prototype is an object that + * has been initialized as an Intl.DateTimeFormat. + * @author: Roozbeh Pournader + */ + +// test by calling a function that would fail if "this" were not an object +// initialized as an Intl.DateTimeFormat +if (typeof Intl.DateTimeFormat.prototype.format(0) !== "string") { + $ERROR("Intl.DateTimeFormat's prototype is not an object that has been " + + "initialized as an Intl.DateTimeFormat"); +} + diff --git a/js/src/tests/test262/intl402/ch12/12.3/12.3_b.js b/js/src/tests/test262/intl402/ch12/12.3/12.3_b.js new file mode 100644 index 000000000..d905bf571 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3_b.js @@ -0,0 +1,33 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Intl.DateTimeFormat.prototype functions throw a + * TypeError if called on a non-object value or an object that hasn't been + * initialized as a DateTimeFormat. + * @author Norbert Lindenberg + */ + +var functions = { + "format getter": Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format").get, + resolvedOptions: Intl.DateTimeFormat.prototype.resolvedOptions +}; +var invalidTargets = [undefined, null, true, 0, "DateTimeFormat", [], {}]; + +Object.getOwnPropertyNames(functions).forEach(function (functionName) { + var f = functions[functionName]; + invalidTargets.forEach(function (target) { + var error; + try { + f.call(target); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Calling " + functionName + " on " + target + " was not rejected."); + } else if (error.name !== "TypeError") { + $ERROR("Calling " + functionName + " on " + target + " was rejected with wrong error " + error.name + "."); + } + }); +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.3/browser.js b/js/src/tests/test262/intl402/ch12/12.3/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/browser.js diff --git a/js/src/tests/test262/intl402/ch12/12.3/shell.js b/js/src/tests/test262/intl402/ch12/12.3/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.3/shell.js |