aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-04-17 17:24:17 -0400
committerBrian Anderson <[email protected]>2011-04-17 17:24:17 -0400
commit1bec738c56c221843adbb022914c1de6e3bd7c61 (patch)
tree2b5d86bb58bc138d1c1c10248a2a8b94f26a8a94 /src
parentFix indentation in syntax-extension-fmt.rs (diff)
downloadrust-1bec738c56c221843adbb022914c1de6e3bd7c61.tar.xz
rust-1bec738c56c221843adbb022914c1de6e3bd7c61.zip
Support #fmt precision for bools, with same rules as strings
Not totally confident this is desirable. The alternative would be to make it a compile error.
Diffstat (limited to 'src')
-rw-r--r--src/lib/ExtFmt.rs8
-rw-r--r--src/test/run-pass/syntax-extension-fmt.rs8
2 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/ExtFmt.rs b/src/lib/ExtFmt.rs
index bbcb14bd..4be03858 100644
--- a/src/lib/ExtFmt.rs
+++ b/src/lib/ExtFmt.rs
@@ -358,11 +358,15 @@ mod RT {
}
fn conv_bool(&conv cv, bool b) -> str {
+ auto s;
if (b) {
- ret pad(cv, "true");
+ s = "true";
} else {
- ret pad(cv, "false");
+ s = "false";
}
+ // Run the boolean conversion through the string conversion logic,
+ // giving it the same rules for precision, etc.
+ ret conv_str(cv, s);
}
fn conv_char(&conv cv, char c) -> str {
diff --git a/src/test/run-pass/syntax-extension-fmt.rs b/src/test/run-pass/syntax-extension-fmt.rs
index 935c87c1..5c66b17a 100644
--- a/src/test/run-pass/syntax-extension-fmt.rs
+++ b/src/test/run-pass/syntax-extension-fmt.rs
@@ -104,4 +104,12 @@ fn main() {
test(#fmt("%.5x", 127u), "0007f");
test(#fmt("%.5t", 3u), "00011");
test(#fmt("%.5c", 'A'), "A");
+
+ // Bool precision. I'm not sure if it's good or bad to have bool
+ // conversions support precision - it's not standard printf so we
+ // can do whatever. For now I'm making it behave the same as string
+ // conversions.
+ test(#fmt("%.b", true), "");
+ test(#fmt("%.0b", true), "");
+ test(#fmt("%.1b", true), "t");
}