ICU-4605 Increase code coverage. Make sure that precision is ignored for %c and %C.
X-SVN-Rev: 18092
This commit is contained in:
parent
8a37b4992d
commit
d7cc623449
@ -260,16 +260,9 @@ u_printf_char_handler(const u_printf_stream_handler *handler,
|
||||
|
||||
/* width = minimum # of characters to write */
|
||||
/* precision = maximum # of characters to write */
|
||||
/* precision is ignored when handling a char */
|
||||
|
||||
/* precision takes precedence over width */
|
||||
/* determine if the string should be truncated */
|
||||
if(info->fPrecision != -1 && len > info->fPrecision) {
|
||||
written = handler->write(context, s, info->fPrecision);
|
||||
}
|
||||
else {
|
||||
/* determine if the string should be padded */
|
||||
written = handler->pad_and_justify(context, info, s, len);
|
||||
}
|
||||
written = handler->pad_and_justify(context, info, s, len);
|
||||
|
||||
return written;
|
||||
}
|
||||
@ -781,20 +774,12 @@ u_printf_uchar_handler(const u_printf_stream_handler *handler,
|
||||
int32_t written = 0;
|
||||
UChar arg = (UChar)(args[0].int64Value);
|
||||
|
||||
|
||||
/* width = minimum # of characters to write */
|
||||
/* precision = maximum # of characters to write */
|
||||
/* precision is ignored when handling a uchar */
|
||||
|
||||
/* precision takes precedence over width */
|
||||
/* determine if the char should be printed */
|
||||
if(info->fPrecision != -1 && info->fPrecision < 1) {
|
||||
/* write nothing */
|
||||
written = 0;
|
||||
}
|
||||
else {
|
||||
/* determine if the string should be padded */
|
||||
written = handler->pad_and_justify(context, info, &arg, 1);
|
||||
}
|
||||
/* determine if the string should be padded */
|
||||
written = handler->pad_and_justify(context, info, &arg, 1);
|
||||
|
||||
return written;
|
||||
}
|
||||
|
@ -1083,9 +1083,13 @@ static void TestFprintfFormat(void) {
|
||||
|
||||
TestFPrintFormat("%8c", (char)'e', "%8c", (char)'e');
|
||||
TestFPrintFormat("%-8c", (char)'e', "%-8c", (char)'e');
|
||||
TestFPrintFormat("%5.3c", (char)'e', "%5.3c", (char)'e');
|
||||
TestFPrintFormat("%-5.3c", (char)'e', "%-5.3c", (char)'e');
|
||||
|
||||
TestFPrintFormat("%8C", (UChar)0x65, "%8c", (char)'e');
|
||||
TestFPrintFormat("%-8C", (UChar)0x65, "%-8c", (char)'e');
|
||||
TestFPrintFormat("%5.3C", (UChar)0x65, "%5.3c", (char)'e');
|
||||
TestFPrintFormat("%-5.3C", (UChar)0x65, "%-5.3c", (char)'e');
|
||||
|
||||
TestFPrintFormat("%f", 1.23456789, "%f", 1.23456789);
|
||||
TestFPrintFormat("%f", 12345.6789, "%f", 12345.6789);
|
||||
|
@ -391,9 +391,13 @@ static void TestSprintfFormat(void) {
|
||||
|
||||
TestSPrintFormat("%8c", (char)'e', "%8c", (char)'e');
|
||||
TestSPrintFormat("%-8c", (char)'e', "%-8c", (char)'e');
|
||||
TestSPrintFormat("%5.3c", (char)'e', "%5.3c", (char)'e');
|
||||
TestSPrintFormat("%-5.3c", (char)'e', "%-5.3c", (char)'e');
|
||||
|
||||
TestSPrintFormat("%8C", (UChar)0x65, "%8c", (char)'e');
|
||||
TestSPrintFormat("%-8C", (UChar)0x65, "%-8c", (char)'e');
|
||||
TestSPrintFormat("%5.3C", (UChar)0x65, "%5.3c", (char)'e');
|
||||
TestSPrintFormat("%-5.3C", (UChar)0x65, "%-5.3c", (char)'e');
|
||||
|
||||
TestSPrintFormat("%f", 1.23456789, "%f", 1.23456789);
|
||||
TestSPrintFormat("%f", 12345.6789, "%f", 12345.6789);
|
||||
|
3
icu4c/source/test/testdata/icuio.txt
vendored
3
icu4c/source/test/testdata/icuio.txt
vendored
@ -48,6 +48,9 @@ icuio {
|
||||
{ "%-5.3s", "abc ", "s", "abcdef" }
|
||||
{ "%5.3s", " a", "s", "a" }
|
||||
{ "%-5.3s", "a ", "s", "a" }
|
||||
{ "%5.3C", " a", "2", "61" }
|
||||
{ "%-5.3C", "a ", "2", "61" }
|
||||
{ "%-5.0C", "a ", "2", "61" } // Make sure that the precision is ignored.
|
||||
{ "%.3P", "120.000%", "d", "1.2" }
|
||||
{ "%.0P", "120%", "d", "1.2" }
|
||||
{ "%.3P", "1.200%", "d", "0.012" }
|
||||
|
Loading…
Reference in New Issue
Block a user