X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/48b980fed3435926e0b3a8d72ecb58be703a1c7a..729e4ab9bc6618bc3d8a898e575df7f4019e29ca:/icuSources/test/intltest/itrbnf.cpp diff --git a/icuSources/test/intltest/itrbnf.cpp b/icuSources/test/intltest/itrbnf.cpp index ceb16039..44ff3501 100644 --- a/icuSources/test/intltest/itrbnf.cpp +++ b/icuSources/test/intltest/itrbnf.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 1996-2008, International Business Machines Corporation and * + * Copyright (C) 1996-2010, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -37,7 +37,7 @@ name = #test; \ if (exec) { \ logln(#test "---"); \ - logln((UnicodeString)""); \ + logln(); \ test(); \ } \ break @@ -78,14 +78,15 @@ void IntlTestRBNF::runIndexedTest(int32_t index, UBool exec, const char* &name, #if U_HAVE_RBNF void IntlTestRBNF::TestHebrewFraction() { + // this is the expected output for 123.45, with no '<' in it. UChar text1[] = { 0x05de, 0x05d0, 0x05d4, 0x0020, 0x05e2, 0x05e9, 0x05e8, 0x05d9, 0x05dd, 0x0020, 0x05d5, 0x05e9, 0x05dc, 0x05d5, 0x05e9, 0x0020, 0x05e0, 0x05e7, 0x05d5, 0x05d3, 0x05d4, 0x0020, - 0x05d0, 0x05e8, 0x05d1, 0x05e2, 0x05d9, 0x05dd, 0x0020, - 0x05d5, 0x05d7, 0x05de, 0x05e9, 0x0000, + 0x05d0, 0x05e8, 0x05d1, 0x05e2, 0x0020, + 0x05d7, 0x05de, 0x05e9, 0x0000, }; UChar text2[] = { 0x05DE, 0x05D0, 0x05D4, 0x0020, @@ -94,11 +95,16 @@ void IntlTestRBNF::TestHebrewFraction() { 0x05E0, 0x05E7, 0x05D5, 0x05D3, 0x05D4, 0x0020, 0x05D0, 0x05E4, 0x05E1, 0x0020, 0x05D0, 0x05E4, 0x05E1, 0x0020, - 0x05D0, 0x05E8, 0x05D1, 0x05E2, 0x05D9, 0x05DD, 0x0020, - 0x05D5, 0x05D7, 0x05DE, 0x05E9, 0x0000, + 0x05D0, 0x05E8, 0x05D1, 0x05E2, 0x0020, + 0x05D7, 0x05DE, 0x05E9, 0x0000, }; UErrorCode status = U_ZERO_ERROR; RuleBasedNumberFormat* formatter = new RuleBasedNumberFormat(URBNF_SPELLOUT, "he_IL", status); + if (status == U_MISSING_RESOURCE_ERROR || status == U_FILE_ACCESS_ERROR) { + errcheckln(status, "Failed in constructing RuleBasedNumberFormat - %s", u_errorName(status)); + delete formatter; + return; + } UnicodeString result; Formattable parseResult; ParsePosition pp(0); @@ -108,10 +114,10 @@ void IntlTestRBNF::TestHebrewFraction() { if (result != expected) { errln((UnicodeString)"expected '" + TestUtility::hex(expected) + "'\nbut got: '" + TestUtility::hex(result) + "'"); } else { - formatter->parse(result, parseResult, pp); - if (parseResult.getDouble() != 123.45) { - errln("expected 123.45 but got: %g", parseResult.getDouble()); - } +// formatter->parse(result, parseResult, pp); +// if (parseResult.getDouble() != 123.45) { +// errln("expected 123.45 but got: %g", parseResult.getDouble()); +// } } } { @@ -122,10 +128,10 @@ void IntlTestRBNF::TestHebrewFraction() { errln((UnicodeString)"expected '" + TestUtility::hex(expected) + "'\nbut got: '" + TestUtility::hex(result) + "'"); } else { pp.setIndex(0); - formatter->parse(result, parseResult, pp); - if (parseResult.getDouble() != 123.0045) { - errln("expected 123.0045 but got: %g", parseResult.getDouble()); - } +// formatter->parse(result, parseResult, pp); +// if (parseResult.getDouble() != 123.0045) { +// errln("expected 123.0045 but got: %g", parseResult.getDouble()); +// } } } delete formatter; @@ -139,6 +145,11 @@ IntlTestRBNF::TestAPI() { UErrorCode status = U_ZERO_ERROR; RuleBasedNumberFormat* formatter = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getUS(), status); + if (status == U_MISSING_RESOURCE_ERROR || status == U_FILE_ACCESS_ERROR) { + dataerrln("Unable to create formatter. - %s", u_errorName(status)); + delete formatter; + return; + } logln("RBNF API test starting"); // test clone @@ -168,12 +179,23 @@ IntlTestRBNF::TestAPI() { // test rule constructor { logln("Testing rule constructor"); - UResourceBundle *en = ures_open(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "rbnf", "en", &status); + LocalUResourceBundlePointer en(ures_open(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "rbnf", "en", &status)); if(U_FAILURE(status)) { errln("Unable to access resource bundle with data!"); } else { int32_t ruleLen = 0; - const UChar *spelloutRules = ures_getStringByKey(en, "SpelloutRules", &ruleLen, &status); + int32_t len = 0; + LocalUResourceBundlePointer rbnfRules(ures_getByKey(en.getAlias(), "RBNFRules", NULL, &status)); + LocalUResourceBundlePointer ruleSets(ures_getByKey(rbnfRules.getAlias(), "SpelloutRules", NULL, &status)); + UnicodeString desc; + while (ures_hasNext(ruleSets.getAlias())) { + const UChar* currentString = ures_getNextString(ruleSets.getAlias(), &len, NULL, &status); + ruleLen += len; + desc.append(currentString); + } + + const UChar *spelloutRules = desc.getTerminatedBuffer(); + if(U_FAILURE(status) || ruleLen == 0 || spelloutRules == NULL) { errln("Unable to access the rules string!"); } else { @@ -189,7 +211,6 @@ IntlTestRBNF::TestAPI() { errln("Formatter constructed from the original rules should be semantically equivalent to the original!"); } } - ures_close(en); } } @@ -215,6 +236,9 @@ IntlTestRBNF::TestAPI() { } #if !UCONFIG_NO_COLLATION + +#define NUMERIC_STRINGS_NOT_PARSEABLE 1 // ticket/8224 + // test ruleset names { logln("Testing getNumberOfRuleSetNames, getRuleSetName and format using rule set names"); @@ -231,6 +255,10 @@ IntlTestRBNF::TestAPI() { FieldPosition pos1, pos2; UnicodeString intFormatResult, doubleFormatResult; Formattable intParseResult, doubleParseResult; +#if NUMERIC_STRINGS_NOT_PARSEABLE + UBool parseDoubleNonLenientOK = TRUE; + UBool parseDoubleLenientOK = TRUE; +#endif ruleSetName = formatter->getRuleSetName(i); log("Rule set name %i is ", i); @@ -244,18 +272,53 @@ IntlTestRBNF::TestAPI() { } logln(intFormatResult); logln(doubleFormatResult); + +#if NUMERIC_STRINGS_NOT_PARSEABLE + // "spellout-numbering-year" ruleSet produces (above) a numeric string using: + // "x.x: =#,###0.#=;" + // which will not parse (below) - we believe this is CORRECT behavior, as found in ICU 4.0 (see ticket/8224). + // Note this numeric string "89,3411.2" will not even parse with Lenient = TRUE because + // the NumberFormat (used as last-resort) in NFSubstitution::doParse fails. + UnicodeString numberingYear = UNICODE_STRING_SIMPLE("spellout-numbering-year"); + + // "spellout-ordinal" and "spellout-ordinal-verbose" ruleSets produce (above) a numeric string using: + // "x.x: =#,##0.#=;" -> "893,411.2" + // which will not parse (below) with Lenient = FALSE, but does parse with Lenient = TRUE because + // NFSubstitution::doParse will succeed when using NumberFormat as last-resort. + UnicodeString ordinal = UNICODE_STRING_SIMPLE("spellout-ordinal"); + + // RuleSets other than spellout-numbering-year and spellout-ordinalXXX produce fully spelled out text above + // which is fully parseable. + parseDoubleLenientOK = ( ruleSetName.indexOf(numberingYear) == -1 ); + parseDoubleNonLenientOK = ( ruleSetName.indexOf(numberingYear) == -1 && ruleSetName.indexOf(ordinal) == -1 ); +#endif + formatter->setLenient(TRUE); formatter->parse(intFormatResult, intParseResult, status); formatter->parse(doubleFormatResult, doubleParseResult, status); logln("Parse results for lenient = TRUE, %i, %f", intParseResult.getLong(), doubleParseResult.getDouble()); +#if NUMERIC_STRINGS_NOT_PARSEABLE + if((!parseDoubleLenientOK) && (status == U_INVALID_FORMAT_ERROR)) { + status = U_USING_FALLBACK_WARNING; + logln("Clearing expected U_INVALID_FORMAT_ERROR during parsing"); + } +#endif + formatter->setLenient(FALSE); formatter->parse(intFormatResult, intParseResult, status); formatter->parse(doubleFormatResult, doubleParseResult, status); logln("Parse results for lenient = FALSE, %i, %f", intParseResult.getLong(), doubleParseResult.getDouble()); +#if NUMERIC_STRINGS_NOT_PARSEABLE + if((!parseDoubleNonLenientOK) && (status == U_INVALID_FORMAT_ERROR)) { + status = U_USING_FALLBACK_WARNING; + logln("Clearing expected U_INVALID_FORMAT_ERROR during parsing"); + } +#endif + if(U_FAILURE(status)) { errln("Error during parsing"); } @@ -377,7 +440,7 @@ void IntlTestRBNF::TestFractionalRuleSet() UParseError perror; RuleBasedNumberFormat formatter(fracRules, Locale::getEnglish(), perror, status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "0", "0" }, @@ -1044,9 +1107,8 @@ IntlTestRBNF::TestEnglishSpellout() UErrorCode status = U_ZERO_ERROR; RuleBasedNumberFormat* formatter = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getUS(), status); - if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "1", "one" }, @@ -1057,18 +1119,18 @@ IntlTestRBNF::TestEnglishSpellout() { "73", "seventy-three" }, { "88", "eighty-eight" }, { "100", "one hundred" }, - { "106", "one hundred and six" }, - { "127", "one hundred and twenty-seven" }, + { "106", "one hundred six" }, + { "127", "one hundred twenty-seven" }, { "200", "two hundred" }, - { "579", "five hundred and seventy-nine" }, + { "579", "five hundred seventy-nine" }, { "1,000", "one thousand" }, { "2,000", "two thousand" }, - { "3,004", "three thousand and four" }, - { "4,567", "four thousand five hundred and sixty-seven" }, - { "15,943", "fifteen thousand nine hundred and forty-three" }, - { "2,345,678", "two million, three hundred and forty-five thousand, six hundred and seventy-eight" }, + { "3,004", "three thousand four" }, + { "4,567", "four thousand five hundred sixty-seven" }, + { "15,943", "fifteen thousand nine hundred forty-three" }, + { "2,345,678", "two million three hundred forty-five thousand six hundred seventy-eight" }, { "-36", "minus thirty-six" }, - { "234.567", "two hundred and thirty-four point five six seven" }, + { "234.567", "two hundred thirty-four point five six seven" }, { NULL, NULL} }; @@ -1099,7 +1161,7 @@ IntlTestRBNF::TestOrdinalAbbreviations() = new RuleBasedNumberFormat(URBNF_ORDINAL, Locale::getUS(), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "1", "1st" }, @@ -1135,7 +1197,7 @@ IntlTestRBNF::TestDurations() = new RuleBasedNumberFormat(URBNF_DURATION, Locale::getUS(), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "3,600", "1:00:00" }, //move me and I fail @@ -1174,7 +1236,7 @@ IntlTestRBNF::TestSpanishSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("es", "ES", ""), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "1", "uno" }, @@ -1195,9 +1257,9 @@ IntlTestRBNF::TestSpanishSpellout() { "3,004", "tres mil cuatro" }, { "4,567", "cuatro mil quinientos sesenta y siete" }, { "15,943", "quince mil novecientos cuarenta y tres" }, - { "2,345,678", "dos mill\\u00f3n trescientos cuarenta y cinco mil seiscientos setenta y ocho"}, + { "2,345,678", "dos millones trescientos cuarenta y cinco mil seiscientos setenta y ocho"}, { "-36", "menos treinta y seis" }, - { "234.567", "doscientos treinta y cuatro punto cinco seis siete" }, + { "234.567", "doscientos treinta y cuatro coma cinco seis siete" }, { NULL, NULL} }; @@ -1214,7 +1276,7 @@ IntlTestRBNF::TestFrenchSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getFrance(), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "1", "un" }, @@ -1224,25 +1286,25 @@ IntlTestRBNF::TestFrenchSpellout() { "23", "vingt-trois" }, { "62", "soixante-deux" }, { "70", "soixante-dix" }, - { "71", "soixante et onze" }, + { "71", "soixante-et-onze" }, { "73", "soixante-treize" }, { "80", "quatre-vingts" }, { "88", "quatre-vingt-huit" }, { "100", "cent" }, - { "106", "cent six" }, - { "127", "cent vingt-sept" }, - { "200", "deux cents" }, - { "579", "cinq cents soixante-dix-neuf" }, + { "106", "cent-six" }, + { "127", "cent-vingt-sept" }, + { "200", "deux-cents" }, + { "579", "cinq-cent-soixante-dix-neuf" }, { "1,000", "mille" }, - { "1,123", "onze cents vingt-trois" }, - { "1,594", "mille cinq cents quatre-vingt-quatorze" }, - { "2,000", "deux mille" }, - { "3,004", "trois mille quatre" }, - { "4,567", "quatre mille cinq cents soixante-sept" }, - { "15,943", "quinze mille neuf cents quarante-trois" }, - { "2,345,678", "deux million trois cents quarante-cinq mille six cents soixante-dix-huit" }, + { "1,123", "mille-cent-vingt-trois" }, + { "1,594", "mille-cinq-cent-quatre-vingt-quatorze" }, + { "2,000", "deux-mille" }, + { "3,004", "trois-mille-quatre" }, + { "4,567", "quatre-mille-cinq-cent-soixante-sept" }, + { "15,943", "quinze-mille-neuf-cent-quarante-trois" }, + { "2,345,678", "deux millions trois-cent-quarante-cinq-mille-six-cent-soixante-dix-huit" }, { "-36", "moins trente-six" }, - { "234.567", "deux cents trente-quatre virgule cinq six sept" }, + { "234.567", "deux-cent-trente-quatre virgule cinq six sept" }, { NULL, NULL} }; @@ -1251,8 +1313,8 @@ IntlTestRBNF::TestFrenchSpellout() #if !UCONFIG_NO_COLLATION formatter->setLenient(TRUE); static const char* lpTestData[][2] = { - { "trente-un", "31" }, - { "un cents quatre vingt dix huit", "198" }, + { "trente-et-un", "31" }, + { "un cent quatre vingt dix huit", "198" }, { NULL, NULL} }; doLenientParseTest(formatter, lpTestData); @@ -1274,20 +1336,20 @@ static const char* const swissFrenchTestData[][2] = { { "80", "huitante" }, { "88", "huitante-huit" }, { "100", "cent" }, - { "106", "cent six" }, - { "127", "cent vingt-sept" }, - { "200", "deux cents" }, - { "579", "cinq cents septante-neuf" }, + { "106", "cent-six" }, + { "127", "cent-vingt-sept" }, + { "200", "deux-cents" }, + { "579", "cinq-cent-septante-neuf" }, { "1,000", "mille" }, - { "1,123", "onze cents vingt-trois" }, - { "1,594", "mille cinq cents nonante-quatre" }, - { "2,000", "deux mille" }, - { "3,004", "trois mille quatre" }, - { "4,567", "quatre mille cinq cents soixante-sept" }, - { "15,943", "quinze mille neuf cents quarante-trois" }, - { "2,345,678", "deux million trois cents quarante-cinq mille six cents septante-huit" }, + { "1,123", "mille-cent-vingt-trois" }, + { "1,594", "mille-cinq-cent-nonante-quatre" }, + { "2,000", "deux-mille" }, + { "3,004", "trois-mille-quatre" }, + { "4,567", "quatre-mille-cinq-cent-soixante-sept" }, + { "15,943", "quinze-mille-neuf-cent-quarante-trois" }, + { "2,345,678", "deux millions trois-cent-quarante-cinq-mille-six-cent-septante-huit" }, { "-36", "moins trente-six" }, - { "234.567", "deux cents trente-quatre virgule cinq six sept" }, + { "234.567", "deux-cent-trente-quatre virgule cinq six sept" }, { NULL, NULL} }; @@ -1299,13 +1361,47 @@ IntlTestRBNF::TestSwissFrenchSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("fr", "CH", ""), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { doTest(formatter, swissFrenchTestData, TRUE); } delete formatter; } +static const char* const belgianFrenchTestData[][2] = { + { "1", "un" }, + { "15", "quinze" }, + { "20", "vingt" }, + { "21", "vingt-et-un" }, + { "23", "vingt-trois" }, + { "62", "soixante-deux" }, + { "70", "septante" }, + { "71", "septante-et-un" }, + { "73", "septante-trois" }, + { "80", "quatre-vingts" }, + { "88", "quatre-vingt-huit" }, + { "90", "nonante" }, + { "91", "nonante-et-un" }, + { "95", "nonante-cinq" }, + { "100", "cent" }, + { "106", "cent-six" }, + { "127", "cent-vingt-sept" }, + { "200", "deux-cents" }, + { "579", "cinq-cent-septante-neuf" }, + { "1,000", "mille" }, + { "1,123", "mille-cent-vingt-trois" }, + { "1,594", "mille-cinq-cent-nonante-quatre" }, + { "2,000", "deux-mille" }, + { "3,004", "trois-mille-quatre" }, + { "4,567", "quatre-mille-cinq-cent-soixante-sept" }, + { "15,943", "quinze-mille-neuf-cent-quarante-trois" }, + { "2,345,678", "deux millions trois-cent-quarante-cinq-mille-six-cent-septante-huit" }, + { "-36", "moins trente-six" }, + { "234.567", "deux-cent-trente-quatre virgule cinq six sept" }, + { NULL, NULL} +}; + + void IntlTestRBNF::TestBelgianFrenchSpellout() { @@ -1314,11 +1410,11 @@ IntlTestRBNF::TestBelgianFrenchSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("fr", "BE", ""), status); if (U_FAILURE(status)) { - errln("rbnf status: 0x%x (%s)\n", status, u_errorName(status)); - errln("FAIL: could not construct formatter"); + errcheckln(status, "rbnf status: 0x%x (%s)\n", status, u_errorName(status)); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { // Belgian french should match Swiss french. - doTest(formatter, swissFrenchTestData, TRUE); + doTest(formatter, belgianFrenchTestData, TRUE); } delete formatter; } @@ -1331,29 +1427,31 @@ IntlTestRBNF::TestItalianSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getItalian(), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "1", "uno" }, { "15", "quindici" }, { "20", "venti" }, - { "23", "ventitr\\u00E9" }, - { "73", "settantatr\\u00E9" }, - { "88", "ottantotto" }, + { "23", "venti\\u00ADtr\\u00E9" }, + { "73", "settanta\\u00ADtr\\u00E9" }, + { "88", "ottant\\u00ADotto" }, { "100", "cento" }, - { "106", "centosei" }, - { "108", "centotto" }, - { "127", "centoventisette" }, - { "181", "centottantuno" }, - { "200", "duecento" }, - { "579", "cinquecentosettantanove" }, + { "101", "cent\\u00ADuno" }, + { "103", "cento\\u00ADtr\\u00E9" }, + { "106", "cento\\u00ADsei" }, + { "108", "cent\\u00ADotto" }, + { "127", "cento\\u00ADventi\\u00ADsette" }, + { "181", "cent\\u00ADottant\\u00ADuno" }, + { "200", "due\\u00ADcento" }, + { "579", "cinque\\u00ADcento\\u00ADsettanta\\u00ADnove" }, { "1,000", "mille" }, - { "2,000", "duemila" }, - { "3,004", "tremilaquattro" }, - { "4,567", "quattromilacinquecentosessantasette" }, - { "15,943", "quindicimilanovecentoquarantatr\\u00E9" }, - { "-36", "meno trentasei" }, - { "234.567", "duecentotrentaquattro virgola cinque sei sette" }, + { "2,000", "due\\u00ADmila" }, + { "3,004", "tre\\u00ADmila\\u00ADquattro" }, + { "4,567", "quattro\\u00ADmila\\u00ADcinque\\u00ADcento\\u00ADsessanta\\u00ADsette" }, + { "15,943", "quindici\\u00ADmila\\u00ADnove\\u00ADcento\\u00ADquaranta\\u00ADtr\\u00E9" }, + { "-36", "meno trenta\\u00ADsei" }, + { "234.567", "due\\u00ADcento\\u00ADtrenta\\u00ADquattro virgola cinque sei sette" }, { NULL, NULL} }; @@ -1370,7 +1468,7 @@ IntlTestRBNF::TestPortugueseSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("pt","BR",""), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "1", "um" }, @@ -1389,10 +1487,10 @@ IntlTestRBNF::TestPortugueseSpellout() { "1,000", "mil" }, { "2,000", "dois mil" }, { "3,004", "tr\\u00EAs mil e quatro" }, - { "4,567", "quatro mil quinhentos e sessenta e sete" }, - { "15,943", "quinze mil novecentos e quarenta e tr\\u00EAs" }, + { "4,567", "quatro mil e quinhentos e sessenta e sete" }, + { "15,943", "quinze mil e novecentos e quarenta e tr\\u00EAs" }, { "-36", "menos trinta e seis" }, - { "234.567", "duzcentos e trinta e quatro ponto cinco seis sete" }, + { "234.567", "duzcentos e trinta e quatro v\\u00EDrgula cinco seis sete" }, { NULL, NULL} }; @@ -1408,26 +1506,26 @@ IntlTestRBNF::TestGermanSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale::getGermany(), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "1", "eins" }, { "15", "f\\u00fcnfzehn" }, { "20", "zwanzig" }, - { "23", "dreiundzwanzig" }, - { "73", "dreiundsiebzig" }, - { "88", "achtundachtzig" }, - { "100", "hundert" }, - { "106", "hundertsechs" }, - { "127", "hundertsiebenundzwanzig" }, - { "200", "zweihundert" }, - { "579", "f\\u00fcnfhundertneunundsiebzig" }, - { "1,000", "tausend" }, - { "2,000", "zweitausend" }, - { "3,004", "dreitausendvier" }, - { "4,567", "viertausendf\\u00fcnfhundertsiebenundsechzig" }, - { "15,943", "f\\u00fcnfzehntausendneunhundertdreiundvierzig" }, - { "2,345,678", "zwei Millionen dreihundertf\\u00fcnfundvierzigtausendsechshundertachtundsiebzig" }, + { "23", "drei\\u00ADund\\u00ADzwanzig" }, + { "73", "drei\\u00ADund\\u00ADsiebzig" }, + { "88", "acht\\u00ADund\\u00ADachtzig" }, + { "100", "ein\\u00ADhundert" }, + { "106", "ein\\u00ADhundert\\u00ADsechs" }, + { "127", "ein\\u00ADhundert\\u00ADsieben\\u00ADund\\u00ADzwanzig" }, + { "200", "zwei\\u00ADhundert" }, + { "579", "f\\u00fcnf\\u00ADhundert\\u00ADneun\\u00ADund\\u00ADsiebzig" }, + { "1,000", "ein\\u00ADtausend" }, + { "2,000", "zwei\\u00ADtausend" }, + { "3,004", "drei\\u00ADtausend\\u00ADvier" }, + { "4,567", "vier\\u00ADtausend\\u00ADf\\u00fcnf\\u00ADhundert\\u00ADsieben\\u00ADund\\u00ADsechzig" }, + { "15,943", "f\\u00fcnfzehn\\u00ADtausend\\u00ADneun\\u00ADhundert\\u00ADdrei\\u00ADund\\u00ADvierzig" }, + { "2,345,678", "zwei Millionen drei\\u00ADhundert\\u00ADf\\u00fcnf\\u00ADund\\u00ADvierzig\\u00ADtausend\\u00ADsechs\\u00ADhundert\\u00ADacht\\u00ADund\\u00ADsiebzig" }, { NULL, NULL} }; @@ -1453,16 +1551,16 @@ IntlTestRBNF::TestThaiSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("th"), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testData[][2] = { { "0", "\\u0e28\\u0e39\\u0e19\\u0e22\\u0e4c" }, { "1", "\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07" }, { "10", "\\u0e2a\\u0e34\\u0e1a" }, - { "11", "\\u0e2a\\u0e34\\u0e1a\\u0e40\\u0e2d\\u0e47\\u0e14" }, - { "21", "\\u0e22\\u0e35\\u0e48\\u0e2a\\u0e34\\u0e1a\\u0e40\\u0e2d\\u0e47\\u0e14" }, - { "101", "\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07\\u0e23\\u0e49\\u0e2d\\u0e22\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07" }, - { "1.234", "\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07\\u0e08\\u0e38\\u0e14\\u0e2a\\u0e2d\\u0e07\\u0e2a\\u0e32\\u0e21\\u0e2a\\u0e35\\u0e48" }, + { "11", "\\u0e2a\\u0e34\\u0e1a\\u200b\\u0e40\\u0e2d\\u0e47\\u0e14" }, + { "21", "\\u0e22\\u0e35\\u0e48\\u200b\\u0e2a\\u0e34\\u0e1a\\u200b\\u0e40\\u0e2d\\u0e47\\u0e14" }, + { "101", "\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07\\u200b\\u0e23\\u0e49\\u0e2d\\u0e22\\u200b\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07" }, + { "1.234", "\\u0e2b\\u0e19\\u0e36\\u0e48\\u0e07\\u200b\\u0e08\\u0e38\\u0e14\\u200b\\u0e2a\\u0e2d\\u0e07\\u0e2a\\u0e32\\u0e21\\u0e2a\\u0e35\\u0e48" }, { NULL, NULL} }; @@ -1479,63 +1577,63 @@ IntlTestRBNF::TestSwedishSpellout() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("sv"), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* testDataDefault[][2] = { - { "101", "etthundra\\u00aden" }, - { "123", "etthundra\\u00adtjugotre" }, - { "1,001", "ettusen en" }, - { "1,100", "ettusen etthundra" }, - { "1,101", "ettusen etthundra\\u00aden" }, - { "1,234", "ettusen tv\\u00e5hundra\\u00adtrettiofyra" }, - { "10,001", "tio\\u00adtusen en" }, + { "101", "ett\\u00adhundra\\u00adett" }, + { "123", "ett\\u00adhundra\\u00adtjugo\\u00adtre" }, + { "1,001", "et\\u00adtusen ett" }, + { "1,100", "et\\u00adtusen ett\\u00adhundra" }, + { "1,101", "et\\u00adtusen ett\\u00adhundra\\u00adett" }, + { "1,234", "et\\u00adtusen tv\\u00e5\\u00adhundra\\u00adtrettio\\u00adfyra" }, + { "10,001", "tio\\u00adtusen ett" }, { "11,000", "elva\\u00adtusen" }, { "12,000", "tolv\\u00adtusen" }, { "20,000", "tjugo\\u00adtusen" }, - { "21,000", "tjugoen\\u00adtusen" }, - { "21,001", "tjugoen\\u00adtusen en" }, - { "200,000", "tv\\u00e5hundra\\u00adtusen" }, - { "201,000", "tv\\u00e5hundra\\u00aden\\u00adtusen" }, - { "200,200", "tv\\u00e5hundra\\u00adtusen tv\\u00e5hundra" }, + { "21,000", "tjugo\\u00adet\\u00adtusen" }, + { "21,001", "tjugo\\u00adet\\u00adtusen ett" }, + { "200,000", "tv\\u00e5\\u00adhundra\\u00adtusen" }, + { "201,000", "tv\\u00e5\\u00adhundra\\u00adet\\u00adtusen" }, + { "200,200", "tv\\u00e5\\u00adhundra\\u00adtusen tv\\u00e5\\u00adhundra" }, { "2,002,000", "tv\\u00e5 miljoner tv\\u00e5\\u00adtusen" }, - { "12,345,678", "tolv miljoner trehundra\\u00adfyrtiofem\\u00adtusen sexhundra\\u00adsjuttio\\u00e5tta" }, - { "123,456.789", "etthundra\\u00adtjugotre\\u00adtusen fyrahundra\\u00adfemtiosex komma sju \\u00e5tta nio" }, - { "-12,345.678", "minus tolv\\u00adtusen trehundra\\u00adfyrtiofem komma sex sju \\u00e5tta" }, + { "12,345,678", "tolv miljoner tre\\u00adhundra\\u00adfyrtio\\u00adfem\\u00adtusen sex\\u00adhundra\\u00adsjuttio\\u00ad\\u00e5tta" }, + { "123,456.789", "ett\\u00adhundra\\u00adtjugo\\u00adtre\\u00adtusen fyra\\u00adhundra\\u00adfemtio\\u00adsex komma sju \\u00e5tta nio" }, + { "-12,345.678", "minus tolv\\u00adtusen tre\\u00adhundra\\u00adfyrtio\\u00adfem komma sex sju \\u00e5tta" }, { NULL, NULL } }; doTest(formatter, testDataDefault, TRUE); - static const char* testDataNeutrum[][2] = { - { "101", "etthundra\\u00adett" }, - { "1,001", "ettusen ett" }, - { "1,101", "ettusen etthundra\\u00adett" }, - { "10,001", "tio\\u00adtusen ett" }, - { "21,001", "tjugoen\\u00adtusen ett" }, - { NULL, NULL } - }; - - formatter->setDefaultRuleSet("%neutrum", status); - if (U_SUCCESS(status)) { - logln("testing neutrum rules"); - doTest(formatter, testDataNeutrum, TRUE); - } - else { - errln("Can't test neutrum rules"); - } + static const char* testDataNeutrum[][2] = { + { "101", "ett\\u00adhundra\\u00aden" }, + { "1,001", "ettusen en" }, + { "1,101", "ettusen ett\\u00adhundra\\u00aden" }, + { "10,001", "tio\\u00adtusen en" }, + { "21,001", "tjugo\\u00aden\\u00adtusen en" }, + { NULL, NULL } + }; + + formatter->setDefaultRuleSet("%spellout-cardinal-neutre", status); + if (U_SUCCESS(status)) { + logln(" testing spellout-cardinal-neutre rules"); + doTest(formatter, testDataNeutrum, TRUE); + } + else { + errln("Can't test spellout-cardinal-neutre rules"); + } static const char* testDataYear[][2] = { - { "101", "etthundra\\u00adett" }, - { "900", "niohundra" }, - { "1,001", "tiohundra\\u00adett" }, - { "1,100", "elvahundra" }, - { "1,101", "elvahundra\\u00adett" }, - { "1,234", "tolvhundra\\u00adtrettiofyra" }, - { "2,001", "tjugohundra\\u00adett" }, + { "101", "ett\\u00adhundra\\u00adett" }, + { "900", "nio\\u00adhundra" }, + { "1,001", "et\\u00adtusen ett" }, + { "1,100", "elva\\u00adhundra" }, + { "1,101", "elva\\u00adhundra\\u00adett" }, + { "1,234", "tolv\\u00adhundra\\u00adtrettio\\u00adfyra" }, + { "2,001", "tjugo\\u00adhundra\\u00adett" }, { "10,001", "tio\\u00adtusen ett" }, { NULL, NULL } }; - formatter->setDefaultRuleSet("%year", status); + formatter->setDefaultRuleSet("%spellout-numbering-year", status); if (U_SUCCESS(status)) { logln("testing year rules"); doTest(formatter, testDataYear, TRUE); @@ -1556,7 +1654,7 @@ IntlTestRBNF::TestSmallValues() = new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("en_US"), status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { static const char* const testDataDefault[][2] = { { "0.001", "zero point zero zero one" }, @@ -1583,11 +1681,11 @@ IntlTestRBNF::TestSmallValues() // { "1,234,567,890.0987654", "one billion, two hundred and thirty-four million, five hundred and sixty-seven thousand, eight hundred and ninety point zero nine eight seven six five four" }, // { "123,456,789.9876543", "one hundred and twenty-three million, four hundred and fifty-six thousand, seven hundred and eighty-nine point nine eight seven six five four three" }, // { "12,345,678.87654321", "twelve million, three hundred and forty-five thousand, six hundred and seventy-eight point eight seven six five four three two one" }, - { "1,234,567.7654321", "one million, two hundred and thirty-four thousand, five hundred and sixty-seven point seven six five four three two one" }, - { "123,456.654321", "one hundred and twenty-three thousand, four hundred and fifty-six point six five four three two one" }, - { "12,345.54321", "twelve thousand three hundred and forty-five point five four three two one" }, - { "1,234.4321", "one thousand two hundred and thirty-four point four three two one" }, - { "123.321", "one hundred and twenty-three point three two one" }, + { "1,234,567.7654321", "one million two hundred thirty-four thousand five hundred sixty-seven point seven six five four three two one" }, + { "123,456.654321", "one hundred twenty-three thousand four hundred fifty-six point six five four three two one" }, + { "12,345.54321", "twelve thousand three hundred forty-five point five four three two one" }, + { "1,234.4321", "one thousand two hundred thirty-four point four three two one" }, + { "123.321", "one hundred twenty-three point three two one" }, { "0.0000000011754944", "zero point zero zero zero zero zero zero zero zero one one seven five four nine four four" }, { "0.000001175494351", "zero point zero zero zero zero zero one one seven five four nine four three five one" }, { NULL, NULL } @@ -1610,7 +1708,7 @@ IntlTestRBNF::TestLocalizations(void) UParseError perror; RuleBasedNumberFormat formatter(rules, perror, status); if (U_FAILURE(status)) { - errln("FAIL: could not construct formatter"); + errcheckln(status, "FAIL: could not construct formatter - %s", u_errorName(status)); } else { { static const char* const testData[][2] = { @@ -1739,32 +1837,89 @@ IntlTestRBNF::TestLocalizations(void) void IntlTestRBNF::TestAllLocales() { - const char* names[] = { - " (spellout) ", - " (ordinal) ", - " (duration) " - }; - int32_t count = 0; - const Locale* locales = Locale::getAvailableLocales(count); - for (int i = 0; i < count; ++i) { - const Locale* loc = &locales[i]; - for (int j = 0; j < 3; ++j) { - UErrorCode status = U_ZERO_ERROR; - RuleBasedNumberFormat* f = new RuleBasedNumberFormat((URBNFRuleSetTag)j, *loc, status); - if (U_SUCCESS(status)) { - double n = 45.678; - UnicodeString str; - f->format(n, str); - delete f; - - logln(UnicodeString(loc->getName()) + UnicodeString(names[j]) - + UnicodeString("success: 45.678 -> ") + str); - } else { - errln(UnicodeString(loc->getName()) + UnicodeString(names[j]) - + UnicodeString("ERROR could not instantiate -> ") + UnicodeString(u_errorName(status))); - } + const char* names[] = { + " (spellout) ", + " (ordinal) ", + " (duration) " + }; + double numbers[] = {45.678, 1, 2, 10, 11, 100, 110, 200, 1000, 1111, -1111}; + + // RBNF parse is extremely slow when lenient option is enabled. + // For non-exhaustive mode, we only test a few locales. + const char* parseLocales[] = {"en_US", "nl_NL", "be", NULL}; + + + int32_t count = 0; + const Locale* locales = Locale::getAvailableLocales(count); + for (int i = 0; i < count; ++i) { + const Locale* loc = &locales[i]; + UBool testParse = TRUE; + if (quick) { + testParse = FALSE; + for (int k = 0; parseLocales[k] != NULL; k++) { + if (strcmp(loc->getLanguage(), parseLocales[k]) == 0) { + testParse = TRUE; + break; + } + } + } + + for (int j = 0; j < 3; ++j) { + UErrorCode status = U_ZERO_ERROR; + RuleBasedNumberFormat* f = new RuleBasedNumberFormat((URBNFRuleSetTag)j, *loc, status); + if (U_FAILURE(status)) { + errln(UnicodeString(loc->getName()) + names[j] + + "ERROR could not instantiate -> " + u_errorName(status)); + continue; + } +#if !UCONFIG_NO_COLLATION + for (unsigned int numidx = 0; numidx < sizeof(numbers)/sizeof(double); numidx++) { + double n = numbers[numidx]; + UnicodeString str; + f->format(n, str); + + logln(UnicodeString(loc->getName()) + names[j] + + "success: " + n + " -> " + str); + + if (testParse) { + // We do not validate the result in this test case, + // because there are cases which do not round trip by design. + Formattable num; + + // regular parse + status = U_ZERO_ERROR; + f->setLenient(FALSE); + f->parse(str, num, status); + if (U_FAILURE(status)) { + //TODO: We need to fix parse problems - see #6895 / #6896 + if (status == U_INVALID_FORMAT_ERROR) { + logln(UnicodeString(loc->getName()) + names[j] + + "WARNING could not parse '" + str + "' -> " + u_errorName(status)); + } else { + errln(UnicodeString(loc->getName()) + names[j] + + "ERROR could not parse '" + str + "' -> " + u_errorName(status)); + } + } + // lenient parse + status = U_ZERO_ERROR; + f->setLenient(TRUE); + f->parse(str, num, status); + if (U_FAILURE(status)) { + //TODO: We need to fix parse problems - see #6895 / #6896 + if (status == U_INVALID_FORMAT_ERROR) { + logln(UnicodeString(loc->getName()) + names[j] + + "WARNING could not parse(lenient) '" + str + "' -> " + u_errorName(status)); + } else { + errln(UnicodeString(loc->getName()) + names[j] + + "ERROR could not parse(lenient) '" + str + "' -> " + u_errorName(status)); + } + } + } + } +#endif + delete f; + } } - } } void @@ -1802,7 +1957,7 @@ IntlTestRBNF::doTest(RuleBasedNumberFormat* formatter, const char* const testDat // NumberFormat* decFmt = NumberFormat::createInstance(Locale::getUS(), status); DecimalFormat decFmt("#,###.################", dfs, status); if (U_FAILURE(status)) { - errln("FAIL: could not create NumberFormat"); + errcheckln(status, "FAIL: could not create NumberFormat - %s", u_errorName(status)); } else { for (int i = 0; testData[i][0]; ++i) { const char* numString = testData[i][0]; @@ -1872,7 +2027,7 @@ IntlTestRBNF::doLenientParseTest(RuleBasedNumberFormat* formatter, const char* t UErrorCode status = U_ZERO_ERROR; NumberFormat* decFmt = NumberFormat::createInstance(Locale::getUS(), status); if (U_FAILURE(status)) { - errln("FAIL: could not create NumberFormat"); + errcheckln(status, "FAIL: could not create NumberFormat - %s", u_errorName(status)); } else { for (int i = 0; testData[i][0]; ++i) { const char* spelledNumber = testData[i][0]; // spelled-out number