| OLD | NEW |
| 1 /******************************************************************** | 1 /******************************************************************** |
| 2 * COPYRIGHT: | 2 * COPYRIGHT: |
| 3 * Copyright (c) 1997-2014, International Business Machines Corporation and | 3 * Copyright (c) 1997-2015, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ******************************************************************** | 5 ******************************************************************** |
| 6 * File TMSGFMT.CPP | 6 * File TMSGFMT.CPP |
| 7 * | 7 * |
| 8 * Modification History: | 8 * Modification History: |
| 9 * | 9 * |
| 10 * Date Name Description | 10 * Date Name Description |
| 11 * 03/24/97 helena Converted from Java. | 11 * 03/24/97 helena Converted from Java. |
| 12 * 07/11/97 helena Updated to work on AIX. | 12 * 07/11/97 helena Updated to work on AIX. |
| 13 * 08/04/97 jfitz Updated to intltest | 13 * 08/04/97 jfitz Updated to intltest |
| (...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1518 // decimal values do not format completely for ordinal or duration, and | 1518 // decimal values do not format completely for ordinal or duration, and |
| 1519 // do not always parse, so do not include them | 1519 // do not always parse, so do not include them |
| 1520 "0", "1", "12", "100", "123", "1001", "123,456", "-17", | 1520 "0", "1", "12", "100", "123", "1001", "123,456", "-17", |
| 1521 }; | 1521 }; |
| 1522 int32_t values_count = sizeof(values)/sizeof(values[0]); | 1522 int32_t values_count = sizeof(values)/sizeof(values[0]); |
| 1523 | 1523 |
| 1524 UnicodeString formats[] = { | 1524 UnicodeString formats[] = { |
| 1525 "There are {0,spellout} files to search.", | 1525 "There are {0,spellout} files to search.", |
| 1526 "There are {0,spellout,%simplified} files to search.", | 1526 "There are {0,spellout,%simplified} files to search.", |
| 1527 "The bogus spellout {0,spellout,%BOGUS} files behaves like the default."
, | 1527 "The bogus spellout {0,spellout,%BOGUS} files behaves like the default."
, |
| 1528 "This is the {0,ordinal} file to search.", // TODO fix bug, ordinal does
not parse | 1528 "This is the {0,ordinal} file to search.", |
| 1529 "Searching this file will take {0,duration} to complete.", | 1529 "Searching this file will take {0,duration} to complete.", |
| 1530 "Searching this file will take {0,duration,%with-words} to complete.", | 1530 "Searching this file will take {0,duration,%with-words} to complete.", |
| 1531 }; | 1531 }; |
| 1532 int32_t formats_count = sizeof(formats)/sizeof(formats[0]); | 1532 int32_t formats_count = sizeof(formats)/sizeof(formats[0]); |
| 1533 | 1533 |
| 1534 Formattable args[1]; | 1534 Formattable args[1]; |
| 1535 | 1535 |
| 1536 NumberFormat* numFmt = NumberFormat::createInstance(locale, ec); | 1536 NumberFormat* numFmt = NumberFormat::createInstance(locale, ec); |
| 1537 if (U_FAILURE(ec)) { | 1537 if (U_FAILURE(ec)) { |
| 1538 dataerrln("Error calling NumberFormat::createInstance()"); | 1538 dataerrln("Error calling NumberFormat::createInstance()"); |
| 1539 return; | 1539 return; |
| 1540 } | 1540 } |
| 1541 | 1541 |
| 1542 for (int i = 0; i < formats_count; ++i) { | 1542 for (int i = 0; i < formats_count; ++i) { |
| 1543 MessageFormat* fmt = new MessageFormat(formats[i], locale, ec); | 1543 MessageFormat* fmt = new MessageFormat(formats[i], locale, ec); |
| 1544 logln((UnicodeString)"Testing format pattern: '" + formats[i] + "'"); | 1544 logln((UnicodeString)"Testing format pattern: '" + formats[i] + "'"); |
| 1545 | 1545 |
| 1546 for (int j = 0; j < values_count; ++j) { | 1546 for (int j = 0; j < values_count; ++j) { |
| 1547 ec = U_ZERO_ERROR; | 1547 ec = U_ZERO_ERROR; |
| 1548 numFmt->parse(values[j], args[0], ec); | 1548 numFmt->parse(values[j], args[0], ec); |
| 1549 if (U_FAILURE(ec)) { | 1549 if (U_FAILURE(ec)) { |
| 1550 errln((UnicodeString)"Failed to parse test argument " + values[j
]); | 1550 errln((UnicodeString)"Failed to parse test argument " + values[j
]); |
| 1551 } else { | 1551 } else { |
| 1552 FieldPosition fp(0); | 1552 FieldPosition fp(0); |
| 1553 UnicodeString result; | 1553 UnicodeString result; |
| 1554 fmt->format(args, 1, result, fp, ec); | 1554 fmt->format(args, 1, result, fp, ec); |
| 1555 logln((UnicodeString)"value: " + toString(args[0]) + " --> " + r
esult + UnicodeString(" ec: ") + u_errorName(ec)); | 1555 logln((UnicodeString)"value: " + toString(args[0]) + " --> " + r
esult + UnicodeString(" ec: ") + u_errorName(ec)); |
| 1556 | 1556 |
| 1557 if (i != 3) { // TODO: fix this, for now skip ordinal parsing (f
ormat string at index 3) | 1557 int32_t count = 0; |
| 1558 int32_t count = 0; | 1558 Formattable* parseResult = fmt->parse(result, count, ec); |
| 1559 Formattable* parseResult = fmt->parse(result, count, ec); | 1559 if (count != 1) { |
| 1560 if (count != 1) { | 1560 errln((UnicodeString)"parse returned " + count + " args"); |
| 1561 errln((UnicodeString)"parse returned " + count + " args"
); | 1561 } else if (parseResult[0] != args[0]) { |
| 1562 } else if (parseResult[0] != args[0]) { | 1562 errln((UnicodeString)"parsed argument " + toString(parseResu
lt[0]) + " != " + toString(args[0])); |
| 1563 errln((UnicodeString)"parsed argument " + toString(parse
Result[0]) + " != " + toString(args[0])); | |
| 1564 } | |
| 1565 delete []parseResult; | |
| 1566 } | 1563 } |
| 1564 delete []parseResult; |
| 1567 } | 1565 } |
| 1568 } | 1566 } |
| 1569 delete fmt; | 1567 delete fmt; |
| 1570 } | 1568 } |
| 1571 delete numFmt; | 1569 delete numFmt; |
| 1572 } | 1570 } |
| 1573 | 1571 |
| 1574 UnicodeString TestMessageFormat::GetPatternAndSkipSyntax(const MessagePattern& p
attern) { | 1572 UnicodeString TestMessageFormat::GetPatternAndSkipSyntax(const MessagePattern& p
attern) { |
| 1575 UnicodeString us(pattern.getPatternString()); | 1573 UnicodeString us(pattern.getPatternString()); |
| 1576 int count = pattern.countParts(); | 1574 int count = pattern.countParts(); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1957 m2.format(args, 1, result, ignore, errorCode), TRUE); | 1955 m2.format(args, 1, result, ignore, errorCode), TRUE); |
| 1958 | 1956 |
| 1959 args[0] = (double)2.5; | 1957 args[0] = (double)2.5; |
| 1960 result.remove(); | 1958 result.remove(); |
| 1961 assertEquals("offset-decimals format(1)", "2.5 meters", | 1959 assertEquals("offset-decimals format(1)", "2.5 meters", |
| 1962 m2.format(args, 1, result, ignore, errorCode), TRUE); | 1960 m2.format(args, 1, result, ignore, errorCode), TRUE); |
| 1963 errorCode.reset(); | 1961 errorCode.reset(); |
| 1964 } | 1962 } |
| 1965 | 1963 |
| 1966 #endif /* #if !UCONFIG_NO_FORMATTING */ | 1964 #endif /* #if !UCONFIG_NO_FORMATTING */ |
| OLD | NEW |