diff options
Diffstat (limited to 'js/src/tests/test262/intl402/ch12/12.1')
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_1.js | 43 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_18.js | 15 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_22.js | 18 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_23.js | 14 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_25.js | 12 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_5.js | 18 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_6.js | 12 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_TDTO.js | 107 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.1_a.js | 18 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.2.1_4.js | 21 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.2.js | 30 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1.3.js | 19 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/12.1_L15.js | 14 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/browser.js | 0 | ||||
-rw-r--r-- | js/src/tests/test262/intl402/ch12/12.1/shell.js | 0 |
15 files changed, 341 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 |