Skip to content

Commit bba245f

Browse files
committed
Add support for bool, char to extfmt.
XFAIL syntax-extension-fmt in rustboot.
1 parent 37f8716 commit bba245f

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/comp/front/extfmt.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
179179
}
180180
}
181181
}
182+
case (ty_bool) {
183+
let vec[str] path = vec("std", "ExtFmt", "RT", "bool_to_str");
184+
let vec[@ast.expr] args = vec(arg);
185+
ret make_call(arg.span, path, args);
186+
}
187+
case (ty_char) {
188+
let vec[str] path = vec("std", "ExtFmt", "RT", "char_to_str");
189+
let vec[@ast.expr] args = vec(arg);
190+
ret make_call(arg.span, path, args);
191+
}
182192
case (_) {
183193
log unsupported;
184194
fail;

src/lib/ExtFmt.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ mod RT {
271271
fn uint_to_str(uint u) -> str {
272272
ret _uint.to_str(u, 10u);
273273
}
274+
275+
fn bool_to_str(bool b) -> str {
276+
if (b) {
277+
ret "true";
278+
} else {
279+
ret "false";
280+
}
281+
}
282+
283+
fn char_to_str(char c) -> str {
284+
ret _str.from_char(c);
285+
}
274286
}
275287

276288
// Local Variables:

src/test/run-pass/syntax-extension-fmt.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// xfail-boot
12
// xfail-stage0
23
use std;
34
import std._str;
@@ -11,7 +12,13 @@ fn test(str actual, str expected) {
1112
fn main() {
1213
test(#fmt("hello %d friends and %s things", 10, "formatted"),
1314
"hello 10 friends and formatted things");
14-
test(#fmt("d: %d", 1), "d: 1");
15-
test(#fmt("i: %i", 2), "i: 2");
16-
test(#fmt("s: %s", "test"), "s: test");
15+
16+
// Simple tests for types
17+
test(#fmt("%d", 1), "1");
18+
test(#fmt("%i", 2), "2");
19+
test(#fmt("%i", -1), "-1");
20+
test(#fmt("%s", "test"), "test");
21+
test(#fmt("%b", true), "true");
22+
test(#fmt("%b", false), "false");
23+
test(#fmt("%c", 'A'), "A");
1724
}

0 commit comments

Comments
 (0)