tor-browser

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

numbering-system-options.js (2509B)


      1 // Copyright 2012 Mozilla Corporation. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-initializenumberformat
      6 description: >
      7    Tests that the options numberingSystem and calendar can be  set through
      8    either the locale or the options.
      9 author: Norbert Lindenberg, Daniel Ehrenberg
     10 ---*/
     11 
     12 let defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
     13 
     14 let supportedNumberingSystems = ["latn", "arab"].filter(nu =>
     15  new Intl.NumberFormat(defaultLocale + "-u-nu-" + nu)
     16    .resolvedOptions().numberingSystem === nu
     17 );
     18 
     19 let options = [
     20    {key: "nu", property: "numberingSystem", type: "string", values: supportedNumberingSystems},
     21 ];
     22 
     23 options.forEach(function (option) {
     24    let numberFormat, opt, result;
     25    
     26    // find out which values are supported for a property in the default locale
     27    let supportedValues = [];
     28    option.values.forEach(function (value) {
     29        opt = {};
     30        opt[option.property] = value;
     31        numberFormat = new Intl.NumberFormat([defaultLocale], opt);
     32        result = numberFormat.resolvedOptions()[option.property];
     33        if (result !== undefined && supportedValues.indexOf(result) === -1) {
     34            supportedValues.push(result);
     35        }
     36    });
     37    
     38    // verify that the supported values can also be set through the locale
     39    supportedValues.forEach(function (value) {
     40        numberFormat = new Intl.NumberFormat([defaultLocale + "-u-" + option.key + "-" + value]);
     41        result = numberFormat.resolvedOptions()[option.property];
     42        assert.sameValue(result, value, "Property " + option.property + " couldn't be set through locale extension key " + option.key + ".");
     43    });
     44    
     45    // verify that the options setting overrides the locale setting
     46    supportedValues.forEach(function (value) {
     47        let otherValue;
     48        option.values.forEach(function (possibleValue) {
     49            if (possibleValue !== value) {
     50                otherValue = possibleValue;
     51            }
     52        });
     53        if (otherValue !== undefined) {
     54            opt = {};
     55            opt[option.property] = value;
     56            numberFormat = new Intl.NumberFormat([defaultLocale + "-u-" + option.key + "-" + otherValue], opt);
     57            result = numberFormat.resolvedOptions()[option.property];
     58            assert.sameValue(result, value, "Options value for property " + option.property + " doesn't override locale extension key " + option.key + ".");
     59        }
     60    });
     61 });
     62 
     63 
     64 reportCompare(0, 0);