auto merge of #8085 : mrordinaire/rust/percent-p, r=huonw
pull request for #8011
This commit is contained in:
commit
8413d4769f
@ -114,6 +114,7 @@ pub mod ct {
|
||||
TyHex(Caseness),
|
||||
TyOctal,
|
||||
TyFloat,
|
||||
TyPointer,
|
||||
TyPoly,
|
||||
}
|
||||
|
||||
@ -325,6 +326,7 @@ pub mod ct {
|
||||
't' => TyBits,
|
||||
'o' => TyOctal,
|
||||
'f' => TyFloat,
|
||||
'p' => TyPointer,
|
||||
'?' => TyPoly,
|
||||
_ => err(fmt!("unknown type in conversion: %c", s.char_at(i)))
|
||||
};
|
||||
@ -434,6 +436,7 @@ pub mod ct {
|
||||
assert!(test("t", TyBits));
|
||||
assert!(test("x", TyHex(CaseLower)));
|
||||
assert!(test("X", TyHex(CaseUpper)));
|
||||
assert!(test("p", TyPointer));
|
||||
assert!(test("?", TyPoly));
|
||||
}
|
||||
|
||||
@ -573,6 +576,10 @@ pub mod rt {
|
||||
} else { None };
|
||||
pad(cv, s, head, PadFloat, buf);
|
||||
}
|
||||
pub fn conv_pointer<T>(cv: Conv, ptr: *T, buf: &mut ~str) {
|
||||
let s = ~"0x" + uint_to_str_prec(ptr as uint, 16, 1u);
|
||||
pad(cv, s, None, PadNozero, buf);
|
||||
}
|
||||
pub fn conv_poly<T>(cv: Conv, v: &T, buf: &mut ~str) {
|
||||
let s = sys::log_str(v);
|
||||
conv_str(cv, s, buf);
|
||||
|
@ -191,6 +191,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span,
|
||||
TyChar => ("char", arg),
|
||||
TyBits | TyOctal | TyHex(_) | TyInt(Unsigned) => ("uint", arg),
|
||||
TyFloat => ("float", arg),
|
||||
TyPointer => ("pointer", arg),
|
||||
TyPoly => ("poly", cx.expr_addr_of(sp, arg))
|
||||
};
|
||||
return make_conv_call(cx, arg.span, name, cnv, actual_arg,
|
||||
@ -242,6 +243,7 @@ fn pieces_to_expr(cx: @ExtCtxt, sp: span,
|
||||
},
|
||||
TyOctal => debug!("type: octal"),
|
||||
TyFloat => debug!("type: float"),
|
||||
TyPointer => debug!("type: pointer"),
|
||||
TyPoly => debug!("type: poly")
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ pub fn main() {
|
||||
part6();
|
||||
percent();
|
||||
more_floats();
|
||||
pointer();
|
||||
}
|
||||
|
||||
fn part1() {
|
||||
@ -263,3 +264,13 @@ fn more_floats() {
|
||||
assert_eq!(~"7.0000", fmt!("%.4f", 6.999999999));
|
||||
assert_eq!(~"3.141590000", fmt!("%.9f", 3.14159));
|
||||
}
|
||||
|
||||
fn pointer() {
|
||||
for 10.times {
|
||||
let x: uint = ::std::rand::random();
|
||||
assert_eq!(fmt!("%p", x as *uint), fmt!("0x%x", x));
|
||||
}
|
||||
|
||||
let i = &1;
|
||||
assert_eq!(fmt!("%p", i), fmt!("0x%x", i as *uint as uint));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user