tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ignore-invalid-unicode-ext-values.js (1892B)


      1 // Copyright 2012 Mozilla Corporation. All rights reserved.
      2 // This code is governed by the license found in the LICENSE file.
      3 
      4 /*---
      5 es5id: 12.2.3_b
      6 description: >
      7    Tests that Intl.DateTimeFormat does not accept Unicode locale
      8    extension keys and values that are not allowed.
      9 author: Norbert Lindenberg
     10 ---*/
     11 
     12 var locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"];
     13 var input = new Date(Date.parse("1989-11-09T17:57:00Z"));
     14 
     15 locales.forEach(function (locale) {
     16    var defaultDateTimeFormat = new Intl.DateTimeFormat([locale]);
     17    var defaultOptions = defaultDateTimeFormat.resolvedOptions();
     18    var defaultOptionsJSON = JSON.stringify(defaultOptions);
     19    var defaultLocale = defaultOptions.locale;
     20    var defaultFormatted = defaultDateTimeFormat.format(input);
     21 
     22    var keyValues = {
     23        "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"], // DateTimeFormat internally uses NumberFormat
     24        "nu": ["native", "traditio", "finance", "invalid"],
     25        "tz": ["usnavajo", "utcw01", "aumel", "uslax", "usnyc", "deber", "invalid"]
     26    };
     27    
     28    Object.getOwnPropertyNames(keyValues).forEach(function (key) {
     29        keyValues[key].forEach(function (value) {
     30            var dateTimeFormat = new Intl.DateTimeFormat([locale + "-u-" + key + "-" + value]);
     31            var options = dateTimeFormat.resolvedOptions();
     32            assert.sameValue(options.locale, defaultLocale, "Locale " + options.locale + " is affected by key " + key + "; value " + value + ".");
     33            assert.sameValue(JSON.stringify(options), defaultOptionsJSON, "Resolved options " + JSON.stringify(options) + " are affected by key " + key + "; value " + value + ".");
     34            assert.sameValue(dateTimeFormat.format(input), defaultFormatted, "Formatted value " + dateTimeFormat.format(input) + " is affected by key " + key + "; value " + value + ".");
     35        });
     36    });
     37 });
     38 
     39 reportCompare(0, 0);