Skip to content

Commit 2e2160b

Browse files
committed
core: Update all tests for fmt movement
1 parent d12a136 commit 2e2160b

File tree

27 files changed

+278
-162
lines changed

27 files changed

+278
-162
lines changed

src/compiletest/common.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ impl FromStr for Mode {
4141
impl fmt::Show for Mode {
4242
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4343
let msg = match *self {
44-
CompileFail => "compile-fail",
45-
RunFail => "run-fail",
46-
RunPass => "run-pass",
47-
Pretty => "pretty",
48-
DebugInfoGdb => "debuginfo-gdb",
49-
DebugInfoLldb => "debuginfo-lldb",
50-
Codegen => "codegen",
44+
CompileFail => "compile-fail",
45+
RunFail => "run-fail",
46+
RunPass => "run-pass",
47+
Pretty => "pretty",
48+
DebugInfoGdb => "debuginfo-gdb",
49+
DebugInfoLldb => "debuginfo-lldb",
50+
Codegen => "codegen",
5151
};
52-
write!(f.buf, "{}", msg)
52+
msg.fmt(f)
5353
}
5454
}
5555

src/libcore/any.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ mod tests {
166166

167167
match a.as_ref::<uint>() {
168168
Some(&5) => {}
169-
x => fail!("Unexpected value {:?}", x)
169+
x => fail!("Unexpected value {}", x)
170170
}
171171

172172
match a.as_ref::<Test>() {
173173
None => {}
174-
x => fail!("Unexpected value {:?}", x)
174+
x => fail!("Unexpected value {}", x)
175175
}
176176
}
177177

@@ -189,35 +189,35 @@ mod tests {
189189
assert_eq!(*x, 5u);
190190
*x = 612;
191191
}
192-
x => fail!("Unexpected value {:?}", x)
192+
x => fail!("Unexpected value {}", x)
193193
}
194194

195195
match b_r.as_mut::<uint>() {
196196
Some(x) => {
197197
assert_eq!(*x, 7u);
198198
*x = 413;
199199
}
200-
x => fail!("Unexpected value {:?}", x)
200+
x => fail!("Unexpected value {}", x)
201201
}
202202

203203
match a_r.as_mut::<Test>() {
204204
None => (),
205-
x => fail!("Unexpected value {:?}", x)
205+
x => fail!("Unexpected value {}", x)
206206
}
207207

208208
match b_r.as_mut::<Test>() {
209209
None => (),
210-
x => fail!("Unexpected value {:?}", x)
210+
x => fail!("Unexpected value {}", x)
211211
}
212212

213213
match a_r.as_mut::<uint>() {
214214
Some(&612) => {}
215-
x => fail!("Unexpected value {:?}", x)
215+
x => fail!("Unexpected value {}", x)
216216
}
217217

218218
match b_r.as_mut::<uint>() {
219219
Some(&413) => {}
220-
x => fail!("Unexpected value {:?}", x)
220+
x => fail!("Unexpected value {}", x)
221221
}
222222
}
223223

