libstd: Remove ~str from all libstd modules except fmt and str.

This commit is contained in:
Patrick Walton 2014-05-16 10:45:16 -07:00
parent e402e75f4e
commit 36195eb91f
204 changed files with 2102 additions and 1496 deletions

View file

@ -11,5 +11,5 @@
// error-pattern:failed at 'test-assert-owned'
fn main() {
assert!(false, "test-assert-owned".to_owned());
assert!(false, "test-assert-owned".to_strbuf());
}

View file

@ -15,5 +15,5 @@
fn main() {
let mut a = 1;
if 1 == 1 { a = 2; }
fail!("woooo".to_owned() + "o");
fail!(format_strbuf!("woooo{}", "o"));
}

View file

@ -22,9 +22,9 @@ fn main() {
let mut map = collections::HashMap::new();
let mut arr = Vec::new();
for _i in range(0u, 10u) {
arr.push(@"key stuff".to_owned());
arr.push(@"key stuff".to_strbuf());
map.insert(arr.clone(),
arr.clone().append([@"value stuff".to_owned()]));
arr.clone().append([@"value stuff".to_strbuf()]));
if arr.len() == 5 {
fail!();
}

View file

@ -92,6 +92,6 @@ fn main() {
} else if args.len() >= 2 && args[1].as_slice() == "double-fail" {
double();
} else {
runtest(args[0]);
runtest(args[0].as_slice());
}
}

View file

@ -46,6 +46,6 @@ fn main() {
info!("info");
});
let s = r.read_to_str().unwrap();
assert!(s.contains("info"));
assert!(!s.contains("debug"));
assert!(s.as_slice().contains("info"));
assert!(!s.as_slice().contains("debug"));
}

View file

