]> granicus.if.org Git - icu/commitdiff
ICU-10625 address data checks in DateFormatTest::TestDateFormatLeniency not checking...
authorScott Russell <DTownSMR@gmail.com>
Wed, 5 Mar 2014 00:52:30 +0000 (00:52 +0000)
committerScott Russell <DTownSMR@gmail.com>
Wed, 5 Mar 2014 00:52:30 +0000 (00:52 +0000)
X-SVN-Rev: 35340

icu4c/source/i18n/smpdtfmt.cpp
icu4c/source/test/intltest/dtfmttst.cpp

index 62c7d22131ee964eccfe80690c50ad31cfa089fd..5ebb8d5b171bb4aca7a4437c067fa2e56d00a0d2 100644 (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;
index 9c9cd5bc859832bc2c30e4223156c9e22491ef91..f6dae50268c405c8b6f089018089de115679a2cf 100644 (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);  
+           } 
+
     }
 }