From d71ffa59d5fa2df454bf1c1853b0ccfc87fe3bcd Mon Sep 17 00:00:00 2001 From: Norbert Lindenberg Date: Sun, 26 Aug 2012 20:50:24 -0700 Subject: Added new tests for chapters 10 to 13 of the ECMAScript Internationalization API Specification. --- test/suite/intl402/ch13/13.3/13.3.0_7.js | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/suite/intl402/ch13/13.3/13.3.0_7.js (limited to 'test/suite/intl402/ch13/13.3/13.3.0_7.js') diff --git a/test/suite/intl402/ch13/13.3/13.3.0_7.js b/test/suite/intl402/ch13/13.3/13.3.0_7.js new file mode 100644 index 000000000..fe7c9271d --- /dev/null +++ b/test/suite/intl402/ch13/13.3/13.3.0_7.js @@ -0,0 +1,58 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/** + * @description Tests that Date.prototype.toLocaleString & Co. produces the same results as Intl.DateTimeFormat. + * @author Norbert Lindenberg + */ + +$INCLUDE("testIntl.js"); + +var functions = { + toLocaleString: [Date.prototype.toLocaleString, + {year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric"}], + toLocaleDateString: [Date.prototype.toLocaleDateString, + {year: "numeric", month: "numeric", day: "numeric"}], + toLocaleTimeString: [Date.prototype.toLocaleTimeString, + {hour: "numeric", minute: "numeric", second: "numeric"}] +}; +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"} +]; + +Object.getOwnPropertyNames(functions).forEach(function (p) { + var f = functions[p][0]; + var defaults = functions[p][1]; + locales.forEach(function (locales) { + options.forEach(function (options) { + var constructorOptions = options; + if (options === undefined) { + constructorOptions = defaults; + } else if (options.day === undefined) { + // for simplicity, our options above have either both date and time or neither + constructorOptions = Object.create(defaults); + for (var prop in options) { + if (options.hasOwnProperty(prop)) { + constructorOptions[prop] = options[prop]; + } + } + } + var referenceDateTimeFormat = new Intl.DateTimeFormat(locales, constructorOptions); + var referenceFormatted = dates.map(referenceDateTimeFormat.format); + + var formatted = dates.map(function (a) { return f.call(a, locales, options); }); + try { + testArraysAreSame(referenceFormatted, formatted); + } catch (e) { + e.message += " (Testing with locales " + locales + "; options " + + (options ? JSON.stringify(options) : options) + ".)"; + throw e; + } + }); + }); +}); + -- cgit v1.2.3