ICU-513 Test for surrogate support
X-SVN-Rev: 5842
This commit is contained in:
parent
cc1505c0ed
commit
7353ac4a23
@ -780,7 +780,7 @@ DecimalFormat::subformat(UnicodeString& result,
|
||||
fieldPosition.setBeginIndex(result.length());
|
||||
}
|
||||
// Restores the digit character or pads the buffer with zeros.
|
||||
UChar c = (UChar)((i < digits.fCount) ?
|
||||
UChar32 c = (UChar32)((i < digits.fCount) ?
|
||||
(digits.fDigits[i] + zeroDelta) :
|
||||
zero);
|
||||
result += c;
|
||||
@ -823,7 +823,7 @@ DecimalFormat::subformat(UnicodeString& result,
|
||||
result += (zero);
|
||||
for (i=0; i<expDigits.fDecimalAt; ++i)
|
||||
{
|
||||
UChar c = (UChar)((i < expDigits.fCount) ?
|
||||
UChar32 c = (UChar32)((i < expDigits.fCount) ?
|
||||
(expDigits.fDigits[i] + zeroDelta) : zero);
|
||||
result += c;
|
||||
}
|
||||
@ -862,7 +862,7 @@ DecimalFormat::subformat(UnicodeString& result,
|
||||
if (i < digits.fDecimalAt && digitIndex < digits.fCount)
|
||||
{
|
||||
// Output a real digit
|
||||
result += ((UChar)(digits.fDigits[digitIndex++] + zeroDelta));
|
||||
result += ((UChar32)(digits.fDigits[digitIndex++] + zeroDelta));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -908,7 +908,7 @@ DecimalFormat::subformat(UnicodeString& result,
|
||||
if (i >= negDecimalAt)
|
||||
{
|
||||
// Output a digit
|
||||
result += ((UChar)(digits.fDigits[digitIndex++] + zeroDelta));
|
||||
result += ((UChar32)(digits.fDigits[digitIndex++] + zeroDelta));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2023,10 +2023,11 @@ DecimalFormat::appendAffix( UnicodeString& buffer,
|
||||
buffer += affix;
|
||||
else {
|
||||
for (int32_t j = 0; j < affix.length(); ++j) {
|
||||
UChar c = affix[j];
|
||||
UChar32 c = affix.char32At(j);
|
||||
buffer += c;
|
||||
if (c == 0x0027 /*'\''*/)
|
||||
buffer += c;
|
||||
j = j + UTF_NEED_MULTIPLE_UCHAR(c);
|
||||
}
|
||||
}
|
||||
if (needQuote)
|
||||
@ -2595,8 +2596,9 @@ DecimalFormat::applyPattern(const UnicodeString& pattern,
|
||||
return;
|
||||
}
|
||||
padPos = pos;
|
||||
padChar = pattern[(UTextOffset) ++pos];
|
||||
pos += padEscape.length();
|
||||
padChar = pattern.char32At(++pos);
|
||||
pos += 1 + UTF_NEED_MULTIPLE_UCHAR(pattern.char32At(pos));
|
||||
// pos += padEscape.length();
|
||||
continue;
|
||||
} else if (pattern.compare(pos, minus.length(), minus) == 0) {
|
||||
affix->append(kQuote); // Encode minus
|
||||
|
@ -39,6 +39,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
||||
CASE(9,TestPad);
|
||||
CASE(10,TestPatterns2);
|
||||
CASE(11,TestSecondaryGrouping);
|
||||
CASE(12,TestSurrogateSupport);
|
||||
|
||||
default: name = ""; break;
|
||||
}
|
||||
@ -543,12 +544,12 @@ void NumberFormatTest::expect(NumberFormat& fmt, const Formattable& n,
|
||||
((DecimalFormat*) &fmt)->toPattern(pat);
|
||||
if (saw == exp) {
|
||||
logln(UnicodeString("Ok ") + toString(n) + " x " +
|
||||
pat + " = \"" +
|
||||
saw + "\"");
|
||||
escape(pat) + " = \"" +
|
||||
escape(saw) + "\"");
|
||||
} else {
|
||||
errln(UnicodeString("FAIL ") + toString(n) + " x " +
|
||||
pat + " = \"" +
|
||||
saw + "\", expected \"" + exp + "\"");
|
||||
escape(pat) + " = \"" +
|
||||
escape(saw) + "\", expected \"" + exp + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
@ -970,3 +971,58 @@ void NumberFormatTest::expectPat(DecimalFormat& fmt, const UnicodeString& exp) {
|
||||
errln(UnicodeString("FAIL \"") + pat + "\", expected \"" + exp + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
void NumberFormatTest::TestSurrogateSupport(void) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DecimalFormatSymbols custom(Locale::US, status);
|
||||
CHECK(status, "DecimalFormatSymbols constructor");
|
||||
|
||||
custom.setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, "decimal");
|
||||
custom.setSymbol(DecimalFormatSymbols::kPlusSignSymbol, "plus");
|
||||
custom.setSymbol(DecimalFormatSymbols::kMinusSignSymbol, " minus ");
|
||||
custom.setSymbol(DecimalFormatSymbols::kExponentialSymbol, "exponent");
|
||||
|
||||
UnicodeString patternStr("*\\U00010000##.##", "");
|
||||
patternStr = patternStr.unescape();
|
||||
UnicodeString expStr("\\U00010000\\U00010000\\U00010000\\U000100000", "");
|
||||
expStr = expStr.unescape();
|
||||
expect(new DecimalFormat(patternStr, custom, status),
|
||||
int32_t(0), expStr, status);
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
expect(new DecimalFormat("*^##.##", custom, status),
|
||||
int32_t(0), "^^^^0", status);
|
||||
status = U_ZERO_ERROR;
|
||||
expect(new DecimalFormat("##.##", custom, status),
|
||||
-1.3, " minus 1decimal3", status);
|
||||
status = U_ZERO_ERROR;
|
||||
expect(new DecimalFormat("##0.0####E0 g'-'m/s^2", custom, status),
|
||||
int32_t(0), "0decimal0exponent0 g-m/s^2", status);
|
||||
status = U_ZERO_ERROR;
|
||||
expect(new DecimalFormat("##0.0####E0 g'-'m/s^2", custom, status),
|
||||
1.0/3, "333decimal333exponent minus 3 g-m/s^2", status);
|
||||
status = U_ZERO_ERROR;
|
||||
expect(new DecimalFormat("##0.0#### g'-'m/s^2", custom, status),
|
||||
int32_t(0), "0decimal0 g-m/s^2", status);
|
||||
status = U_ZERO_ERROR;
|
||||
expect(new DecimalFormat("##0.0#### g'-'m/s^2", custom, status),
|
||||
1.0/3, "0decimal33333 g-m/s^2", status);
|
||||
|
||||
UnicodeString zero((UChar32)0x10000);
|
||||
custom.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, zero);
|
||||
expStr = UnicodeString("\\U00010001decimal\\U00010002\\U00010005\\U00010000", "");
|
||||
expStr = expStr.unescape();
|
||||
status = U_ZERO_ERROR;
|
||||
expect(new DecimalFormat("##0.000", custom, status),
|
||||
1.25, expStr, status);
|
||||
|
||||
custom.setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, (UChar)0x30);
|
||||
custom.setSymbol(DecimalFormatSymbols::kCurrencySymbol, "units of money");
|
||||
custom.setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, "money separator");
|
||||
patternStr = "0.00 \\u00A4' in your bank account'";
|
||||
patternStr = patternStr.unescape();
|
||||
expStr = UnicodeString(" minus 20money separator00 units of money in your bank account", "");
|
||||
status = U_ZERO_ERROR;
|
||||
expect(new DecimalFormat(patternStr, custom, status),
|
||||
int32_t(-20), expStr, status);
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ public:
|
||||
virtual void TestExponent(void);
|
||||
virtual void TestScientific(void);
|
||||
|
||||
virtual void TestSurrogateSupport(void);
|
||||
|
||||
/**
|
||||
* Test the functioning of the secondary grouping value.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user