diff options
Diffstat (limited to 'js/src/tests/test262/intl402/ch12')
42 files changed, 811 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_1.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_1.js new file mode 100644 index 000000000..8136fb421 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_1.js @@ -0,0 +1,43 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that an object can't be re-initialized as a DateTimeFormat. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testWithIntlConstructors(function (Constructor) { + var obj, error; + + // variant 1: use constructor in a "new" expression + obj = new Constructor(); + try { + Intl.DateTimeFormat.call(obj); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Re-initializing object created with \"new\" as DateTimeFormat was not rejected."); + } else if (error.name !== "TypeError") { + $ERROR("Re-initializing object created with \"new\" as DateTimeFormat was rejected with wrong error " + error.name + "."); + } + + // variant 2: use constructor as a function + obj = Constructor.call({}); + error = undefined; + try { + Intl.DateTimeFormat.call(obj); + } catch (e) { + error = e; + } + if (error === undefined) { + $ERROR("Re-initializing object created with constructor as function as DateTimeFormat was not rejected."); + } else if (error.name !== "TypeError") { + $ERROR("Re-initializing object created with constructor as function as DateTimeFormat was rejected with wrong error " + error.name + "."); + } + + return true; +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_18.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_18.js new file mode 100644 index 000000000..f75ea1e32 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_18.js @@ -0,0 +1,15 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the option hour12 is processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testOption(Intl.DateTimeFormat, "hour12", "boolean", undefined, undefined, + {extra: {any: {hour: "numeric", minute: "numeric"}}}); +testOption(Intl.DateTimeFormat, "hour12", "boolean", undefined, undefined, + {noReturn: true}); + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_22.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_22.js new file mode 100644 index 000000000..5c317c6b9 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_22.js @@ -0,0 +1,18 @@ +// 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", "timeZone"]); + +var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; +if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { + $ERROR("DateTimeFormat returns invalid locale " + locale + "."); +} + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_23.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_23.js new file mode 100644 index 000000000..d26e1d28c --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_23.js @@ -0,0 +1,14 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the options for the date and time components are processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +getDateTimeComponents().forEach(function (component) { + testOption(Intl.DateTimeFormat, component, "string", getDateTimeComponentValues(component), undefined, {isILD: true}); +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_25.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_25.js new file mode 100644 index 000000000..ccaf7be03 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_25.js @@ -0,0 +1,12 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the option formatMatcher is processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testOption(Intl.DateTimeFormat, "formatMatcher", "string", ["basic", "best fit"], "best fit", {noReturn: true}); + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_5.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_5.js new file mode 100644 index 000000000..c6b166814 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_5.js @@ -0,0 +1,18 @@ +// 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(["localeMatcher"]); + +var locale = new Intl.DateTimeFormat(undefined, {localeMatcher: "lookup"}).resolvedOptions().locale; +if (!isCanonicalizedStructurallyValidLanguageTag(locale)) { + $ERROR("DateTimeFormat returns invalid locale " + locale + "."); +} + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_6.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_6.js new file mode 100644 index 000000000..148ca02f6 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_6.js @@ -0,0 +1,12 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the option localeMatcher is processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testOption(Intl.DateTimeFormat, "localeMatcher", "string", ["lookup", "best fit"], "best fit", {noReturn: true}); + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_TDTO.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_TDTO.js new file mode 100644 index 000000000..5df6a1cf2 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_TDTO.js @@ -0,0 +1,107 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that the set of options for the date and time components is processed correctly. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var locales = [[], ["zh-Hans-CN"], ["hi-IN"], ["en-US"], ["id-ID"]]; +var dates = [new Date(), new Date(0), new Date(Date.parse("1989-11-09T17:57:00Z"))]; + +function testWithDateTimeFormat(options, expected) { + locales.forEach(function (locales) { + var format = new Intl.DateTimeFormat(locales, options); + var resolvedOptions = format.resolvedOptions(); + getDateTimeComponents().forEach(function (component) { + if (resolvedOptions.hasOwnProperty(component)) { + if (!expected.hasOwnProperty(component)) { + $ERROR("Unrequested component " + component + + " added to expected subset " + JSON.stringify(expected) + + "; locales " + locales + ", options " + + (options ? JSON.stringify(options) : options) + "."); + } + } else { + if (expected.hasOwnProperty(component)) { + $ERROR("Missing component " + component + + " from expected subset " + JSON.stringify(expected) + + "; locales " + locales + ", options " + + (options ? JSON.stringify(options) : options) + "."); + } + } + }); + }); +} + +function testWithToLocale(f, options, expected) { + // expected can be either one subset or an array of possible subsets + if (expected.length === undefined) { + expected = [expected]; + } + locales.forEach(function (locales) { + dates.forEach(function (date) { + var formatted = Date.prototype[f].call(date, locales, options); + var expectedStrings = []; + expected.forEach(function (expected) { + var referenceFormat = new Intl.DateTimeFormat(locales, expected); + expectedStrings.push(referenceFormat.format(date)); + }); + if (expectedStrings.indexOf(formatted) === -1) { + $ERROR("Function " + f + " did not return expected string for locales " + + locales + ", options " + (options? JSON.stringify(options) : options) + + "; expected " + + (expectedStrings.length === 1 ? expectedStrings[0] : "one of " + expectedStrings) + + ", got " + formatted + "."); + } + }); + }); +} + +// any/date: steps 5a, 6a, 7a +testWithDateTimeFormat(undefined, {year: "numeric", month: "numeric", day: "numeric"}); + +// any/date: steps 5a, 6a +testWithDateTimeFormat({year: "numeric", month: "numeric"}, {year: "numeric", month: "numeric"}); + +// any/date: steps 5a, 6a +testWithDateTimeFormat({hour: "numeric", minute: "numeric"}, {hour: "numeric", minute: "numeric"}); + +// any/all: steps 5a, 6a, 7a, 8a +testWithToLocale("toLocaleString", undefined, [ + // the first one is not guaranteed to be supported; the second one is + {year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}, + {weekday: "short", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"} +]); + +// any/all: steps 5a, 6a +testWithToLocale("toLocaleString", {year: "numeric", month: "numeric"}, {year: "numeric", month: "numeric"}); + +// any/all: steps 5a, 6a +testWithToLocale("toLocaleString", {hour: "numeric", minute: "numeric"}, {hour: "numeric", minute: "numeric"}); + +// date/date: steps 5a, 7a +testWithToLocale("toLocaleDateString", undefined, {year: "numeric", month: "numeric", day: "numeric"}); + +// date/date: steps 5a +testWithToLocale("toLocaleDateString", {year: "numeric", month: "numeric"}, {year: "numeric", month: "numeric"}); + +// date/date: steps 5a, 7a +testWithToLocale("toLocaleDateString", {hour: "numeric", minute: "numeric", second: "numeric"}, [ + // the first one is not guaranteed to be supported; the second one is + {year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}, + {weekday: "short", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"} +]); + +// time/time: steps 6a, 8a +testWithToLocale("toLocaleTimeString", undefined, {hour: "numeric", minute: "numeric", second: "numeric"}); + +// time/time: steps 6a, 8a +testWithToLocale("toLocaleTimeString", {weekday: "short", year: "numeric", month: "numeric", day: "numeric"}, + {weekday: "short", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}); + +// time/time: steps 6a +testWithToLocale("toLocaleTimeString", {hour: "numeric", minute: "numeric"}, {hour: "numeric", minute: "numeric"}); + + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.1_a.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_a.js new file mode 100644 index 000000000..4f5f3dbf5 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.1_a.js @@ -0,0 +1,18 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that constructing a DateTimeFormat doesn't create or modify + * unwanted properties on the RegExp constructor. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +testForUnwantedRegExpChanges(function () { + new Intl.DateTimeFormat("de-DE-u-ca-gregory"); +}); + +testForUnwantedRegExpChanges(function () { + new Intl.DateTimeFormat("de-DE-u-ca-gregory", {timeZone: "UTC"}); +}); diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.2.1_4.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.2.1_4.js new file mode 100644 index 000000000..cb22be8f9 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.2.1_4.js @@ -0,0 +1,21 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that for non-object values passed as this to DateTimeFormat a + * wrapper object will be initialized and returned. + * @author Norbert Lindenberg + */ + +var thisValues = [true, 42, "国際化"]; + +thisValues.forEach(function (value) { + var format = Intl.DateTimeFormat.call(value); + // check that the returned object functions as a date-time format + var referenceFormat = new Intl.DateTimeFormat(); + if (Intl.DateTimeFormat.prototype.format.call(format, new Date(111111111)) !== referenceFormat.format(new Date(111111111))) { + $ERROR("DateTimeFormat initialized from " + value + " doesn't behave like normal date-time format."); + } + return true; +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.2.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.2.js new file mode 100644 index 000000000..3ffed2ec8 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.2.js @@ -0,0 +1,30 @@ +// Copyright 2011-2012 Norbert Lindenberg. All rights reserved. +// 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 can be subclassed. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +// get a date-time format and have it format an array of dates for comparison with the subclass +var locales = ["tlh", "id", "en"]; +var a = [new Date(0), Date.now(), new Date(Date.parse("1989-11-09T17:57:00Z"))]; +var referenceDateTimeFormat = new Intl.DateTimeFormat(locales); +var referenceFormatted = a.map(referenceDateTimeFormat.format); + +function MyDateTimeFormat(locales, options) { + Intl.DateTimeFormat.call(this, locales, options); + // could initialize MyDateTimeFormat properties +} + +MyDateTimeFormat.prototype = Object.create(Intl.DateTimeFormat.prototype); +MyDateTimeFormat.prototype.constructor = MyDateTimeFormat; +// could add methods to MyDateTimeFormat.prototype + +var format = new MyDateTimeFormat(locales); +var actual = a.map(format.format); +testArraysAreSame(referenceFormatted, actual); + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1.3.js b/js/src/tests/test262/intl402/ch12/12.1/12.1.3.js new file mode 100644 index 000000000..5e70bbb8f --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1.3.js @@ -0,0 +1,19 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that objects constructed by Intl.DateTimeFormat have the specified internal properties. + * @author Norbert Lindenberg + */ + +var obj = new Intl.DateTimeFormat(); + +var actualPrototype = Object.getPrototypeOf(obj); +if (actualPrototype !== Intl.DateTimeFormat.prototype) { + $ERROR("Prototype of object constructed by Intl.DateTimeFormat isn't Intl.DateTimeFormat.prototype; got " + actualPrototype); +} + +if (!Object.isExtensible(obj)) { + $ERROR("Object constructed by Intl.DateTimeFormat must be extensible."); +} + diff --git a/js/src/tests/test262/intl402/ch12/12.1/12.1_L15.js b/js/src/tests/test262/intl402/ch12/12.1/12.1_L15.js new file mode 100644 index 000000000..46c4f5f50 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/12.1_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 + * 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, true, true, ["supportedLocalesOf"], 0); + diff --git a/js/src/tests/test262/intl402/ch12/12.1/browser.js b/js/src/tests/test262/intl402/ch12/12.1/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/browser.js diff --git a/js/src/tests/test262/intl402/ch12/12.1/shell.js b/js/src/tests/test262/intl402/ch12/12.1/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.1/shell.js diff --git a/js/src/tests/test262/intl402/ch12/12.2/12.2.1.js b/js/src/tests/test262/intl402/ch12/12.2/12.2.1.js new file mode 100644 index 000000000..3590c0a9d --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.2/12.2.1.js @@ -0,0 +1,22 @@ +// 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 has the required attributes. + * @author Norbert Lindenberg + */ + +var desc = Object.getOwnPropertyDescriptor(Intl.DateTimeFormat, "prototype"); +if (desc === undefined) { + $ERROR("Intl.DateTimeFormat.prototype is not defined."); +} +if (desc.writable) { + $ERROR("Intl.DateTimeFormat.prototype must not be writable."); +} +if (desc.enumerable) { + $ERROR("Intl.DateTimeFormat.prototype must not be enumerable."); +} +if (desc.configurable) { + $ERROR("Intl.DateTimeFormat.prototype must not be configurable."); +} + diff --git a/js/src/tests/test262/intl402/ch12/12.2/12.2.2_L15.js b/js/src/tests/test262/intl402/ch12/12.2/12.2.2_L15.js new file mode 100644 index 000000000..8b21df1fd --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.2/12.2.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 Intl.DateTimeFormat.supportedLocalesOf + * 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.supportedLocalesOf, true, false, [], 1); + diff --git a/js/src/tests/test262/intl402/ch12/12.2/12.2.2_a.js b/js/src/tests/test262/intl402/ch12/12.2/12.2.2_a.js new file mode 100644 index 000000000..42eedc0a1 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.2/12.2.2_a.js @@ -0,0 +1,28 @@ +// 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 has a supportedLocalesOf + * property, and it works as planned. + * @author: Roozbeh Pournader + */ + +var defaultLocale = new Intl.DateTimeFormat().resolvedOptions().locale; +var notSupported = 'zxx'; // "no linguistic content" +var requestedLocales = [defaultLocale, notSupported]; + +var supportedLocales; + +if (!Intl.DateTimeFormat.hasOwnProperty('supportedLocalesOf')) { + $ERROR("Intl.DateTimeFormat doesn't have a supportedLocalesOf property."); +} + +supportedLocales = Intl.DateTimeFormat.supportedLocalesOf(requestedLocales); +if (supportedLocales.length !== 1) { + $ERROR('The length of supported locales list is not 1.'); +} + +if (supportedLocales[0] !== defaultLocale) { + $ERROR('The default locale is not returned in the supported list.'); +} + diff --git a/js/src/tests/test262/intl402/ch12/12.2/12.2.2_b.js b/js/src/tests/test262/intl402/ch12/12.2/12.2.2_b.js new file mode 100644 index 000000000..06bc8027e --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.2/12.2.2_b.js @@ -0,0 +1,13 @@ +// Copyright 2013 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.DateTimeFormat.supportedLocalesOf + * doesn't access arguments that it's not given. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +taintDataProperty(Object.prototype, "1"); +new Intl.DateTimeFormat("und"); diff --git a/js/src/tests/test262/intl402/ch12/12.2/12.2.3_b.js b/js/src/tests/test262/intl402/ch12/12.2/12.2.3_b.js new file mode 100644 index 000000000..65fd9dc5f --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.2/12.2.3_b.js @@ -0,0 +1,47 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/** + * @description Tests that Intl.DateTimeFormat does not accept Unicode locale + * extension keys and values that are not allowed. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"]; +var input = new Date(Date.parse("1989-11-09T17:57:00Z")); + +locales.forEach(function (locale) { + var defaultDateTimeFormat = new Intl.DateTimeFormat([locale]); + var defaultOptions = defaultDateTimeFormat.resolvedOptions(); + var defaultOptionsJSON = JSON.stringify(defaultOptions); + var defaultLocale = defaultOptions.locale; + var defaultFormatted = defaultDateTimeFormat.format(input); + + var keyValues = { + "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"], // DateTimeFormat internally uses NumberFormat + "nu": ["native", "traditio", "finance", "invalid"], + "tz": ["usnavajo", "utcw01", "aumel", "uslax", "usnyc", "deber", "invalid"] + }; + + Object.getOwnPropertyNames(keyValues).forEach(function (key) { + keyValues[key].forEach(function (value) { + var dateTimeFormat = new Intl.DateTimeFormat([locale + "-u-" + key + "-" + value]); + var options = dateTimeFormat.resolvedOptions(); + if (options.locale !== defaultLocale) { + $ERROR("Locale " + options.locale + " is affected by key " + + key + "; value " + value + "."); + } + if (JSON.stringify(options) !== defaultOptionsJSON) { + $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " + + key + "; value " + value + "."); + } + if (defaultFormatted !== dateTimeFormat.format(input)) { + $ERROR("Formatted value " + dateTimeFormat.format(input) + " is affected by key " + + key + "; value " + value + "."); + } + }); + }); +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.2/12.2.3_c.js b/js/src/tests/test262/intl402/ch12/12.2/12.2.3_c.js new file mode 100644 index 000000000..0aced6ca9 --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.2/12.2.3_c.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 Intl.DateTimeFormat provides the required date-time + * format component subsets. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var locales = ["de-DE", "en-US", "hi-IN", "id-ID", "ja-JP", "th-TH", "zh-Hans-CN", "zh-Hant-TW", "zxx"]; +var subsets = [ + {weekday: "long", year: "numeric", month: "numeric", day: "numeric", + hour: "numeric", minute: "numeric", second: "numeric"}, + {weekday: "long", year: "numeric", month: "numeric", day: "numeric"}, + {year: "numeric", month: "numeric", day: "numeric"}, + {year: "numeric", month: "numeric"}, + {month: "numeric", day: "numeric"}, + {hour: "numeric", minute: "numeric", second: "numeric"}, + {hour: "numeric", minute: "numeric"} +]; + +locales.forEach(function (locale) { + subsets.forEach(function (subset) { + var format = new Intl.DateTimeFormat([locale], subset); + var actual = format.resolvedOptions(); + getDateTimeComponents().forEach(function (component) { + if (actual.hasOwnProperty(component)) { + if (!subset.hasOwnProperty(component)) { + $ERROR("Unrequested component " + component + + " added to requested subset " + JSON.stringify(subset) + + "; locale " + locale + "."); + } + try { + testValidDateTimeComponentValue(component, actual[component]); + } catch (e) { + e.message += " (Testing locale " + locale + "; subset " + + JSON.stringify(subset) + ")"; + throw e; + } + } else { + if (subset.hasOwnProperty(component)) { + $ERROR("Missing component " + component + + " from requested subset " + JSON.stringify(subset) + + "; locale " + locale + "."); + } + } + }); + }); +}); + diff --git a/js/src/tests/test262/intl402/ch12/12.2/browser.js b/js/src/tests/test262/intl402/ch12/12.2/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.2/browser.js diff --git a/js/src/tests/test262/intl402/ch12/12.2/shell.js b/js/src/tests/test262/intl402/ch12/12.2/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.2/shell.js 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 diff --git a/js/src/tests/test262/intl402/ch12/12.4/12.4_a.js b/js/src/tests/test262/intl402/ch12/12.4/12.4_a.js new file mode 100644 index 000000000..8e8d5954c --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.4/12.4_a.js @@ -0,0 +1,15 @@ +// 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 instances have the specified properties. + * @author Norbert Lindenberg + */ + +var obj = new Intl.DateTimeFormat(); + +var toStringValue = Object.prototype.toString.call(obj); +if (toStringValue !== "[object Object]") { + $ERROR("Intl.DateTimeFormat instance produces wrong [[Class]] - toString returns " + toStringValue + "."); +} + diff --git a/js/src/tests/test262/intl402/ch12/12.4/browser.js b/js/src/tests/test262/intl402/ch12/12.4/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.4/browser.js diff --git a/js/src/tests/test262/intl402/ch12/12.4/shell.js b/js/src/tests/test262/intl402/ch12/12.4/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/12.4/shell.js diff --git a/js/src/tests/test262/intl402/ch12/browser.js b/js/src/tests/test262/intl402/ch12/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/browser.js diff --git a/js/src/tests/test262/intl402/ch12/shell.js b/js/src/tests/test262/intl402/ch12/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/test262/intl402/ch12/shell.js |