about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <andersrb@gmail.com>2011-04-26 19:52:31 -0400
committerBrian Anderson <andersrb@gmail.com>2011-04-26 20:20:17 -0400
commit66b59e4b056ade5f0a5e5a8fd64534aeea9b952c (patch)
tree588266e56db994279d4957133d8df81a3dee3356
parente77f5b1561092d9caa3a5423c569c1a2f8e44f99 (diff)
Make #fmt char conversions behave like printf
-rw-r--r--src/lib/ExtFmt.rs2
-rw-r--r--src/test/run-pass/syntax-extension-fmt.rs7
2 files changed, 6 insertions, 3 deletions
diff --git a/src/lib/ExtFmt.rs b/src/lib/ExtFmt.rs
index fb7c4b9a0ae..a87fc87904d 100644
--- a/src/lib/ExtFmt.rs
+++ b/src/lib/ExtFmt.rs
@@ -382,7 +382,7 @@ mod RT {
     }
 
     fn conv_char(&conv cv, char c) -> str {
-        ret conv_str(cv, _str.from_char(c));
+        ret pad(cv, _str.from_char(c), pad_nozero);
     }
 
     fn conv_str(&conv cv, str s) -> str {
diff --git a/src/test/run-pass/syntax-extension-fmt.rs b/src/test/run-pass/syntax-extension-fmt.rs
index c5ad77f80d2..b69533702fe 100644
--- a/src/test/run-pass/syntax-extension-fmt.rs
+++ b/src/test/run-pass/syntax-extension-fmt.rs
@@ -67,7 +67,7 @@ fn main() {
   test(#fmt("%.s", "test"), "");
   test(#fmt("%.x", 127u), "7f");
   test(#fmt("%.t", 3u), "11");
-  test(#fmt("%.c", 'A'), "");
+  test(#fmt("%.c", 'A'), "A");
 
   test(#fmt("%.0d", 0), "");
   test(#fmt("%.0u", 0u), "");
@@ -79,7 +79,7 @@ fn main() {
   test(#fmt("%.0s", "test"), "");
   test(#fmt("%.0x", 127u), "7f");
   test(#fmt("%.0t", 3u), "11");
-  test(#fmt("%.0c", 'A'), "");
+  test(#fmt("%.0c", 'A'), "A");
 
   test(#fmt("%.1d", 0), "0");
   test(#fmt("%.1u", 0u), "0");
@@ -137,6 +137,7 @@ fn main() {
   test(#fmt("%05t", 3u), "00011");
   // 0-padding a string is undefined but glibc does this:
   test(#fmt("%05s", "test"), " test");
+  test(#fmt("%05c", 'A'), "    A");
   test(#fmt("%05b", true), " true");
 
   // Left-justify overrides 0-padding
@@ -148,6 +149,7 @@ fn main() {
   test(#fmt("%-05X", 127u), "7F   ");
   test(#fmt("%-05t", 3u), "11   ");
   test(#fmt("%-05s", "test"), "test ");
+  test(#fmt("%-05c", 'A'), "A    ");
   test(#fmt("%-05b", true), "true ");
 
   // Precision overrides 0-padding
@@ -158,6 +160,7 @@ fn main() {
   test(#fmt("%06.5d", -10), "-00010");
   test(#fmt("%06.5u", 10u), " 00010");
   test(#fmt("%06.5s", "test"), "  test");
+  test(#fmt("%06.5c", 'A'), "     A");
   test(#fmt("%06.5x", 127u), " 0007f");
   test(#fmt("%06.5X", 127u), " 0007F");