diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-04-02 16:54:22 -0700 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-10 22:10:10 +1000 |
| commit | d8e45ea7c054b4ad6fb82ec3a9fcf1736b4d7260 (patch) | |
| tree | 3ff220512aeae37710c8b1c783e1229e685bfce3 /src/libtest | |
| parent | 7fbcb400f0697621ece9f9773b0f0bf1ec73e9c1 (diff) | |
| download | rust-d8e45ea7c054b4ad6fb82ec3a9fcf1736b4d7260.tar.gz rust-d8e45ea7c054b4ad6fb82ec3a9fcf1736b4d7260.zip | |
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and
port all code over to use it.
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")); |
