From 190cf5c730258ca9d2f94d6b33eee5e01aca3d0c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 27 Apr 2018 11:49:37 +0200 Subject: [PATCH] Extract list of structurally invalid tags from invalid-tags.js. --- harness/testIntl.js | 60 +++++++++++++++++++ .../Intl/getCanonicalLocales/invalid-tags.js | 53 +--------------- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/harness/testIntl.js b/harness/testIntl.js index 690791d7d0..3b9e62d7ce 100644 --- a/harness/testIntl.js +++ b/harness/testIntl.js @@ -162,6 +162,66 @@ function getLocaleSupportInfo(Constructor) { } +/** + * Returns an array of strings for which IsStructurallyValidLanguageTag() returns false + */ +function getInvalidLanguageTags() { + var invalidLanguageTags = [ + "", // empty tag + "i", // singleton alone + "x", // private use without subtag + "u", // extension singleton in first place + "419", // region code in first place + "u-nu-latn-cu-bob", // extension sequence without language + "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code, + // but those can't be followed by extlang codes. + "cmn-hans-cn-u-u", // duplicate singleton + "cmn-hans-cn-t-u-ca-u", // duplicate singleton + "de-gregory-gregory", // duplicate variant + "*", // language range + "de-*", // language range + "中文", // non-ASCII letters + "en-ß", // non-ASCII letters + "ıd", // non-ASCII letters + + // underscores in different parts of the language tag + "de_DE", + "DE_de", + "cmn_Hans", + "cmn-hans_cn", + "es_419", + "es-419-u-nu-latn-cu_bob", + "i_klingon", + "cmn-hans-cn-t-ca-u-ca-x_t-u", + "enochian_enochian", + "de-gregory_u-ca-gregory", + + "en\u0000", // null-terminator sequence + " en", // leading whitespace + "en ", // trailing whitespace + "it-IT-Latn", // country before script tag + "de-u", // incomplete Unicode extension sequences + "de-u-", + "de-u-ca-", + "de-u-ca-gregory-", + "si-x", // incomplete private-use tags + "x-", + "x-y-", + ]; + + // make sure the data above is correct + for (var i = 0; i < invalidLanguageTags.length; ++i) { + var invalidTag = invalidLanguageTags[i]; + assert( + !isCanonicalizedStructurallyValidLanguageTag(invalidTag), + "Test data \"" + invalidTag + "\" is a canonicalized and structurally valid language tag." + ); + } + + return invalidLanguageTags; +} + + /** * @description Tests whether locale is a String value representing a * structurally valid and canonicalized BCP 47 language tag, as defined in diff --git a/test/intl402/Intl/getCanonicalLocales/invalid-tags.js b/test/intl402/Intl/getCanonicalLocales/invalid-tags.js index e218f21f1b..b131603a50 100644 --- a/test/intl402/Intl/getCanonicalLocales/invalid-tags.js +++ b/test/intl402/Intl/getCanonicalLocales/invalid-tags.js @@ -21,58 +21,7 @@ info: | includes: [testIntl.js] ---*/ -var invalidLanguageTags = [ - "", // empty tag - "i", // singleton alone - "x", // private use without subtag - "u", // extension singleton in first place - "419", // region code in first place - "u-nu-latn-cu-bob", // extension sequence without language - "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code, - // but those can't be followed by extlang codes. - "cmn-hans-cn-u-u", // duplicate singleton - "cmn-hans-cn-t-u-ca-u", // duplicate singleton - "de-gregory-gregory", // duplicate variant - "*", // language range - "de-*", // language range - "中文", // non-ASCII letters - "en-ß", // non-ASCII letters - "ıd", // non-ASCII letters - - // underscores in different parts of the language tag - "de_DE", - "DE_de", - "cmn_Hans", - "cmn-hans_cn", - "es_419", - "es-419-u-nu-latn-cu_bob", - "i_klingon", - "cmn-hans-cn-t-ca-u-ca-x_t-u", - "enochian_enochian", - "de-gregory_u-ca-gregory", - - "en\u0000", // null-terminator sequence - " en", // leading whitespace - "en ", // trailing whitespace - "it-IT-Latn", // country before script tag - "de-u", // incomplete Unicode extension sequences - "de-u-", - "de-u-ca-", - "de-u-ca-gregory-", - "si-x", // incomplete private-use tags - "x-", - "x-y-", -]; - -// make sure the data above is correct -for (var i = 0; i < invalidLanguageTags.length; ++i) { - var invalidTag = invalidLanguageTags[i]; - assert( - !isCanonicalizedStructurallyValidLanguageTag(invalidTag), - "Test data \"" + invalidTag + "\" is a canonicalized and structurally valid language tag." - ); -} - +var invalidLanguageTags = getInvalidLanguageTags(); for (var i = 0; i < invalidLanguageTags.length; ++i) { var invalidTag = invalidLanguageTags[i]; assert.throws(RangeError, function() {