Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | // Copyright 2012 Mozilla Corporation. All rights reserved. |
michael@0 | 2 | // This code is governed by the BSD license found in the LICENSE file. |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * @description Tests that language tags with invalid subtag sequences are not accepted. |
michael@0 | 6 | * @author Norbert Lindenberg |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | $INCLUDE("testIntl.js"); |
michael@0 | 10 | |
michael@0 | 11 | var invalidLanguageTags = [ |
michael@0 | 12 | "", // empty tag |
michael@0 | 13 | "i", // singleton alone |
michael@0 | 14 | "x", // private use without subtag |
michael@0 | 15 | "u", // extension singleton in first place |
michael@0 | 16 | "419", // region code in first place |
michael@0 | 17 | "u-nu-latn-cu-bob", // extension sequence without language |
michael@0 | 18 | "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code, |
michael@0 | 19 | // but those can't be followed by extlang codes. |
michael@0 | 20 | "cmn-hans-cn-u-u", // duplicate singleton |
michael@0 | 21 | "cmn-hans-cn-t-u-ca-u", // duplicate singleton |
michael@0 | 22 | "de-gregory-gregory", // duplicate variant |
michael@0 | 23 | "*", // language range |
michael@0 | 24 | "de-*", // language range |
michael@0 | 25 | "中文", // non-ASCII letters |
michael@0 | 26 | "en-ß", // non-ASCII letters |
michael@0 | 27 | "ıd" // non-ASCII letters |
michael@0 | 28 | ]; |
michael@0 | 29 | |
michael@0 | 30 | testWithIntlConstructors(function (Constructor) { |
michael@0 | 31 | invalidLanguageTags.forEach(function (tag) { |
michael@0 | 32 | var error; |
michael@0 | 33 | try { |
michael@0 | 34 | // this must throw an exception for an invalid language tag |
michael@0 | 35 | var obj = new Constructor([tag]); |
michael@0 | 36 | } catch (e) { |
michael@0 | 37 | error = e; |
michael@0 | 38 | } |
michael@0 | 39 | if (error === undefined) { |
michael@0 | 40 | $ERROR("Invalid language tag " + tag + " was not rejected."); |
michael@0 | 41 | } else if (error.name !== "RangeError") { |
michael@0 | 42 | $ERROR("Invalid language tag " + tag + " was rejected with wrong error " + error.name + "."); |
michael@0 | 43 | } |
michael@0 | 44 | }); |
michael@0 | 45 | return true; |
michael@0 | 46 | }); |
michael@0 | 47 |