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 (1706B)


      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: 11.2.3_b
      6 description: >
      7    Tests that Intl.NumberFormat 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 = 1234567.89;
     14 
     15 locales.forEach(function (locale) {
     16    var defaultNumberFormat = new Intl.NumberFormat([locale]);
     17    var defaultOptions = defaultNumberFormat.resolvedOptions();
     18    var defaultOptionsJSON = JSON.stringify(defaultOptions);
     19    var defaultLocale = defaultOptions.locale;
     20    var defaultFormatted = defaultNumberFormat.format(input);
     21 
     22    var keyValues = {
     23        "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"],
     24        "nu": ["native", "traditio", "finance", "invalid"]
     25    };
     26    
     27    Object.getOwnPropertyNames(keyValues).forEach(function (key) {
     28        keyValues[key].forEach(function (value) {
     29            var numberFormat = new Intl.NumberFormat([locale + "-u-" + key + "-" + value]);
     30            var options = numberFormat.resolvedOptions();
     31            assert.sameValue(options.locale, defaultLocale, "Locale " + options.locale + " is affected by key " + key + "; value " + value + ".");
     32            assert.sameValue(JSON.stringify(options), defaultOptionsJSON, "Resolved options " + JSON.stringify(options) + " are affected by key " + key + "; value " + value + ".");
     33            assert.sameValue(numberFormat.format(input), defaultFormatted, "Formatted value " + numberFormat.format(input) + " is affected by key " + key + "; value " + value + ".");
     34        });
     35    });
     36 });
     37 
     38 reportCompare(0, 0);