@ -32,7 +32,7 @@ pub fn main() {
// expression was never evaluated, we wound up trying to clean
// uninitialized memory.
if args.len() >= 2 && args[1] == "signal".to_owned() {
if args.len() >= 2 && args[1].as_slice() == "signal" {
// Raise a segfault.
unsafe { *(0 as *mut int) = 0; }
}

View file

@ -9,8 +9,8 @@
// except according to those terms.
pub fn main() {
assert_eq!(format!(concat!("foo", "bar", "{}"), "baz"), "foobarbaz".to_owned());
assert_eq!(format!(concat!()), "".to_owned());
assert_eq!(format!(concat!("foo", "bar", "{}"), "baz"), "foobarbaz".to_strbuf());
assert_eq!(format!(concat!()), "".to_strbuf());
assert_eq!(
concat!(1, 2i, 3u, 4f32, 4.0, 'a', true, ()),

View file

@ -41,15 +41,15 @@ impl fmt::Show for Custom {
}
pub fn main() {
assert_eq!(B1.to_str(), "B1".to_owned());
assert_eq!(B2.to_str(), "B2".to_owned());
assert_eq!(C1(3).to_str(), "C1(3)".to_owned());
assert_eq!(C2(B2).to_str(), "C2(B2)".to_owned());
assert_eq!(D1{ a: 2 }.to_str(), "D1 { a: 2 }".to_owned());
assert_eq!(E.to_str(), "E".to_owned());
assert_eq!(F(3).to_str(), "F(3)".to_owned());
assert_eq!(G(3, 4).to_str(), "G(3, 4)".to_owned());
assert_eq!(G(3, 4).to_str(), "G(3, 4)".to_owned());
assert_eq!(I{ a: 2, b: 4 }.to_str(), "I { a: 2, b: 4 }".to_owned());
assert_eq!(J(Custom).to_str(), "J(yay)".to_owned());
assert_eq!(B1.to_str(), "B1".to_strbuf());
assert_eq!(B2.to_str(), "B2".to_strbuf());
assert_eq!(C1(3).to_str(), "C1(3)".to_strbuf());
assert_eq!(C2(B2).to_str(), "C2(B2)".to_strbuf());
assert_eq!(D1{ a: 2 }.to_str(), "D1 { a: 2 }".to_strbuf());
assert_eq!(E.to_str(), "E".to_strbuf());
assert_eq!(F(3).to_str(), "F(3)".to_strbuf());
assert_eq!(G(3, 4).to_str(), "G(3, 4)".to_strbuf());
assert_eq!(G(3, 4).to_str(), "G(3, 4)".to_strbuf());
assert_eq!(I{ a: 2, b: 4 }.to_str(), "I { a: 2, b: 4 }".to_strbuf());
assert_eq!(J(Custom).to_str(), "J(yay)".to_strbuf());
}

View file

@ -28,7 +28,7 @@ enum Enum {
macro_rules! t {
($x:expr, $expected:expr) => {
assert_eq!(format!("{}", $x), $expected.to_owned())
assert_eq!(format!("{}", $x), $expected.to_strbuf())
}
}

View file

@ -23,8 +23,8 @@ macro_rules! check {
assert_eq!(size_of::<E>(), size_of::<$t>());
assert_eq!(V as $t, $v);
assert_eq!(C as $t, $v);
assert_eq!(format!("{:?}", V), "V".to_owned());
assert_eq!(format!("{:?}", C), "V".to_owned());
assert_eq!(format!("{:?}", V), "V".to_strbuf());
assert_eq!(format!("{:?}", C), "V".to_strbuf());
}
}
$m::check();

View file

@ -13,5 +13,5 @@
use std::os;
pub fn main() {
assert_eq!(os::getenv("TEST_EXEC_ENV"), Some("22".to_owned()));
assert_eq!(os::getenv("TEST_EXEC_ENV"), Some("22".to_strbuf()));
}

View file

@ -13,7 +13,7 @@
use s = std::num::strconv;
use to_str = std::num::strconv::float_to_str_common;
macro_rules! t(($a:expr, $b:expr) => { { let (r, _) = $a; assert_eq!(r, $b.to_owned()) } })
macro_rules! t(($a:expr, $b:expr) => { { let (r, _) = $a; assert_eq!(r, $b.to_strbuf()) } })
pub fn main() {
// Basic usage

View file

@ -17,5 +17,5 @@ pub fn main() {
let arr = [1,2,3];
let struc = Struc {a: 13u8, b: arr, c: 42};
let s = repr::repr_to_str(&struc);
assert_eq!(s, "Struc{a: 13u8, b: [1, 2, 3], c: 42}".to_owned());
assert_eq!(s, "Struc{a: 13u8, b: [1, 2, 3], c: 42}".to_strbuf());
}

View file

@ -14,5 +14,5 @@ pub fn main() {
let name = RefCell::new("rust");
let what = RefCell::new("rocks");
let msg = format!("{name:?} {:?}", &*what.borrow(), name=&*name.borrow());
assert_eq!(msg, "&\"rust\" &\"rocks\"".to_owned());
assert_eq!(msg, "&\"rust\" &\"rocks\"".to_strbuf());
}

View file

@ -222,5 +222,5 @@ fn test_order() {
}
assert_eq!(format!("{} {} {a} {b} {} {c}",
foo(), foo(), foo(), a=foo(), b=foo(), c=foo()),
"1 2 4 5 3 6".to_owned());
"1 2 4 5 3 6".to_strbuf());
}

View file

@ -22,8 +22,8 @@ fn check_strs(actual: &str, expected: &str) -> bool {
pub fn main() {
let mut table = HashMap::new();
table.insert("one".to_owned(), 1);
table.insert("two".to_owned(), 2);
assert!(check_strs(table.to_str(), "{one: 1, two: 2}") ||
check_strs(table.to_str(), "{two: 2, one: 1}"));
table.insert("one".to_strbuf(), 1);
table.insert("two".to_strbuf(), 2);
assert!(check_strs(table.to_str().as_slice(), "{one: 1, two: 2}") ||
check_strs(table.to_str().as_slice(), "{two: 2, one: 1}"));
}

View file

@ -159,7 +159,7 @@ pub fn check_strs(actual: &str, expected: &str) -> bool {
fn test_ascii_art_ctor() {
let art = AsciiArt(3, 3, '*');
assert!(check_strs(art.to_str(), "...\n...\n..."));
assert!(check_strs(art.to_str().as_slice(), "...\n...\n..."));
}
@ -168,7 +168,7 @@ fn test_add_pt() {
art.add_pt(0, 0);
art.add_pt(0, -10);
art.add_pt(1, 2);
assert!(check_strs(art.to_str(), "*..\n...\n.*."));
assert!(check_strs(art.to_str().as_slice(), "*..\n...\n.*."));
}
@ -176,7 +176,7 @@ fn test_shapes() {
let mut art = AsciiArt(4, 4, '*');
art.add_rect(Rect {top_left: Point {x: 0, y: 0}, size: Size {width: 4, height: 4}});
art.add_point(Point {x: 2, y: 2});
assert!(check_strs(art.to_str(), "****\n*..*\n*.**\n****"));
assert!(check_strs(art.to_str().as_slice(), "****\n*..*\n*.**\n****"));
}
pub fn main() {

View file

@ -36,12 +36,13 @@ fn main() {
let blah = "\u03c0\u042f\u97f3\u00e6\u221e";
let child_name = "child";
let child_dir = "process-spawn-with-unicode-params-" + blah;
let child_dir = format_strbuf!("process-spawn-with-unicode-params-{}",
blah);
// parameters sent to child / expected to be received from parent
let arg = blah;
let cwd = my_dir.join(Path::new(child_dir.clone()));
let env = ("RUST_TEST_PROC_SPAWN_UNICODE".to_owned(), blah.to_owned());
let env = ("RUST_TEST_PROC_SPAWN_UNICODE".to_strbuf(), blah.to_strbuf());
// am I the parent or the child?
if my_args.len() == 1 { // parent

View file

@ -64,6 +64,6 @@ pub fn main() {
// because `inner`s alignment was 4.
assert_eq!(mem::size_of::<Outer>(), m::size());
assert_eq!(y, "Outer{c8: 22u8, t: Inner{c64: 44u32}}".to_owned());
assert_eq!(y, "Outer{c8: 22u8, t: Inner{c64: 44u32}}".to_strbuf());
}
}

View file

@ -86,6 +86,6 @@ pub fn main() {
// because `Inner`s alignment was 4.
assert_eq!(mem::size_of::<Outer>(), m::m::size());
assert_eq!(y, "Outer{c8: 22u8, t: Inner{c64: 44u64}}".to_owned());
assert_eq!(y, "Outer{c8: 22u8, t: Inner{c64: 44u64}}".to_strbuf());
}
}

View file

@ -54,18 +54,8 @@ pub fn main() {
assert_eq!(map.find_equiv(&("cde")), Some(&c));
assert_eq!(map.find_equiv(&("def")), Some(&d));
assert_eq!(map.find_equiv(&("abc".to_owned())), Some(&a));
assert_eq!(map.find_equiv(&("bcd".to_owned())), Some(&b));
assert_eq!(map.find_equiv(&("cde".to_owned())), Some(&c));
assert_eq!(map.find_equiv(&("def".to_owned())), Some(&d));
assert_eq!(map.find_equiv(&Slice("abc")), Some(&a));
assert_eq!(map.find_equiv(&Slice("bcd")), Some(&b));
assert_eq!(map.find_equiv(&Slice("cde")), Some(&c));
assert_eq!(map.find_equiv(&Slice("def")), Some(&d));
assert_eq!(map.find_equiv(&Owned("abc".to_owned())), Some(&a));
assert_eq!(map.find_equiv(&Owned("bcd".to_owned())), Some(&b));
assert_eq!(map.find_equiv(&Owned("cde".to_owned())), Some(&c));
assert_eq!(map.find_equiv(&Owned("def".to_owned())), Some(&d));
}

View file

@ -26,7 +26,7 @@ use std::io::process::{Command, ExitSignal, ExitStatus};
pub fn main() {
let args = os::args();
let args = args.as_slice();
if args.len() >= 2 && args[1] == "signal".to_owned() {
if args.len() >= 2 && args[1].as_slice() == "signal" {
// Raise a segfault.
unsafe { *(0 as *mut int) = 0; }
} else {

View file

@ -22,5 +22,5 @@ pub fn main() {
let x = t_rec {c8: 22u8, t: a_tag(44u64)};
let y = format!("{:?}", x);
println!("y = {}", y);
assert_eq!(y, "t_rec{c8: 22u8, t: a_tag(44u64)}".to_owned());
assert_eq!(y, "t_rec{c8: 22u8, t: a_tag(44u64)}".to_strbuf());
}

View file

@ -19,7 +19,7 @@ enum color {
pub fn main() {
let act = format!("{:?}", red);
println!("{}", act);
assert_eq!("red".to_owned(), act);
assert_eq!("green".to_owned(), format!("{:?}", green));
assert_eq!("white".to_owned(), format!("{:?}", white));
assert_eq!("red".to_strbuf(), act);
assert_eq!("green".to_strbuf(), format!("{:?}", green));
assert_eq!("white".to_strbuf(), format!("{:?}", white));
}

View file

@ -63,7 +63,7 @@ iotest!(fn eventual_timeout() {
let (tx1, rx1) = channel();
let (_tx2, rx2) = channel::<()>();
native::task::spawn(proc() {
let _l = TcpListener::bind(host, port).unwrap().listen();
let _l = TcpListener::bind(host.as_slice(), port).unwrap().listen();
tx1.send(());
let _ = rx2.recv_opt();
});
@ -84,7 +84,7 @@ iotest!(fn timeout_success() {
let addr = next_test_ip4();
let host = addr.ip.to_str();
let port = addr.port;
let _l = TcpListener::bind(host, port).unwrap().listen();
let _l = TcpListener::bind(host.as_slice(), port).unwrap().listen();
assert!(TcpStream::connect_timeout(addr, 1000).is_ok());
})

View file

@ -64,7 +64,7 @@ fn main() {
builder.spawn(proc() {
let host = addr.ip.to_str();
let port = addr.port;
match TcpStream::connect(host, port) {
match TcpStream::connect(host.as_slice(), port) {
Ok(stream) => {
let mut stream = stream;
stream.write([1]);

View file

@ -27,10 +27,10 @@ fn checktests() {
let tests = __test::TESTS;
assert!(
tests.iter().any(|t| t.desc.name.to_str() == "shouldignore".to_owned() &&
tests.iter().any(|t| t.desc.name.to_str().as_slice() == "shouldignore" &&
t.desc.ignore));
assert!(
tests.iter().any(|t| t.desc.name.to_str() == "shouldnotignore".to_owned() &&
tests.iter().any(|t| t.desc.name.to_str().as_slice() == "shouldnotignore" &&
!t.desc.ignore));
}

View file

@ -9,12 +9,12 @@
// except according to those terms.
pub fn main() {
assert_eq!((vec!(0, 1)).to_str(), "[0, 1]".to_owned());
assert_eq!((&[1, 2]).to_str(), "[1, 2]".to_owned());
assert_eq!((vec!(0, 1)).to_str(), "[0, 1]".to_strbuf());
assert_eq!((&[1, 2]).to_str(), "[1, 2]".to_strbuf());
let foo = vec!(3, 4);
let bar = &[4, 5];
assert_eq!(foo.to_str(), "[3, 4]".to_owned());
assert_eq!(bar.to_str(), "[4, 5]".to_owned());
assert_eq!(foo.to_str(), "[3, 4]".to_strbuf());
assert_eq!(bar.to_str(), "[4, 5]".to_strbuf());
}