aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-04-11 21:36:10 -0400
committerBrian Anderson <[email protected]>2011-04-11 21:54:03 -0400
commitbba245f3e6cdf9203cfafe7e8a81739a499b20eb (patch)
tree4333ee7ef70ca5d8f71deb0dbc42c0ec7541bde0 /src
parentMove ExtFmt compile-time functions into their own module (diff)
downloadrust-bba245f3e6cdf9203cfafe7e8a81739a499b20eb.tar.xz
rust-bba245f3e6cdf9203cfafe7e8a81739a499b20eb.zip
Add support for bool, char to extfmt.
XFAIL syntax-extension-fmt in rustboot.
Diffstat (limited to 'src')
-rw-r--r--src/comp/front/extfmt.rs10
-rw-r--r--src/lib/ExtFmt.rs12
-rw-r--r--src/test/run-pass/syntax-extension-fmt.rs13
3 files changed, 32 insertions, 3 deletions
diff --git a/src/comp/front/extfmt.rs b/src/comp/front/extfmt.rs
index f006cb5e..6004bc90 100644
--- a/src/comp/front/extfmt.rs
+++ b/src/comp/front/extfmt.rs
@@ -179,6 +179,16 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
}
}
}
+ case (ty_bool) {
+ let vec[str] path = vec("std", "ExtFmt", "RT", "bool_to_str");
+ let vec[@ast.expr] args = vec(arg);
+ ret make_call(arg.span, path, args);
+ }
+ case (ty_char) {
+ let vec[str] path = vec("std", "ExtFmt", "RT", "char_to_str");
+ let vec[@ast.expr] args = vec(arg);
+ ret make_call(arg.span, path, args);
+ }
case (_) {
log unsupported;
fail;
diff --git a/src/lib/ExtFmt.rs b/src/lib/ExtFmt.rs
index 138f3894..7ef91605 100644
--- a/src/lib/ExtFmt.rs
+++ b/src/lib/ExtFmt.rs
@@ -271,6 +271,18 @@ mod RT {
fn uint_to_str(uint u) -> str {
ret _uint.to_str(u, 10u);
}
+
+ fn bool_to_str(bool b) -> str {
+ if (b) {
+ ret "true";
+ } else {
+ ret "false";
+ }
+ }
+
+ fn char_to_str(char c) -> str {
+ ret _str.from_char(c);
+ }
}
// Local Variables:
diff --git a/src/test/run-pass/syntax-extension-fmt.rs b/src/test/run-pass/syntax-extension-fmt.rs
index db0d8a19..2eb25099 100644
--- a/src/test/run-pass/syntax-extension-fmt.rs
+++ b/src/test/run-pass/syntax-extension-fmt.rs
@@ -1,3 +1,4 @@
+// xfail-boot
// xfail-stage0
use std;
import std._str;
@@ -11,7 +12,13 @@ fn test(str actual, str expected) {
fn main() {
test(#fmt("hello %d friends and %s things", 10, "formatted"),
"hello 10 friends and formatted things");
- test(#fmt("d: %d", 1), "d: 1");
- test(#fmt("i: %i", 2), "i: 2");
- test(#fmt("s: %s", "test"), "s: test");
+
+ // Simple tests for types
+ test(#fmt("%d", 1), "1");
+ test(#fmt("%i", 2), "2");
+ test(#fmt("%i", -1), "-1");
+ test(#fmt("%s", "test"), "test");
+ test(#fmt("%b", true), "true");
+ test(#fmt("%b", false), "false");
+ test(#fmt("%c", 'A'), "A");
}