TESTCASE(TestLikelySubtags);
TESTCASE(TestToLanguageTag);
TESTCASE(TestForLanguageTag);
+ TESTCASE(TestInvalidLanguageTag);
TESTCASE(TestTrailingNull);
TESTCASE(TestUnicodeDefines);
TESTCASE(TestEnglishExemplarCharacters);
{"ja-u-ijkl-efgh-abcd-ca-japanese-xx-yyy-zzz-kn", "ja@attribute=abcd-efgh-ijkl;calendar=japanese;colnumeric=yes;xx=yyy-zzz", FULL_LENGTH},
{"de-u-xc-xphonebk-co-phonebk-ca-buddhist-mo-very-lo-extensi-xd-that-de-should-vc-probably-xz-killthebuffer",
"de@calendar=buddhist;collation=phonebook;de=should;lo=extensi;mo=very;vc=probably;xc=xphonebk;xd=that;xz=yes", 91},
+ {"de-1901-1901", "de__1901", 7},
+ {"de-DE-1901-1901", "de_DE_1901", 10},
+ {"en-a-bbb-a-ccc", "en@a=bbb", 8},
/* #12761 */
{"en-a-bar-u-baz", "en@a=bar;attribute=baz", FULL_LENGTH},
{"en-a-bar-u-baz-x-u-foo", "en@a=bar;attribute=baz;x=u-foo", FULL_LENGTH},
{"zh-cmn-TW", "cmn_TW", FULL_LENGTH},
{"zh-x_t-ab", "zh", 2},
{"zh-hans-cn-u-ca-x_t-u", "zh_Hans_CN@calendar=yes", 15},
+ /* #20140 dupe keys in U-extension */
+ {"zh-u-ca-chinese-ca-gregory", "zh@calendar=chinese", FULL_LENGTH},
+ {"zh-u-ca-gregory-co-pinyin-ca-chinese", "zh@calendar=gregorian;collation=pinyin", FULL_LENGTH},
+ {"de-latn-DE-1901-u-co-phonebk-co-pinyin-ca-gregory", "de_Latn_DE_1901@calendar=gregorian;collation=phonebook", FULL_LENGTH},
+ {"th-u-kf-nu-thai-kf-false", "th@colcasefirst=yes;numbers=thai", FULL_LENGTH},
{NULL, NULL, 0}
};
}
}
+/* See https://unicode-org.atlassian.net/browse/ICU-20149 .
+ * Depending on the resolution of that bug, this test may have
+ * to be revised.
+ */
+static void TestInvalidLanguageTag(void) {
+ static const char* invalid_lang_tags[] = {
+ "zh-u-foo-foo-co-pinyin", /* duplicate attribute in U extension */
+ "zh-cmn-hans-u-foo-foo-co-pinyin", /* duplicate attribute in U extension */
+#if 0
+ /*
+ * These do not lead to an error. Instead, parsing stops at the 1st
+ * invalid subtag.
+ */
+ "de-DE-1901-1901", /* duplicate variant */
+ "en-a-bbb-a-ccc", /* duplicate extension */
+#endif
+ NULL
+ };
+ char locale[256];
+ for (const char** tag = invalid_lang_tags; *tag != NULL; tag++) {
+ UErrorCode status = U_ZERO_ERROR;
+ uloc_forLanguageTag(*tag, locale, sizeof(locale), NULL, &status);
+ if (status != U_ILLEGAL_ARGUMENT_ERROR) {
+ log_err("Error returned by uloc_forLanguageTag for input language tag [%s] : %s - expected error: %s\n",
+ *tag, u_errorName(status), u_errorName(U_ILLEGAL_ARGUMENT_ERROR));
+ }
+ }
+}
+
static void TestToUnicodeLocaleKey(void)
{
/* $IN specifies the result should be the input pointer itself */
{"zh-cmn-TW", "cmn_TW", NOERROR},
{"zh-x_t-ab", "zh", Integer.valueOf(3)},
{"zh-hans-cn-u-ca-x_t-u", "zh_Hans_CN@calendar=yes", Integer.valueOf(16)},
+ /* #20140 dupe keys in U-extension */
+ {"zh-u-ca-chinese-ca-gregory", "zh@calendar=chinese", NOERROR},
+ {"zh-u-ca-gregory-co-pinyin-ca-chinese", "zh@calendar=gregorian;collation=pinyin", NOERROR},
+ {"de-latn-DE-1901-u-co-phonebk-co-pinyin-ca-gregory", "de_Latn_DE_1901@calendar=gregorian;collation=phonebook", NOERROR},
+ {"th-u-kf-nu-thai-kf-false", "th@colcasefirst=yes;numbers=thai", NOERROR},
};
for (int i = 0; i < langtag_to_locale.length; i++) {