@@ -229,11 +229,11 @@ mod tests {
229229
let b = box Test as Box<Any>;
230230

231231
match a.move::<uint>() {
232-
Ok(a) => { assert_eq!(a, box 8u); }
232+
Ok(a) => { assert!(a == box 8u); }
233233
Err(..) => fail!()
234234
}
235235
match b.move::<Test>() {
236-
Ok(a) => { assert_eq!(a, box Test); }
236+
Ok(a) => { assert!(a == box Test); }
237237
Err(..) => fail!()
238238
}
239239

@@ -246,13 +246,14 @@ mod tests {
246246

247247
#[test]
248248
fn test_show() {
249-
let a = box 8u as Box<::realcore::any::Any>;
250-
let b = box Test as Box<::realcore::any::Any>;
251-
assert_eq!(format!("{}", a), "Box<Any>".to_owned());
252-
assert_eq!(format!("{}", b), "Box<Any>".to_owned());
253-
254-
let a = &8u as &::realcore::any::Any;
255-
let b = &Test as &::realcore::any::Any;
249+
use realstd::to_str::ToStr;
250+
let a = box 8u as Box<::realstd::any::Any>;
251+
let b = box Test as Box<::realstd::any::Any>;
252+
assert_eq!(a.to_str(), "Box<Any>".to_owned());
253+
assert_eq!(b.to_str(), "Box<Any>".to_owned());
254+
255+
let a = &8u as &Any;
256+
let b = &Test as &Any;
256257
assert_eq!(format!("{}", a), "&Any".to_owned());
257258
assert_eq!(format!("{}", b), "&Any".to_owned());
258259
}

src/libcore/cell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ mod test {
255255
fn cell_has_sensible_show() {
256256
use str::StrSlice;
257257

258-
let x = ::realcore::cell::Cell::new("foo bar");
258+
let x = Cell::new("foo bar");
259259
assert!(format!("{}", x).contains(x.get()));
260260

261261
x.set("baz qux");

src/libcore/char.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,9 @@ impl Default for char {
633633
mod test {
634634
use super::{escape_unicode, escape_default};
635635

636-
use realcore::char::Char;
636+
use char::Char;
637637
use slice::ImmutableVector;
638-
use realstd::option::{Some, None};
638+
use option::{Some, None};
639639
use realstd::strbuf::StrBuf;
640640
use realstd::str::StrAllocating;
641641

src/libcore/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ mod test {
131131
fn test_owned_clone() {
132132
let a = box 5i;
133133
let b: Box<int> = realclone(&a);
134-
assert_eq!(a, b);
134+
assert!(a == b);
135135
}
136136

137137
#[test]

src/libcore/fmt/float.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,16 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
352352

353353
let mut filler = Filler { buf: buf, end: &mut end };
354354
match sign {
355-
SignNeg => { let _ = write!(&mut filler, "{:-}", exp); }
356-
SignNone | SignAll => { let _ = write!(&mut filler, "{}", exp); }
355+
SignNeg => {
356+
let _ = format_args!(|args| {
357+
fmt::write(&mut filler, args)
358+
}, "{:-}", exp);
359+
}
360+
SignNone | SignAll => {
361+
let _ = format_args!(|args| {
362+
fmt::write(&mut filler, args)
363+
}, "{}", exp);
364+
}
357365
}
358366
}
359367
}

src/libcore/fmt/mod.rs

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
#![allow(unused_variable)]
1414

1515
use any;
16-
use cast;
1716
use cell::Cell;
1817
use char::Char;
1918
use container::Container;
2019
use iter::{Iterator, range};
2120
use kinds::Copy;
21+
use mem;
2222
use option::{Option, Some, None};
23-
use owned::Box;
24-
use result;
2523
use result::{Ok, Err};
24+
use result;
2625
use slice::{Vector, ImmutableVector};
2726
use slice;
2827
use str::StrSlice;
@@ -34,8 +33,7 @@ pub use self::num::RadixFmt;
3433

3534
macro_rules! write(
3635
($dst:expr, $($arg:tt)*) => ({
37-
let dst: &mut ::fmt::FormatWriter = $dst;
38-
format_args!(|args| { ::std::fmt::write(dst, args) }, $($arg)*)
36+
format_args!(|args| { $dst.write_fmt(args) }, $($arg)*)
3937
})
4038
)
4139

@@ -104,7 +102,7 @@ impl<'a> Arguments<'a> {
104102
#[doc(hidden)] #[inline]
105103
pub unsafe fn new<'a>(fmt: &'static [rt::Piece<'static>],
106104
args: &'a [Argument<'a>]) -> Arguments<'a> {
107-
Arguments{ fmt: cast::transmute(fmt), args: args }
105+
Arguments{ fmt: mem::transmute(fmt), args: args }
108106
}
109107
}
110108

@@ -329,7 +327,7 @@ impl<'a> Formatter<'a> {
329327
rt::Plural(offset, ref selectors, ref default) => {
330328
// This is validated at compile-time to be a pointer to a
331329
// '&uint' value.
332-
let value: &uint = unsafe { cast::transmute(arg.value) };
330+
let value: &uint = unsafe { mem::transmute(arg.value) };
333331
let value = *value;
334332

335333
// First, attempt to match against explicit values without the
@@ -372,7 +370,7 @@ impl<'a> Formatter<'a> {
372370
rt::Select(ref selectors, ref default) => {
373371
// This is validated at compile-time to be a pointer to a
374372
// string slice,
375-
let value: & &str = unsafe { cast::transmute(arg.value) };
373+
let value: & &str = unsafe { mem::transmute(arg.value) };
376374
let value = *value;
377375

378376
for s in selectors.iter() {
@@ -565,10 +563,33 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result,
565563
t: &'a T) -> Argument<'a> {
566564
unsafe {
567565
Argument {
568-
formatter: cast::transmute(f),
569-
value: cast::transmute(t)
566+
formatter: mem::transmute(f),
567+
value: mem::transmute(t)
568+
}
569+
}
570+
}
571+
572+
#[cfg(test)]
573+
pub fn format(args: &Arguments) -> ~str {
574+
use str;
575+
use realstd::str::StrAllocating;
576+
use realstd::io::MemWriter;
577+
578+
fn mywrite<T: ::realstd::io::Writer>(t: &mut T, b: &[u8]) {
579+
use realstd::io::Writer;
580+
let _ = t.write(b);
581+
}
582+
583+
impl FormatWriter for MemWriter {
584+
fn write(&mut self, bytes: &[u8]) -> Result {
585+
mywrite(self, bytes);
586+
Ok(())
570587
}
571588
}
589+
590+
let mut i = MemWriter::new();
591+
let _ = write(&mut i, args);
592+
str::from_utf8(i.get_ref()).unwrap().to_owned()
572593
}
573594

574595
/// When the compiler determines that the type of an argument *must* be a string
@@ -590,12 +611,12 @@ pub fn argumentuint<'a>(s: &'a uint) -> Argument<'a> {
590611
impl<T: Show> Show for @T {
591612
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
592613
}
593-
impl<T: Show> Show for Box<T> {
594-
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
595-
}
596614
impl<'a, T: Show> Show for &'a T {
597615
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) }
598616
}
617+
impl<'a, T: Show> Show for &'a mut T {
618+
fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
619+
}
599620

600621
impl Bool for bool {
601622
fn fmt(&self, f: &mut Formatter) -> Result {
@@ -613,7 +634,7 @@ impl Char for char {
613634
fn fmt(&self, f: &mut Formatter) -> Result {
614635
let mut utf8 = [0u8, ..4];
615636
let amt = self.encode_utf8(utf8);
616-
let s: &str = unsafe { cast::transmute(utf8.slice_to(amt)) };
637+
let s: &str = unsafe { mem::transmute(utf8.slice_to(amt)) };
617638
secret_string(&s, f)
618639
}
619640
}
@@ -738,20 +759,20 @@ macro_rules! tuple (
738759
impl<$($name:Show),*> Show for ($($name,)*) {
739760
#[allow(uppercase_variables, dead_assignment)]
740761
fn fmt(&self, f: &mut Formatter) -> Result {
741-
try!(write!(f.buf, "("));
762+
try!(write!(f, "("));
742763
let ($(ref $name,)*) = *self;
743764
let mut n = 0;
744765
$(
745766
if n > 0 {
746-
try!(write!(f.buf, ", "));
767+
try!(write!(f, ", "));
747768
}
748-
try!(write!(f.buf, "{}", *$name));
769+
try!(write!(f, "{}", *$name));
749770
n += 1;
750771
)*
751772
if n == 1 {
752-
try!(write!(f.buf, ","));
773+
try!(write!(f, ","));
753774
}
754-
write!(f.buf, ")")
775+
write!(f, ")")
755776
}
756777
}
757778
peel!($($name,)*)
@@ -760,30 +781,26 @@ macro_rules! tuple (
760781

761782
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
762783

763-
impl Show for Box<any::Any> {
764-
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("Box<Any>") }
765-
}
766-
767784
impl<'a> Show for &'a any::Any {
768785
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") }
769786
}
770787

771788
impl<'a, T: Show> Show for &'a [T] {
772789
fn fmt(&self, f: &mut Formatter) -> Result {
773790
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
774-
try!(write!(f.buf, "["));
791+
try!(write!(f, "["));
775792
}
776793
let mut is_first = true;
777794
for x in self.iter() {
778795
if is_first {
779796
is_first = false;
780797
} else {
781-
try!(write!(f.buf, ", "));
798+
try!(write!(f, ", "));
782799
}
783-
try!(write!(f.buf, "{}", *x))
800+
try!(write!(f, "{}", *x))
784801
}
785802
if f.flags & (1 << (rt::FlagAlternate as uint)) == 0 {
786-
try!(write!(f.buf, "]"));
803+
try!(write!(f, "]"));
787804
}
788805
Ok(())
789806
}
@@ -809,7 +826,7 @@ impl Show for () {
809826

810827
impl<T: Copy + Show> Show for Cell<T> {
811828
fn fmt(&self, f: &mut Formatter) -> Result {
812-
write!(f.buf, r"Cell \{ value: {} \}", self.get())
829+
write!(f, r"Cell \{ value: {} \}", self.get())
813830
}
814831
}
815832

src/libcore/fmt/num.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ macro_rules! integer {
172172
int_base!(Octal for $Int as $Uint -> Octal)
173173
int_base!(LowerHex for $Int as $Uint -> LowerHex)
174174
int_base!(UpperHex for $Int as $Uint -> UpperHex)
175-
radix_fmt!($Int as $Uint, fmt_int)
175+
radix_fmt!($Int as $Int, fmt_int)
176176

177177
int_base!(Show for $Uint as $Uint -> Decimal)
178178
int_base!(Unsigned for $Uint as $Uint -> Decimal)
@@ -194,7 +194,7 @@ mod tests {
194194
use fmt::radix;
195195
use super::{Binary, Octal, Decimal, LowerHex, UpperHex};
196196
use super::{GenericRadix, Radix};
197-
use str::StrAllocating;
197+
use realstd::str::StrAllocating;
198198

199199
#[test]
200200
fn test_radix_base() {

0 commit comments

Comments
 (0)