diff options
| author | bors <bors@rust-lang.org> | 2014-04-10 21:01:41 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-10 21:01:41 -0700 |
| commit | cea8def62068b405495ecd1810124ebc88b4f90b (patch) | |
| tree | 65d5755bd532a9213799c52572db6d6683d5e942 /src/libtest | |
| parent | 0156af156d70efd5a3c96d0c5b8fc9bec39a7ae5 (diff) | |
| parent | def90f43e2df9968cda730a2a30cb7ccb9513002 (diff) | |
| download | rust-cea8def62068b405495ecd1810124ebc88b4f90b.tar.gz rust-cea8def62068b405495ecd1810124ebc88b4f90b.zip | |
auto merge of #13440 : huonw/rust/strbuf, r=alexcrichton
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and port all code over to use it. Rebased & tests-fixed version of https://github.com/mozilla/rust/pull/13269
Diffstat (limited to 'src/libtest')
| -rw-r--r-- | src/libtest/lib.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 5c74715fd29..8c6f7576ec4 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -59,6 +59,7 @@ use std::io::{File, ChanReader, ChanWriter}; use std::io; use std::os; use std::str; +use std::strbuf::StrBuf; use std::task; // to be used by rustc to compile tests in libtest @@ -99,13 +100,19 @@ enum NamePadding { PadNone, PadOnLeft, PadOnRight } impl TestDesc { fn padded_name(&self, column_count: uint, align: NamePadding) -> ~str { use std::num::Saturating; - let name = self.name.to_str(); + let mut name = StrBuf::from_str(self.name.to_str()); let fill = column_count.saturating_sub(name.len()); - let pad = " ".repeat(fill); + let mut pad = StrBuf::from_owned_str(" ".repeat(fill)); match align { - PadNone => name, - PadOnLeft => pad.append(name), - PadOnRight => name.append(pad), + PadNone => name.into_owned(), + PadOnLeft => { + pad.push_str(name.as_slice()); + pad.into_owned() + } + PadOnRight => { + name.push_str(pad.as_slice()); + name.into_owned() + } } } } @@ -543,7 +550,7 @@ impl<T: Writer> ConsoleTestState<T> { pub fn write_failures(&mut self) -> io::IoResult<()> { try!(self.write_plain("\nfailures:\n")); let mut failures = Vec::new(); - let mut fail_out = ~""; + let mut fail_out = StrBuf::new(); for &(ref f, ref stdout) in self.failures.iter() { failures.push(f.name.to_str()); if stdout.len() > 0 { @@ -556,7 +563,7 @@ impl<T: Writer> ConsoleTestState<T> { } if fail_out.len() > 0 { try!(self.write_plain("\n")); - try!(self.write_plain(fail_out)); + try!(self.write_plain(fail_out.as_slice())); } try!(self.write_plain("\nfailures:\n")); |
