ICU-20661 Adding test that (U)Locale constructor accepts BCP47.
This commit is contained in:
parent
a3956a8d8b
commit
3bdb509ac5
@ -253,6 +253,7 @@ void LocaleTest::runIndexedTest( int32_t index, UBool exec, const char* &name, c
|
||||
TESTCASE_AUTO(TestBug13277);
|
||||
TESTCASE_AUTO(TestBug13554);
|
||||
TESTCASE_AUTO(TestBug20410);
|
||||
TESTCASE_AUTO(TestConstructorAcceptsBCP47);
|
||||
TESTCASE_AUTO(TestForLanguageTag);
|
||||
TESTCASE_AUTO(TestToLanguageTag);
|
||||
TESTCASE_AUTO(TestMoveAssign);
|
||||
@ -3078,6 +3079,45 @@ void LocaleTest::TestBug20410() {
|
||||
assertEquals(locid4, expected4.getName(), result4.getName());
|
||||
}
|
||||
|
||||
void LocaleTest::TestConstructorAcceptsBCP47() {
|
||||
IcuTestErrorCode status(*this, "TestConstructorAcceptsBCP47");
|
||||
|
||||
Locale loc1("ar-EG-u-nu-latn");
|
||||
Locale loc2("ar-EG@numbers=latn");
|
||||
Locale loc3("ar-EG");
|
||||
std::string val;
|
||||
|
||||
// Check getKeywordValue "numbers"
|
||||
val = loc1.getKeywordValue<std::string>("numbers", status);
|
||||
assertEquals("BCP47 syntax has ICU keyword value", "latn", val.c_str());
|
||||
|
||||
val = loc2.getKeywordValue<std::string>("numbers", status);
|
||||
assertEquals("ICU syntax has ICU keyword value", "latn", val.c_str());
|
||||
|
||||
val = loc3.getKeywordValue<std::string>("numbers", status);
|
||||
assertEquals("Default, ICU keyword", "", val.c_str());
|
||||
|
||||
// Check getUnicodeKeywordValue "nu"
|
||||
val = loc1.getUnicodeKeywordValue<std::string>("nu", status);
|
||||
assertEquals("BCP47 syntax has short unicode keyword value", "latn", val.c_str());
|
||||
|
||||
val = loc2.getUnicodeKeywordValue<std::string>("nu", status);
|
||||
assertEquals("ICU syntax has short unicode keyword value", "latn", val.c_str());
|
||||
|
||||
val = loc3.getUnicodeKeywordValue<std::string>("nu", status);
|
||||
status.expectErrorAndReset(U_ILLEGAL_ARGUMENT_ERROR, "Default, short unicode keyword");
|
||||
|
||||
// Check getUnicodeKeywordValue "numbers"
|
||||
val = loc1.getUnicodeKeywordValue<std::string>("numbers", status);
|
||||
assertEquals("BCP47 syntax has long unicode keyword value", "latn", val.c_str());
|
||||
|
||||
val = loc2.getUnicodeKeywordValue<std::string>("numbers", status);
|
||||
assertEquals("ICU syntax has long unicode keyword value", "latn", val.c_str());
|
||||
|
||||
val = loc3.getUnicodeKeywordValue<std::string>("numbers", status);
|
||||
status.expectErrorAndReset(U_ILLEGAL_ARGUMENT_ERROR, "Default, long unicode keyword");
|
||||
}
|
||||
|
||||
void LocaleTest::TestForLanguageTag() {
|
||||
IcuTestErrorCode status(*this, "TestForLanguageTag()");
|
||||
|
||||
|
@ -117,6 +117,7 @@ public:
|
||||
void TestBug13277();
|
||||
void TestBug13554();
|
||||
void TestBug20410();
|
||||
void TestConstructorAcceptsBCP47();
|
||||
|
||||
void TestAddLikelySubtags();
|
||||
void TestMinimizeSubtags();
|
||||
|
@ -4138,6 +4138,26 @@ public class ULocaleTest extends TestFmwk {
|
||||
assertEquals("getExtension(\'0\')", "abc", uloc.getExtension('0'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestConstructorAcceptsBCP47() {
|
||||
ULocale loc1 = new ULocale("ar-EG-u-nu-latn");
|
||||
ULocale loc2 = new ULocale("ar-EG@numbers=latn");
|
||||
ULocale loc3 = new ULocale("ar-EG");
|
||||
String val;
|
||||
|
||||
// Check getKeywordValue "numbers"
|
||||
val = loc1.getKeywordValue("numbers");
|
||||
assertEquals("BCP47 syntax has ICU keyword value", "latn", val);
|
||||
|
||||
val = loc2.getKeywordValue("numbers");
|
||||
assertEquals("ICU syntax has ICU keyword value", "latn", val);
|
||||
|
||||
val = loc3.getKeywordValue("numbers");
|
||||
assertEquals("Default, ICU keyword", null, val);
|
||||
|
||||
// Note: ICU does not have getUnicodeKeywordValue()
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestForLanguageTag() {
|
||||
final Integer NOERROR = Integer.valueOf(-1);
|
||||
|
Loading…
Reference in New Issue
Block a user