tor-browser

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

test-option-currency.js (2774B)


      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 es5id: 11.1.1_17
      6 description: Tests that the option currency is processed correctly.
      7 author: Norbert Lindenberg
      8 ---*/
      9 
     10 var validValues = ["CNY", "USD", "EUR", "IDR", "jpy", {toString: function () {return "INR";}}];
     11 var invalidValues = ["$", "SFr.", "US$", "ßP", {toString: function () {return;}}];
     12 
     13 var defaultLocale = new Intl.NumberFormat().resolvedOptions().locale;
     14 
     15 validValues.forEach(function (value) {
     16    var format, actual, expected;
     17 
     18    // with currency style, we should get the upper case form back
     19    format = new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value});
     20    actual = format.resolvedOptions().currency;
     21    expected = value.toString().toUpperCase();
     22    assert.sameValue(actual, expected, "Incorrect resolved currency with currency style.");
     23    
     24    // without currency style, we shouldn't get any currency back
     25    format = new Intl.NumberFormat([defaultLocale], {currency: value});
     26    actual = format.resolvedOptions().currency;
     27    expected = undefined;
     28    assert.sameValue(actual, expected, "Incorrect resolved currency with non-currency style.");
     29    
     30    // currencies specified through the locale must be ignored
     31    format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value});
     32    actual = format.resolvedOptions().currency;
     33    expected = value.toString().toUpperCase();
     34    assert.sameValue(actual, expected, "Incorrect resolved currency with -u-cu- and currency style.");
     35    
     36    format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value});
     37    actual = format.resolvedOptions().currency;
     38    expected = undefined;
     39    assert.sameValue(actual, expected, "Incorrect resolved currency with -u-cu- and non-currency style.");
     40 });
     41 
     42 invalidValues.forEach(function (value) {
     43    assert.throws(RangeError, function () {
     44            return new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value});
     45    }, "Invalid currency value " + value + " was not rejected.");
     46    assert.throws(RangeError, function () {
     47            return new Intl.NumberFormat([defaultLocale], {currency: value});
     48    }, "Invalid currency value " + value + " was not rejected.");
     49    assert.throws(RangeError, function () {
     50            return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value});
     51    }, "Invalid currency value " + value + " was not rejected.");
     52    assert.throws(RangeError, function () {
     53            return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value});
     54    }, "Invalid currency value " + value + " was not rejected.");
     55 });
     56 
     57 reportCompare(0, 0);