ICU-10625 address data checks in DateFormatTest::TestDateFormatLeniency not checking expected results

X-SVN-Rev: 35340
This commit is contained in:
Scott Russell 2014-03-05 00:52:30 +00:00
parent 10c83d606d
commit 8791b26095
2 changed files with 41 additions and 12 deletions

View file

@ -2230,7 +2230,7 @@ UBool SimpleDateFormat::matchLiterals(const UnicodeString &pattern,
if (t >= text.length() || literal.charAt(p) != text.charAt(t)) {
// Ran out of text, or found a non-matching character:
// OK in lenient mode, an error in strict mode.
if (partialMatchLenient) {
if (whitespaceLenient) {
if (t == textOffset && text.charAt(t) == 0x2e &&
isAfterNonNumericField(pattern, patternOffset)) {
// Lenient mode and the literal input text begins with a "." and
@ -2238,9 +2238,16 @@ UBool SimpleDateFormat::matchLiterals(const UnicodeString &pattern,
++t;
continue; // Do not update p.
}
// if it is actual whitespace and we're whitespace lenient it's OK
UChar wsc = text.charAt(t);
if(PatternProps::isWhiteSpace(wsc))
break;
}
// or if we're partial match lenient it's OK
if(partialMatchLenient) {
break;
}
return FALSE;
}
++p;

View file

@ -4212,9 +4212,9 @@ void DateFormatTest::TestDateFormatLeniency() {
//locale leniency parse String pattern expected result
{ "en", true, UnicodeString("2008-07 02"), UnicodeString("yyyy-LLLL dd"), UnicodeString("2008-July 02") },
{ "en", false, UnicodeString("2008-07 02"), UnicodeString("yyyy-LLLL dd"), UnicodeString("") },
{ "en", true, UnicodeString("2008-Jan 02"), UnicodeString("yyyy-LLL. dd"), UnicodeString("2008-Jan 02") },
{ "en", true, UnicodeString("2008-Jan 02"), UnicodeString("yyyy-LLL. dd"), UnicodeString("2008-Jan. 02") },
{ "en", false, UnicodeString("2008-Jan 02"), UnicodeString("yyyy-LLL. dd"), UnicodeString("") },
{ "en", true, UnicodeString("2008-Jan--02"), UnicodeString("yyyy-MMM' -- 'dd"), UnicodeString("2008-Jan 02") },
{ "en", true, UnicodeString("2008-Jan--02"), UnicodeString("yyyy-MMM' -- 'dd"), UnicodeString("2008-Jan -- 02") },
{ "en", false, UnicodeString("2008-Jan--02"), UnicodeString("yyyy-MMM' -- 'dd"), UnicodeString("") },
// terminator
{ NULL, true, UnicodeString(""), UnicodeString(""), UnicodeString("") }
@ -4240,17 +4240,39 @@ void DateFormatTest::TestDateFormatLeniency() {
}
sdmft->setLenient(itemPtr->leniency);
sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->leniency, status).
setBooleanAttribute(UDAT_PARSE_PARTIAL_MATCH, itemPtr->leniency, status).
setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->leniency, status);
UDate d = sdmft->parse(itemPtr->parseString, pos);
(void)d;
UDate d = sdmft->parse(itemPtr->parseString, pos);
// TODO: Ticket 10625. Nothing here is checking the expected result when the parse succeeds.
if ((pos.getErrorIndex() > -1) && (itemPtr->expectedResult.length() != 0)) {
errln("error: unexpected error - " + itemPtr->parseString +
" - error index " + pos.getErrorIndex() +
" - leniency " + itemPtr->leniency);
if(itemPtr->expectedResult.length() == 0) {
if(pos.getErrorIndex() != -1) {
continue;
} else {
errln("error: unexpected parse success - " + itemPtr->parseString +
" - pattern " + itemPtr->pattern +
" - error index " + pos.getErrorIndex() +
" - leniency " + itemPtr->leniency);
continue;
}
}
if(pos.getErrorIndex() != -1) {
errln("error: parse error for string - " + itemPtr->parseString +
" - pattern " + itemPtr->pattern +
" - idx " + pos.getIndex() +
" - error index "+pos.getErrorIndex() +
" - leniency " + itemPtr->leniency);
continue;
}
UnicodeString formatResult("");
sdmft->format(d, formatResult);
if(formatResult.compare(itemPtr->expectedResult) != 0) {
errln("error: unexpected format result. pattern["+itemPtr->pattern+"] expected[" + itemPtr->expectedResult + "] but result was[" + formatResult + "]");
continue;
} else {
logln("formatted results match! - " + formatResult);
}
}
}