ICU-1981 synch up ICU4J and ICU4C test of swedish collation
X-SVN-Rev: 9118
This commit is contained in:
parent
27da46cea7
commit
608e614f95
@ -376,6 +376,42 @@ RuleBasedNumberFormat::setLenient(UBool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RuleBasedNumberFormat::setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status) {
|
||||
if (U_SUCCESS(status)) {
|
||||
if (ruleSetName.isEmpty()) {
|
||||
initDefaultRuleSet();
|
||||
} else if (ruleSetName.startsWith("%%")) {
|
||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
} else {
|
||||
NFRuleSet* result = findRuleSet(ruleSetName, status);
|
||||
if (result != NULL) {
|
||||
defaultRuleSet = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RuleBasedNumberFormat::initDefaultRuleSet()
|
||||
{
|
||||
NFRuleSet**p = &ruleSets[1];
|
||||
while (*p) {
|
||||
++p;
|
||||
}
|
||||
|
||||
defaultRuleSet = *--p;
|
||||
if (!defaultRuleSet->isPublic()) {
|
||||
while (p != ruleSets) {
|
||||
if ((*--p)->isPublic()) {
|
||||
defaultRuleSet = *p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErrorCode& status)
|
||||
{
|
||||
@ -498,18 +534,7 @@ RuleBasedNumberFormat::init(const UnicodeString& rules, UParseError& pErr, UErro
|
||||
// rather than the first so that a user can create a new formatter
|
||||
// from an existing formatter and change its default behavior just
|
||||
// by appending more rule sets to the end)
|
||||
// setDefaultRuleSet
|
||||
{
|
||||
defaultRuleSet = ruleSets[numRuleSets - 1];
|
||||
if (!defaultRuleSet->isPublic()) {
|
||||
for (int i = numRuleSets - 2; i >= 0; --i) {
|
||||
if (ruleSets[i]->isPublic()) {
|
||||
defaultRuleSet = ruleSets[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
initDefaultRuleSet();
|
||||
|
||||
// finally, we can go back through the temporary descriptions
|
||||
// list and finish seting up the substructure (and we throw
|
||||
|
@ -797,11 +797,19 @@ public:
|
||||
*/
|
||||
virtual inline UBool isLenient(void) const;
|
||||
|
||||
/**
|
||||
* Override the default rule set to use. If ruleSetName is null, reset
|
||||
* to the initial default rule set. If the rule set is not a public rule set name,
|
||||
* U_ILLEGAL_ARGUMENT_ERROR is returned in status.
|
||||
* @param ruleSetName the name of the rule set, or null to reset the initial default.
|
||||
*/
|
||||
virtual void setDefaultRuleSet(const UnicodeString& ruleSetName, UErrorCode& status);
|
||||
|
||||
private:
|
||||
void init(const UnicodeString& rules, UParseError& perror, UErrorCode& status);
|
||||
void dispose();
|
||||
void stripWhitespace(UnicodeString& src);
|
||||
void setDefaultRuleSet();
|
||||
void initDefaultRuleSet();
|
||||
void format(double number, NFRuleSet& ruleSet);
|
||||
NFRuleSet* findRuleSet(const UnicodeString& name, UErrorCode& status) const;
|
||||
|
||||
|
@ -49,7 +49,7 @@ void IntlTestRBNF::runIndexedTest(int32_t index, UBool exec, const char* &name,
|
||||
TESTCASE(8, TestThaiSpellout);
|
||||
TESTCASE(9, TestAPI);
|
||||
TESTCASE(10, TestFractionalRuleSet);
|
||||
// TESTCASE(11, TestLLong);
|
||||
TESTCASE(11, TestSwedishSpellout);
|
||||
#else
|
||||
TESTCASE(0, TestRBNFDisabled);
|
||||
#endif
|
||||
@ -1272,6 +1272,77 @@ IntlTestRBNF::TestThaiSpellout()
|
||||
delete formatter;
|
||||
}
|
||||
|
||||
void
|
||||
IntlTestRBNF::TestSwedishSpellout()
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
RuleBasedNumberFormat* formatter
|
||||
= new RuleBasedNumberFormat(URBNF_SPELLOUT, Locale("sv"), status);
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
errln("FAIL: could not construct formatter");
|
||||
} 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" },
|
||||
{ "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" },
|
||||
{ "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" },
|
||||
{ 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);
|
||||
}
|
||||
|
||||
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" },
|
||||
{ "10,001", "tio\\u00adtusen ett" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
formatter->setDefaultRuleSet("%year", status);
|
||||
if (U_SUCCESS(status)) {
|
||||
logln("testing year rules");
|
||||
doTest(formatter, testDataYear, TRUE);
|
||||
}
|
||||
}
|
||||
delete formatter;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
IntlTestRBNF::doTest(RuleBasedNumberFormat* formatter, const char* testData[][2], UBool testParsing)
|
||||
{
|
||||
|
@ -85,6 +85,11 @@ class IntlTestRBNF : public IntlTest {
|
||||
*/
|
||||
virtual void TestThaiSpellout();
|
||||
|
||||
/**
|
||||
* Perform a simple spot check on the Swedish spellout rules
|
||||
*/
|
||||
virtual void TestSwedishSpellout();
|
||||
|
||||
protected:
|
||||
virtual void doTest(RuleBasedNumberFormat* formatter, const char* testData[][2], UBool testParsing);
|
||||
virtual void doLenientParseTest(RuleBasedNumberFormat* formatter, const char* testData[][2]);
|
||||
|
Loading…
Reference in New Issue
Block a user