Add support for bool, char to extfmt.

XFAIL syntax-extension-fmt in rustboot.
This commit is contained in:
Brian Anderson 2011-04-11 21:36:10 -04:00
parent 37f87161cc
commit bba245f3e6
3 changed files with 32 additions and 3 deletions

View file

@ -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;

View file

@ -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:

View file

@ -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");
}