duplicate-singleton-variant.js (1314B)
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")) 2 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 // Check for duplicate variants and singletons case-insensitively, but don't 8 // check in privateuse components. 9 10 function checkInvalidLocale(locale) 11 { 12 try 13 { 14 new Intl.NumberFormat(locale); 15 throw new Error("didn't throw"); 16 } 17 catch (e) 18 { 19 assertEq(e instanceof RangeError, true, 20 "expected RangeError for locale '" + locale + "', got " + e); 21 } 22 } 23 24 var badLocales = 25 [ 26 "en-u-foo-U-foo", 27 "en-tester-Tester", 28 "en-tesTER-TESter", 29 "de-DE-u-kn-true-U-kn-true", 30 "ar-u-foo-q-bar-u-baz", 31 "ar-z-moo-u-foo-q-bar-z-eit-u-baz", 32 ]; 33 34 for (var locale of badLocales) 35 checkInvalidLocale(locale); 36 37 // Fully-privateuse locales are rejected. 38 for (var locale of badLocales) 39 assertThrowsInstanceOf(() => new Intl.NumberFormat("x-" + locale), RangeError); 40 41 // Locales with trailing privateuse also okay. 42 for (var locale of badLocales) 43 { 44 new Intl.NumberFormat("en-x-" + locale).format(5); 45 new Intl.NumberFormat("en-u-foo-x-u-" + locale).format(5); 46 } 47 48 if (typeof reportCompare === "function") 49 reportCompare(true, true);