about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBrian Anderson <andersrb@gmail.com>2011-04-11 21:36:10 -0400
committerBrian Anderson <andersrb@gmail.com>2011-04-11 21:54:03 -0400
commitbba245f3e6cdf9203cfafe7e8a81739a499b20eb (patch)
tree4333ee7ef70ca5d8f71deb0dbc42c0ec7541bde0 /src
parent37f87161cc408ad76d4b748be428b1b206a0ed28 (diff)
downloadrust-bba245f3e6cdf9203cfafe7e8a81739a499b20eb.tar.gz
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 f006cb5ebce..6004bc90c25 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 138f389499f..7ef9160594d 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 db0d8a19583..2eb25099427 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");
 }