js/src/tests/test262/intl402/ch12/12.3/12.3.2_1_c.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/test262/intl402/ch12/12.3/12.3.2_1_c.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,34 @@
     1.4 +// Copyright 2012 Mozilla Corporation. All rights reserved.
     1.5 +// This code is governed by the BSD license found in the LICENSE file.
     1.6 +
     1.7 +/**
     1.8 + * @description Tests that format function is bound to its Intl.DateTimeFormat.
     1.9 + * @author Norbert Lindenberg
    1.10 + */
    1.11 +
    1.12 +$INCLUDE("testIntl.js");
    1.13 +
    1.14 +var dates = [new Date(), new Date(0), new Date(Date.parse("1989-11-09T17:57:00Z"))];
    1.15 +var locales = [undefined, ["de"], ["th-u-ca-gregory-nu-thai"], ["en"], ["ja-u-ca-japanese"], ["ar-u-ca-islamicc-nu-arab"]];
    1.16 +var options = [
    1.17 +    undefined,
    1.18 +    {hour12: false},
    1.19 +    {month: "long", day: "numeric", hour: "2-digit", minute: "2-digit"}
    1.20 +];
    1.21 +
    1.22 +locales.forEach(function (locales) {
    1.23 +    options.forEach(function (options) {
    1.24 +        var formatObj = new Intl.DateTimeFormat(locales, options);
    1.25 +        var formatFunc = formatObj.format;
    1.26 +        dates.forEach(function (date) {
    1.27 +            var referenceFormatted = formatObj.format(date);
    1.28 +            var formatted = formatFunc(date);
    1.29 +            if (referenceFormatted !== formatted) {
    1.30 +                $ERROR("format function produces different result than format method for locales " +
    1.31 +                    locales + "; options: " + (options ? JSON.stringify(options) : options) +
    1.32 +                    " : " + formatted + " vs. " + referenceFormatted + ".");
    1.33 +            }
    1.34 +        });
    1.35 +    });
    1.36 +});
    1.37 +

mercurial