diff options
| author | Richo Healey <richo@psych0tik.net> | 2014-04-15 18:17:48 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2014-04-18 17:25:34 -0700 |
| commit | 919889a1d688a6bbe2edac8705f048f06b1b455c (patch) | |
| tree | 322a69fa39bdaf37bbfffc84020acbd4c87871d0 /src/libstd | |
| parent | b75683cadf6c4c55360202cd6a0106be80532451 (diff) | |
| download | rust-919889a1d688a6bbe2edac8705f048f06b1b455c.tar.gz rust-919889a1d688a6bbe2edac8705f048f06b1b455c.zip | |
Replace all ~"" with "".to_owned()
Diffstat (limited to 'src/libstd')
37 files changed, 543 insertions, 505 deletions
diff --git a/src/libstd/any.rs b/src/libstd/any.rs index e204e082f4b..5a6ecdb1f21 100644 --- a/src/libstd/any.rs +++ b/src/libstd/any.rs @@ -164,6 +164,7 @@ impl<'a> fmt::Show for &'a Any { mod tests { use prelude::*; use super::*; + use str::StrSlice; #[deriving(Eq, Show)] struct Test; @@ -290,13 +291,13 @@ mod tests { fn test_show() { let a = ~8u as ~Any; let b = ~Test as ~Any; - assert_eq!(format!("{}", a), ~"~Any"); - assert_eq!(format!("{}", b), ~"~Any"); + assert_eq!(format!("{}", a), "~Any".to_owned()); + assert_eq!(format!("{}", b), "~Any".to_owned()); let a = &8u as &Any; let b = &Test as &Any; - assert_eq!(format!("{}", a), ~"&Any"); - assert_eq!(format!("{}", b), ~"&Any"); + assert_eq!(format!("{}", a), "&Any".to_owned()); + assert_eq!(format!("{}", b), "&Any".to_owned()); } } diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index a52658da209..6ffe0cfe57d 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -487,6 +487,7 @@ mod tests { use str::from_char; use char::from_u32; use vec::Vec; + use str::StrSlice; macro_rules! v2ascii ( ( [$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]); @@ -536,14 +537,14 @@ mod tests { // FIXME: #5475 borrowchk error, owned vectors do not live long enough // if chained-from directly let v = ~[40u8, 32u8, 59u8]; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59])); - let v = ~"( ;"; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59])); + let v = "( ;".to_owned(); assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59])); - assert_eq!("abCDef&?#".to_ascii().to_lower().into_str(), ~"abcdef&?#"); - assert_eq!("abCDef&?#".to_ascii().to_upper().into_str(), ~"ABCDEF&?#"); + assert_eq!("abCDef&?#".to_ascii().to_lower().into_str(), "abcdef&?#".to_owned()); + assert_eq!("abCDef&?#".to_ascii().to_upper().into_str(), "ABCDEF&?#".to_owned()); - assert_eq!("".to_ascii().to_lower().into_str(), ~""); - assert_eq!("YMCA".to_ascii().to_lower().into_str(), ~"ymca"); - assert_eq!("abcDEFxyz:.;".to_ascii().to_upper().into_str(), ~"ABCDEFXYZ:.;"); + assert_eq!("".to_ascii().to_lower().into_str(), "".to_owned()); + assert_eq!("YMCA".to_ascii().to_lower().into_str(), "ymca".to_owned()); + assert_eq!("abcDEFxyz:.;".to_ascii().to_upper().into_str(), "ABCDEFXYZ:.;".to_owned()); assert!("aBcDeF&?#".to_ascii().eq_ignore_case("AbCdEf&?#".to_ascii())); @@ -555,18 +556,19 @@ mod tests { #[test] fn test_ascii_vec_ng() { - assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_lower()).into_str(), ~"abcdef&?#"); - assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_upper()).into_str(), ~"ABCDEF&?#"); - - assert_eq!(Vec::from_slice("".to_ascii().to_lower()).into_str(), ~""); - assert_eq!(Vec::from_slice("YMCA".to_ascii().to_lower()).into_str(), ~"ymca"); + assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_lower()).into_str(), + "abcdef&?#".to_owned()); + assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_upper()).into_str(), + "ABCDEF&?#".to_owned()); + assert_eq!(Vec::from_slice("".to_ascii().to_lower()).into_str(), "".to_owned()); + assert_eq!(Vec::from_slice("YMCA".to_ascii().to_lower()).into_str(), "ymca".to_owned()); assert_eq!(Vec::from_slice("abcDEFxyz:.;".to_ascii().to_upper()).into_str(), - ~"ABCDEFXYZ:.;"); + "ABCDEFXYZ:.;".to_owned()); } #[test] fn test_owned_ascii_vec() { - assert_eq!((~"( ;").into_ascii(), v2ascii!(~[40, 32, 59])); + assert_eq!(("( ;".to_owned()).into_ascii(), v2ascii!(~[40, 32, 59])); assert_eq!((~[40u8, 32u8, 59u8]).into_ascii(), v2ascii!(~[40, 32, 59])); } @@ -578,8 +580,8 @@ mod tests { #[test] fn test_ascii_into_str() { - assert_eq!(v2ascii!(~[40, 32, 59]).into_str(), ~"( ;"); - assert_eq!(vec2ascii!(40, 32, 59).into_str(), ~"( ;"); + assert_eq!(v2ascii!(~[40, 32, 59]).into_str(), "( ;".to_owned()); + assert_eq!(vec2ascii!(40, 32, 59).into_str(), "( ;".to_owned()); } #[test] @@ -626,14 +628,14 @@ mod tests { assert_eq!((~[40u8, 32u8, 59u8]).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59]))); assert_eq!((~[127u8, 128u8, 255u8]).into_ascii_opt(), None); - assert_eq!((~"( ;").into_ascii_opt(), Some(v2ascii!(~[40, 32, 59]))); - assert_eq!((~"zoä华").into_ascii_opt(), None); + assert_eq!(("( ;".to_owned()).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59]))); + assert_eq!(("zoä华".to_owned()).into_ascii_opt(), None); } #[test] fn test_to_ascii_upper() { - assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), ~"URL()URL()URL()üRL"); - assert_eq!("hıKß".to_ascii_upper(), ~"HıKß"); + assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL".to_owned()); + assert_eq!("hıKß".to_ascii_upper(), "HıKß".to_owned()); let mut i = 0; while i <= 500 { @@ -647,9 +649,9 @@ mod tests { #[test] fn test_to_ascii_lower() { - assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), ~"url()url()url()Ürl"); + assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl".to_owned()); // Dotted capital I, Kelvin sign, Sharp S. - assert_eq!("HİKß".to_ascii_lower(), ~"hİKß"); + assert_eq!("HİKß".to_ascii_lower(), "hİKß".to_owned()); let mut i = 0; while i <= 500 { @@ -663,8 +665,9 @@ mod tests { #[test] fn test_into_ascii_upper() { - assert_eq!((~"url()URL()uRl()ürl").into_ascii_upper(), ~"URL()URL()URL()üRL"); - assert_eq!((~"hıKß").into_ascii_upper(), ~"HıKß"); + assert_eq!(("url()URL()uRl()ürl".to_owned()).into_ascii_upper(), + "URL()URL()URL()üRL".to_owned()); + assert_eq!(("hıKß".to_owned()).into_ascii_upper(), "HıKß".to_owned()); let mut i = 0; while i <= 500 { @@ -678,9 +681,10 @@ mod tests { #[test] fn test_into_ascii_lower() { - assert_eq!((~"url()URL()uRl()Ürl").into_ascii_lower(), ~"url()url()url()Ürl"); + assert_eq!(("url()URL()uRl()Ürl".to_owned()).into_ascii_lower(), + "url()url()url()Ürl".to_owned()); // Dotted capital I, Kelvin sign, Sharp S. - assert_eq!((~"HİKß").into_ascii_lower(), ~"hİKß"); + assert_eq!(("HİKß".to_owned()).into_ascii_lower(), "hİKß".to_owned()); let mut i = 0; while i <= 500 { @@ -716,12 +720,12 @@ mod tests { #[test] fn test_to_str() { let s = Ascii{ chr: 't' as u8 }.to_str(); - assert_eq!(s, ~"t"); + assert_eq!(s, "t".to_owned()); } #[test] fn test_show() { let c = Ascii { chr: 't' as u8 }; - assert_eq!(format!("{}", c), ~"t"); + assert_eq!(format!("{}", c), "t".to_owned()); } } diff --git a/src/libstd/bool.rs b/src/libstd/bool.rs index 05efa3eab79..5a07c860b5d 100644 --- a/src/libstd/bool.rs +++ b/src/libstd/bool.rs @@ -199,6 +199,7 @@ impl Default for bool { mod tests { use prelude::*; use super::to_bit; + use str::StrSlice; #[test] fn test_to_bit() { @@ -268,8 +269,8 @@ mod tests { #[test] fn test_to_str() { - assert_eq!(false.to_str(), ~"false"); - assert_eq!(true.to_str(), ~"true"); + assert_eq!(false.to_str(), "false".to_owned()); + assert_eq!(true.to_str(), "true".to_owned()); } #[test] diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index a7234eeb1d5..310bc861cd3 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -428,6 +428,7 @@ mod tests { use super::*; use libc; use ptr; + use str::StrSlice; #[test] fn test_str_multistring_parsing() { @@ -638,7 +639,7 @@ mod tests { #[test] fn test_clone_noleak() { fn foo(f: |c: &CString|) { - let s = ~"test"; + let s = "test".to_owned(); let c = s.to_c_str(); // give the closure a non-owned CString let mut c_ = c.with_ref(|c| unsafe { CString::new(c, false) } ); diff --git a/src/libstd/cast.rs b/src/libstd/cast.rs index f9f9e395f2e..0fb6f30e8a1 100644 --- a/src/libstd/cast.rs +++ b/src/libstd/cast.rs @@ -108,6 +108,7 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T { mod tests { use cast::{bump_box_refcount, transmute}; use raw; + use str::StrSlice; #[test] fn test_transmute_copy() { @@ -117,13 +118,13 @@ mod tests { #[test] fn test_bump_managed_refcount() { unsafe { - let managed = @~"box box box"; // refcount 1 + let managed = @"box box box".to_owned(); // refcount 1 bump_box_refcount(managed); // refcount 2 let ptr: *int = transmute(managed); // refcount 2 let _box1: @~str = ::cast::transmute_copy(&ptr); let _box2: @~str = ::cast::transmute_copy(&ptr); - assert!(*_box1 == ~"box box box"); - assert!(*_box2 == ~"box box box"); + assert!(*_box1 == "box box box".to_owned()); + assert!(*_box2 == "box box box".to_owned()); // Will destroy _box1 and _box2. Without the bump, this would // use-after-free. With too many bumps, it would leak. } @@ -142,7 +143,7 @@ mod tests { #[test] fn test_transmute2() { unsafe { - assert_eq!(~[76u8], transmute(~"L")); + assert_eq!(~[76u8], transmute("L".to_owned())); } } } diff --git a/src/libstd/char.rs b/src/libstd/char.rs index 67c046986d3..228db221cfc 100644 --- a/src/libstd/char.rs +++ b/src/libstd/char.rs @@ -779,19 +779,19 @@ fn test_escape_default() { escape_default(c, |c| { result.push_char(c); }); return result.into_owned(); } - assert_eq!(string('\n'), ~"\\n"); - assert_eq!(string('\r'), ~"\\r"); - assert_eq!(string('\''), ~"\\'"); - assert_eq!(string('"'), ~"\\\""); - assert_eq!(string(' '), ~" "); - assert_eq!(string('a'), ~"a"); - assert_eq!(string('~'), ~"~"); - assert_eq!(string('\x00'), ~"\\x00"); - assert_eq!(string('\x1f'), ~"\\x1f"); - assert_eq!(string('\x7f'), ~"\\x7f"); - assert_eq!(string('\xff'), ~"\\xff"); - assert_eq!(string('\u011b'), ~"\\u011b"); - assert_eq!(string('\U0001d4b6'), ~"\\U0001d4b6"); + assert_eq!(string('\n'), "\\n".to_owned()); + assert_eq!(string('\r'), "\\r".to_owned()); + assert_eq!(string('\''), "\\'".to_owned()); + assert_eq!(string('"'), "\\\"".to_owned()); + assert_eq!(string(' '), " ".to_owned()); + assert_eq!(string('a'), "a".to_owned()); + assert_eq!(string('~'), "~".to_owned()); + assert_eq!(string('\x00'), "\\x00".to_owned()); + assert_eq!(string('\x1f'), "\\x1f".to_owned()); + assert_eq!(string('\x7f'), "\\x7f".to_owned()); + assert_eq!(string('\xff'), "\\xff".to_owned()); + assert_eq!(string('\u011b'), "\\u011b".to_owned()); + assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned()); } #[test] @@ -801,19 +801,19 @@ fn test_escape_unicode() { escape_unicode(c, |c| { result.push_char(c); }); return result.into_owned(); } - assert_eq!(string('\x00'), ~"\\x00"); - assert_eq!(string('\n'), ~"\\x0a"); - assert_eq!(string(' '), ~"\\x20"); - assert_eq!(string('a'), ~"\\x61"); - assert_eq!(string('\u011b'), ~"\\u011b"); - assert_eq!(string('\U0001d4b6'), ~"\\U0001d4b6"); + assert_eq!(string('\x00'), "\\x00".to_owned()); + assert_eq!(string('\n'), "\\x0a".to_owned()); + assert_eq!(string(' '), "\\x20".to_owned()); + assert_eq!(string('a'), "\\x61".to_owned()); + assert_eq!(string('\u011b'), "\\u011b".to_owned()); + assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned()); } #[test] fn test_to_str() { use to_str::ToStr; let s = 't'.to_str(); - assert_eq!(s, ~"t"); + assert_eq!(s, "t".to_owned()); } #[test] diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index f4f4be7172c..8e4d8707cca 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -34,12 +34,12 @@ arguments directly while performing minimal allocations. Some examples of the `format!` extension are: ```rust -format!("Hello"); // => ~"Hello" -format!("Hello, {:s}!", "world"); // => ~"Hello, world!" -format!("The number is {:d}", 1); // => ~"The number is 1" -format!("{:?}", ~[3, 4]); // => ~"~[3, 4]" -format!("{value}", value=4); // => ~"4" -format!("{} {}", 1, 2); // => ~"1 2" +format!("Hello"); // => "Hello".to_owned() +format!("Hello, {:s}!", "world"); // => "Hello, world!".to_owned() +format!("The number is {:d}", 1); // => "The number is 1".to_owned() +format!("{:?}", ~[3, 4]); // => "~[3, 4]".to_owned() +format!("{value}", value=4); // => "4".to_owned() +format!("{} {}", 1, 2); // => "1 2".to_owned() ``` From these, you can see that the first argument is a format string. It is @@ -62,7 +62,7 @@ iterator over the argument. Each time a "next argument" specifier is seen, the iterator advances. This leads to behavior like this: ```rust -format!("{1} {} {0} {}", 1, 2); // => ~"2 1 1 2" +format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2".to_owned() ``` The internal iterator over the argument has not been advanced by the time the @@ -89,9 +89,9 @@ identifier '=' expression For example, the following `format!` expressions all use named argument: ```rust -format!("{argument}", argument = "test"); // => ~"test" -format!("{name} {}", 1, name = 2); // => ~"2 1" -format!("{a:s} {c:d} {b:?}", a="a", b=(), c=3); // => ~"a 3 ()" +format!("{argument}", argument = "test"); // => "test".to_owned() +format!("{name} {}", 1, name = 2); // => "2 1".to_owned() +format!("{a:s} {c:d} {b:?}", a="a", b=(), c=3); // => "a 3 ()".to_owned() ``` It is illegal to put positional parameters (those without names) after arguments @@ -330,7 +330,7 @@ to reference the string value of the argument which was selected upon. As an example: ```rust -format!("{0, select, other{#}}", "hello"); // => ~"hello" +format!("{0, select, other{#}}", "hello"); // => "hello".to_owned() ``` This example is the equivalent of `{0:s}` essentially. @@ -771,7 +771,7 @@ pub unsafe fn write_unsafe(output: &mut io::Writer, /// use std::fmt; /// /// let s = format_args!(fmt::format, "Hello, {}!", "world"); -/// assert_eq!(s, ~"Hello, world!"); +/// assert_eq!(s, "Hello, world!".to_owned()); /// ``` pub fn format(args: &Arguments) -> ~str { unsafe { format_unsafe(args.fmt, args.args) } diff --git a/src/libstd/fmt/num.rs b/src/libstd/fmt/num.rs index 88b21f1f87b..1abfca50b54 100644 --- a/src/libstd/fmt/num.rs +++ b/src/libstd/fmt/num.rs @@ -138,7 +138,7 @@ pub struct RadixFmt<T, R>(T, R); /// /// ~~~ /// use std::fmt::radix; -/// assert_eq!(format!("{}", radix(55, 36)), ~"1j"); +/// assert_eq!(format!("{}", radix(55, 36)), "1j".to_owned()); /// ~~~ pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> { RadixFmt(x, Radix::new(base)) @@ -192,6 +192,7 @@ mod tests { use fmt::radix; use super::{Binary, Octal, Decimal, LowerHex, UpperHex}; use super::{GenericRadix, Radix}; + use str::StrSlice; #[test] fn test_radix_base() { @@ -243,143 +244,143 @@ mod tests { // Formatting integers should select the right implementation based off // the type of the argument. Also, hex/octal/binary should be defined // for integers, but they shouldn't emit the negative sign. - assert_eq!(format!("{}", 1i), ~"1"); - assert_eq!(format!("{}", 1i8), ~"1"); - assert_eq!(format!("{}", 1i16), ~"1"); - assert_eq!(format!("{}", 1i32), ~"1"); - assert_eq!(format!("{}", 1i64), ~"1"); - assert_eq!(format!("{:d}", -1i), ~"-1"); - assert_eq!(format!("{:d}", -1i8), ~"-1"); - assert_eq!(format!("{:d}", -1i16), ~"-1"); - assert_eq!(format!("{:d}", -1i32), ~"-1"); - assert_eq!(format!("{:d}", -1i64), ~"-1"); - assert_eq!(format!("{:t}", 1i), ~"1"); - assert_eq!(format!("{:t}", 1i8), ~"1"); - assert_eq!(format!("{:t}", 1i16), ~"1"); - assert_eq!(format!("{:t}", 1i32), ~"1"); - assert_eq!(format!("{:t}", 1i64), ~"1"); - assert_eq!(format!("{:x}", 1i), ~"1"); - assert_eq!(format!("{:x}", 1i8), ~"1"); - assert_eq!(format!("{:x}", 1i16), ~"1"); - assert_eq!(format!("{:x}", 1i32), ~"1"); - assert_eq!(format!("{:x}", 1i64), ~"1"); - assert_eq!(format!("{:X}", 1i), ~"1"); - assert_eq!(format!("{:X}", 1i8), ~"1"); - assert_eq!(format!("{:X}", 1i16), ~"1"); - assert_eq!(format!("{:X}", 1i32), ~"1"); - assert_eq!(format!("{:X}", 1i64), ~"1"); - assert_eq!(format!("{:o}", 1i), ~"1"); - assert_eq!(format!("{:o}", 1i8), ~"1"); - assert_eq!(format!("{:o}", 1i16), ~"1"); - assert_eq!(format!("{:o}", 1i32), ~"1"); - assert_eq!(format!("{:o}", 1i64), ~"1"); - - assert_eq!(format!("{}", 1u), ~"1"); - assert_eq!(format!("{}", 1u8), ~"1"); - assert_eq!(format!("{}", 1u16), ~"1"); - assert_eq!(format!("{}", 1u32), ~"1"); - assert_eq!(format!("{}", 1u64), ~"1"); - assert_eq!(format!("{:u}", 1u), ~"1"); - assert_eq!(format!("{:u}", 1u8), ~"1"); - assert_eq!(format!("{:u}", 1u16), ~"1"); - assert_eq!(format!("{:u}", 1u32), ~"1"); - assert_eq!(format!("{:u}", 1u64), ~"1"); - assert_eq!(format!("{:t}", 1u), ~"1"); - assert_eq!(format!("{:t}", 1u8), ~"1"); - assert_eq!(format!("{:t}", 1u16), ~"1"); - assert_eq!(format!("{:t}", 1u32), ~"1"); - assert_eq!(format!("{:t}", 1u64), ~"1"); - assert_eq!(format!("{:x}", 1u), ~"1"); - assert_eq!(format!("{:x}", 1u8), ~"1"); - assert_eq!(format!("{:x}", 1u16), ~"1"); - assert_eq!(format!("{:x}", 1u32), ~"1"); - assert_eq!(format!("{:x}", 1u64), ~"1"); - assert_eq!(format!("{:X}", 1u), ~"1"); - assert_eq!(format!("{:X}", 1u8), ~"1"); - assert_eq!(format!("{:X}", 1u16), ~"1"); - assert_eq!(format!("{:X}", 1u32), ~"1"); - assert_eq!(format!("{:X}", 1u64), ~"1"); - assert_eq!(format!("{:o}", 1u), ~"1"); - assert_eq!(format!("{:o}", 1u8), ~"1"); - assert_eq!(format!("{:o}", 1u16), ~"1"); - assert_eq!(format!("{:o}", 1u32), ~"1"); - assert_eq!(format!("{:o}", 1u64), ~"1"); + assert_eq!(format!("{}", 1i), "1".to_owned()); + assert_eq!(format!("{}", 1i8), "1".to_owned()); + assert_eq!(format!("{}", 1i16), "1".to_owned()); + assert_eq!(format!("{}", 1i32), "1".to_owned()); + assert_eq!(format!("{}", 1i64), "1".to_owned()); + assert_eq!(format!("{:d}", -1i), "-1".to_owned()); + assert_eq!(format!("{:d}", -1i8), "-1".to_owned()); + assert_eq!(format!("{:d}", -1i16), "-1".to_owned()); + assert_eq!(format!("{:d}", -1i32), "-1".to_owned()); + assert_eq!(format!("{:d}", -1i64), "-1".to_owned()); + assert_eq!(format!("{:t}", 1i), "1".to_owned()); + assert_eq!(format!("{:t}", 1i8), "1".to_owned()); + assert_eq!(format!("{:t}", 1i16), "1".to_owned()); + assert_eq!(format!("{:t}", 1i32), "1".to_owned()); + assert_eq!(format!("{:t}", 1i64), "1".to_owned()); + assert_eq!(format!("{:x}", 1i), "1".to_owned()); + assert_eq!(format!("{:x}", 1i8), "1".to_owned()); + assert_eq!(format!("{:x}", 1i16), "1".to_owned()); + assert_eq!(format!("{:x}", 1i32), "1".to_owned()); + assert_eq!(format!("{:x}", 1i64), "1".to_owned()); + assert_eq!(format!("{:X}", 1i), "1".to_owned()); + assert_eq!(format!("{:X}", 1i8), "1".to_owned()); + assert_eq!(format!("{:X}", 1i16), "1".to_owned()); + assert_eq!(format!("{:X}", 1i32), "1".to_owned()); + assert_eq!(format!("{:X}", 1i64), "1".to_owned()); + assert_eq!(format!("{:o}", 1i), "1".to_owned()); + assert_eq!(format!("{:o}", 1i8), "1".to_owned()); + assert_eq!(format!("{:o}", 1i16), "1".to_owned()); + assert_eq!(format!("{:o}", 1i32), "1".to_owned()); + assert_eq!(format!("{:o}", 1i64), "1".to_owned()); + + assert_eq!(format!("{}", 1u), "1".to_owned()); + assert_eq!(format!("{}", 1u8), "1".to_owned()); + assert_eq!(format!("{}", 1u16), "1".to_owned()); + assert_eq!(format!("{}", 1u32), "1".to_owned()); + assert_eq!(format!("{}", 1u64), "1".to_owned()); + assert_eq!(format!("{:u}", 1u), "1".to_owned()); + assert_eq!(format!("{:u}", 1u8), "1".to_owned()); + assert_eq!(format!("{:u}", 1u16), "1".to_owned()); + assert_eq!(format!("{:u}", 1u32), "1".to_owned()); + assert_eq!(format!("{:u}", 1u64), "1".to_owned()); + assert_eq!(format!("{:t}", 1u), "1".to_owned()); + assert_eq!(format!("{:t}", 1u8), "1".to_owned()); + assert_eq!(format!("{:t}", 1u16), "1".to_owned()); + assert_eq!(format!("{:t}", 1u32), "1".to_owned()); + assert_eq!(format!("{:t}", 1u64), "1".to_owned()); + assert_eq!(format!("{:x}", 1u), "1".to_owned()); + assert_eq!(format!("{:x}", 1u8), "1".to_owned()); + assert_eq!(format!("{:x}", 1u16), "1".to_owned()); + assert_eq!(format!("{:x}", 1u32), "1".to_owned()); + assert_eq!(format!("{:x}", 1u64), "1".to_owned()); + assert_eq!(format!("{:X}", 1u), "1".to_owned()); + assert_eq!(format!("{:X}", 1u8), "1".to_owned()); + assert_eq!(format!("{:X}", 1u16), "1".to_owned()); + assert_eq!(format!("{:X}", 1u32), "1".to_owned()); + assert_eq!(format!("{:X}", 1u64), "1".to_owned()); + assert_eq!(format!("{:o}", 1u), "1".to_owned()); + assert_eq!(format!("{:o}", 1u8), "1".to_owned()); + assert_eq!(format!("{:o}", 1u16), "1".to_owned()); + assert_eq!(format!("{:o}", 1u32), "1".to_owned()); + assert_eq!(format!("{:o}", 1u64), "1".to_owned()); // Test a larger number - assert_eq!(format!("{:t}", 55), ~"110111"); - assert_eq!(format!("{:o}", 55), ~"67"); - assert_eq!(format!("{:d}", 55), ~"55"); - assert_eq!(format!("{:x}", 55), ~"37"); - assert_eq!(format!("{:X}", 55), ~"37"); + assert_eq!(format!("{:t}", 55), "110111".to_owned()); + assert_eq!(format!("{:o}", 55), "67".to_owned()); + assert_eq!(format!("{:d}", 55), "55".to_owned()); + assert_eq!(format!("{:x}", 55), "37".to_owned()); + assert_eq!(format!("{:X}", 55), "37".to_owned()); } #[test] fn test_format_int_zero() { - assert_eq!(format!("{}", 0i), ~"0"); - assert_eq!(format!("{:d}", 0i), ~"0"); - assert_eq!(format!("{:t}", 0i), ~"0"); - assert_eq!(format!("{:o}", 0i), ~"0"); - assert_eq!(format!("{:x}", 0i), ~"0"); - assert_eq!(format!("{:X}", 0i), ~"0"); - - assert_eq!(format!("{}", 0u), ~"0"); - assert_eq!(format!("{:u}", 0u), ~"0"); - assert_eq!(format!("{:t}", 0u), ~"0"); - assert_eq!(format!("{:o}", 0u), ~"0"); - assert_eq!(format!("{:x}", 0u), ~"0"); - assert_eq!(format!("{:X}", 0u), ~"0"); + assert_eq!(format!("{}", 0i), "0".to_owned()); + assert_eq!(format!("{:d}", 0i), "0".to_owned()); + assert_eq!(format!("{:t}", 0i), "0".to_owned()); + assert_eq!(format!("{:o}", 0i), "0".to_owned()); + assert_eq!(format!("{:x}", 0i), "0".to_owned()); + assert_eq!(format!("{:X}", 0i), "0".to_owned()); + + assert_eq!(format!("{}", 0u), "0".to_owned()); + assert_eq!(format!("{:u}", 0u), "0".to_owned()); + assert_eq!(format!("{:t}", 0u), "0".to_owned()); + assert_eq!(format!("{:o}", 0u), "0".to_owned()); + assert_eq!(format!("{:x}", 0u), "0".to_owned()); + assert_eq!(format!("{:X}", 0u), "0".to_owned()); } #[test] fn test_format_int_flags() { - assert_eq!(format!("{:3d}", 1), ~" 1"); - assert_eq!(format!("{:>3d}", 1), ~" 1"); - assert_eq!(format!("{:>+3d}", 1), ~" +1"); - assert_eq!(format!("{:<3d}", 1), ~"1 "); - assert_eq!(format!("{:#d}", 1), ~"1"); - assert_eq!(format!("{:#x}", 10), ~"0xa"); - assert_eq!(format!("{:#X}", 10), ~"0xA"); - assert_eq!(format!("{:#5x}", 10), ~" 0xa"); - assert_eq!(format!("{:#o}", 10), ~"0o12"); - assert_eq!(format!("{:08x}", 10), ~"0000000a"); - assert_eq!(format!("{:8x}", 10), ~" a"); - assert_eq!(format!("{:<8x}", 10), ~"a "); - assert_eq!(format!("{:>8x}", 10), ~" a"); - assert_eq!(format!("{:#08x}", 10), ~"0x00000a"); - assert_eq!(format!("{:08d}", -10), ~"-0000010"); - assert_eq!(format!("{:x}", -1u8), ~"ff"); - assert_eq!(format!("{:X}", -1u8), ~"FF"); - assert_eq!(format!("{:t}", -1u8), ~"11111111"); - assert_eq!(format!("{:o}", -1u8), ~"377"); - assert_eq!(format!("{:#x}", -1u8), ~"0xff"); - assert_eq!(format!("{:#X}", -1u8), ~"0xFF"); - assert_eq!(format!("{:#t}", -1u8), ~"0b11111111"); - assert_eq!(format!("{:#o}", -1u8), ~"0o377"); + assert_eq!(format!("{:3d}", 1), " 1".to_owned()); + assert_eq!(format!("{:>3d}", 1), " 1".to_owned()); + assert_eq!(format!("{:>+3d}", 1), " +1".to_owned()); + assert_eq!(format!("{:<3d}", 1), "1 ".to_owned()); + assert_eq!(format!("{:#d}", 1), "1".to_owned()); + assert_eq!(format!("{:#x}", 10), "0xa".to_owned()); + assert_eq!(format!("{:#X}", 10), "0xA".to_owned()); + assert_eq!(format!("{:#5x}", 10), " 0xa".to_owned()); + assert_eq!(format!("{:#o}", 10), "0o12".to_owned()); + assert_eq!(format!("{:08x}", 10), "0000000a".to_owned()); + assert_eq!(format!("{:8x}", 10), " a".to_owned()); + assert_eq!(format!("{:<8x}", 10), "a ".to_owned()); + assert_eq!(format!("{:>8x}", 10), " a".to_owned()); + assert_eq!(format!("{:#08x}", 10), "0x00000a".to_owned()); + assert_eq!(format!("{:08d}", -10), "-0000010".to_owned()); + assert_eq!(format!("{:x}", -1u8), "ff".to_owned()); + assert_eq!(format!("{:X}", -1u8), "FF".to_owned()); + assert_eq!(format!("{:t}", -1u8), "11111111".to_owned()); + assert_eq!(format!("{:o}", -1u8), "377".to_owned()); + assert_eq!(format!("{:#x}", -1u8), "0xff".to_owned()); + assert_eq!(format!("{:#X}", -1u8), "0xFF".to_owned()); + assert_eq!(format!("{:#t}", -1u8), "0b11111111".to_owned()); + assert_eq!(format!("{:#o}", -1u8), "0o377".to_owned()); } #[test] fn test_format_int_sign_padding() { - assert_eq!(format!("{:+5d}", 1), ~" +1"); - assert_eq!(format!("{:+5d}", -1), ~" -1"); - assert_eq!(format!("{:05d}", 1), ~"00001"); - assert_eq!(format!("{:05d}", -1), ~"-0001"); - assert_eq!(format!("{:+05d}", 1), ~"+0001"); - assert_eq!(format!("{:+05d}", -1), ~"-0001"); + assert_eq!(format!("{:+5d}", 1), " +1".to_owned()); + assert_eq!(format!("{:+5d}", -1), " -1".to_owned()); + assert_eq!(format!("{:05d}", 1), "00001".to_owned()); + assert_eq!(format!("{:05d}", -1), "-0001".to_owned()); + assert_eq!(format!("{:+05d}", 1), "+0001".to_owned()); + assert_eq!(format!("{:+05d}", -1), "-0001".to_owned()); } #[test] fn test_format_int_twos_complement() { use {i8, i16, i32, i64}; - assert_eq!(format!("{}", i8::MIN), ~"-128"); - assert_eq!(format!("{}", i16::MIN), ~"-32768"); - assert_eq!(format!("{}", i32::MIN), ~"-2147483648"); - assert_eq!(format!("{}", i64::MIN), ~"-9223372036854775808"); + assert_eq!(format!("{}", i8::MIN), "-128".to_owned()); + assert_eq!(format!("{}", i16::MIN), "-32768".to_owned()); + assert_eq!(format!("{}", i32::MIN), "-2147483648".to_owned()); + assert_eq!(format!("{}", i64::MIN), "-9223372036854775808".to_owned()); } #[test] fn test_format_radix() { - assert_eq!(format!("{:04}", radix(3, 2)), ~"0011"); - assert_eq!(format!("{}", radix(55, 36)), ~"1j"); + assert_eq!(format!("{:04}", radix(3, 2)), "0011".to_owned()); + assert_eq!(format!("{}", radix(55, 36)), "1j".to_owned()); } #[test] diff --git a/src/libstd/hash/mod.rs b/src/libstd/hash/mod.rs index 5e63f59f761..ffb41e9781b 100644 --- a/src/libstd/hash/mod.rs +++ b/src/libstd/hash/mod.rs @@ -27,8 +27,8 @@ * phone: u64, * } * - * let person1 = Person { id: 5, name: ~"Janet", phone: 555_666_7777 }; - * let person2 = Person { id: 5, name: ~"Bob", phone: 555_666_7777 }; + * let person1 = Person { id: 5, name: "Janet".to_owned(), phone: 555_666_7777 }; + * let person2 = Person { id: 5, name: "Bob".to_owned(), phone: 555_666_7777 }; * * assert!(hash::hash(&person1) != hash::hash(&person2)); * ``` @@ -54,8 +54,8 @@ * } * } * - * let person1 = Person { id: 5, name: ~"Janet", phone: 555_666_7777 }; - * let person2 = Person { id: 5, name: ~"Bob", phone: 555_666_7777 }; + * let person1 = Person { id: 5, name: "Janet".to_owned(), phone: 555_666_7777 }; + * let person2 = Person { id: 5, name: "Bob".to_owned(), phone: 555_666_7777 }; * * assert!(hash::hash(&person1) == hash::hash(&person2)); * ``` diff --git a/src/libstd/hash/sip.rs b/src/libstd/hash/sip.rs index eee8e416231..794c4ee62ff 100644 --- a/src/libstd/hash/sip.rs +++ b/src/libstd/hash/sip.rs @@ -361,6 +361,10 @@ mod tests { extern crate test; use prelude::*; use num::ToStrRadix; + use option::{Some, None}; + use str::{Str,StrSlice}; + use strbuf::StrBuf; + use slice::{Vector, ImmutableVector, OwnedVector}; use self::test::Bencher; use super::super::Hash; @@ -640,7 +644,7 @@ officia deserunt mollit anim id est laborum."; let compound = Compound { x: 1, y: 2, - z: ~"foobarbaz", + z: "foobarbaz".to_owned(), }; b.iter(|| { assert_eq!(hash(&compound), 15783192367317361799); diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index c541eb91d06..298e9df6d68 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -372,6 +372,7 @@ mod test { use super::*; use super::super::mem::{MemReader, MemWriter, BufReader}; use self::test::Bencher; + use str::StrSlice; /// A type, free to create, primarily intended for benchmarking creation of /// wrappers that, just for construction, don't need a Reader/Writer that @@ -535,9 +536,9 @@ mod test { fn test_read_line() { let in_buf = MemReader::new(Vec::from_slice(bytes!("a\nb\nc"))); let mut reader = BufferedReader::with_capacity(2, in_buf); - assert_eq!(reader.read_line(), Ok(~"a\n")); - assert_eq!(reader.read_line(), Ok(~"b\n")); - assert_eq!(reader.read_line(), Ok(~"c")); + assert_eq!(reader.read_line(), Ok("a\n".to_owned())); + assert_eq!(reader.read_line(), Ok("b\n".to_owned())); + assert_eq!(reader.read_line(), Ok("c".to_owned())); assert!(reader.read_line().is_err()); } @@ -546,9 +547,9 @@ mod test { let in_buf = MemReader::new(Vec::from_slice(bytes!("a\nb\nc"))); let mut reader = BufferedReader::with_capacity(2, in_buf); let mut it = reader.lines(); - assert_eq!(it.next(), Some(Ok(~"a\n"))); - assert_eq!(it.next(), Some(Ok(~"b\n"))); - assert_eq!(it.next(), Some(Ok(~"c"))); + assert_eq!(it.next(), Some(Ok("a\n".to_owned()))); + assert_eq!(it.next(), Some(Ok("b\n".to_owned()))); + assert_eq!(it.next(), Some(Ok("c".to_owned()))); assert_eq!(it.next(), None); } diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index 11271d71cbe..bb45e519e5e 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -16,6 +16,7 @@ use io; use option::{None, Option, Some}; use result::{Ok, Err}; use super::{Reader, Writer, IoResult}; +use str::StrSlice; use slice::{bytes, CloneableVector, MutableVector, ImmutableVector}; /// Allows reading from a rx. diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index c24d67f18cf..6bc32d0ed7b 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -711,6 +711,7 @@ mod test { use path::Path; use io; use ops::Drop; + use str::StrSlice; macro_rules! check( ($e:expr) => ( match $e { diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index aa3820bcd1f..2f64592ec7a 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -339,6 +339,7 @@ mod test { use super::*; use io::*; use io; + use str::StrSlice; #[test] fn test_mem_writer() { @@ -496,7 +497,7 @@ mod test { writer.write_line("testing").unwrap(); writer.write_str("testing").unwrap(); let mut r = BufReader::new(writer.get_ref()); - assert_eq!(r.read_to_str().unwrap(), ~"testingtesting\ntesting"); + assert_eq!(r.read_to_str().unwrap(), "testingtesting\ntesting".to_owned()); } #[test] @@ -506,7 +507,7 @@ mod test { writer.write_char('\n').unwrap(); writer.write_char('ệ').unwrap(); let mut r = BufReader::new(writer.get_ref()); - assert_eq!(r.read_to_str().unwrap(), ~"a\nệ"); + assert_eq!(r.read_to_str().unwrap(), "a\nệ".to_owned()); } #[test] diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 6864f18d26c..d8267e472bd 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1188,7 +1188,7 @@ pub trait Buffer: Reader { /// use std::io; /// /// let mut reader = io::stdin(); - /// let input = reader.read_line().ok().unwrap_or(~"nothing"); + /// let input = reader.read_line().ok().unwrap_or("nothing".to_owned()); /// ``` /// /// # Error diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 10e1ffacd95..f61b282767f 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -445,7 +445,8 @@ mod test { #[test] fn ipv6_addr_to_str() { let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280); - assert!(a1.to_str() == ~"::ffff:192.0.2.128" || a1.to_str() == ~"::FFFF:192.0.2.128"); - assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_str(), ~"8:9:a:b:c:d:e:f"); + assert!(a1.to_str() == "::ffff:192.0.2.128".to_owned() || + a1.to_str() == "::FFFF:192.0.2.128".to_owned()); + assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_str(), "8:9:a:b:c:d:e:f".to_owned()); } } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 26ead9e1e53..b507f61bb45 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -43,7 +43,7 @@ use rt::rtio::{RtioProcess, IoFactory, LocalIo}; /// ```should_fail /// use std::io::Process; /// -/// let mut child = match Process::new("/bin/cat", [~"file.txt"]) { +/// let mut child = match Process::new("/bin/cat", ["file.txt".to_owned()]) { /// Ok(child) => child, /// Err(e) => fail!("failed to execute child: {}", e), /// }; @@ -81,7 +81,7 @@ pub struct Process { /// /// let config = ProcessConfig { /// program: "/bin/sh", -/// args: &[~"-c", ~"true"], +/// args: &["-c".to_owned(), "true".to_owned()], /// .. ProcessConfig::new() /// }; /// ``` @@ -211,7 +211,7 @@ impl<'a> ProcessConfig<'a> { /// /// let config = ProcessConfig { /// program: "/bin/sh", - /// args: &[~"-c", ~"echo hello"], + /// args: &["-c".to_owned(), "echo hello".to_owned()], /// .. ProcessConfig::new() /// }; /// @@ -248,7 +248,7 @@ impl Process { /// ``` /// use std::io::Process; /// - /// let mut process = match Process::new("sh", &[~"c", ~"echo hello"]) { + /// let mut process = match Process::new("sh", &["c".to_owned(), "echo hello".to_owned()]) { /// Ok(p) => p, /// Err(e) => fail!("failed to execute process: {}", e), /// }; @@ -272,7 +272,7 @@ impl Process { /// use std::io::Process; /// use std::str; /// - /// let output = match Process::output("cat", [~"foo.txt"]) { + /// let output = match Process::output("cat", ["foo.txt".to_owned()]) { /// Ok(output) => output, /// Err(e) => fail!("failed to execute process: {}", e), /// }; @@ -427,6 +427,7 @@ impl Drop for Process { mod tests { use io::process::{ProcessConfig, Process}; use prelude::*; + use str::StrSlice; // FIXME(#10380) these tests should not all be ignored on android. @@ -471,7 +472,7 @@ mod tests { iotest!(fn signal_reported_right() { let args = ProcessConfig { program: "/bin/sh", - args: &[~"-c", ~"kill -1 $$"], + args: &["-c".to_owned(), "kill -1 $$".to_owned()], .. ProcessConfig::new() }; let p = Process::configure(args); @@ -501,11 +502,11 @@ mod tests { iotest!(fn stdout_works() { let args = ProcessConfig { program: "echo", - args: &[~"foobar"], + args: &["foobar".to_owned()], stdout: CreatePipe(false, true), .. ProcessConfig::new() }; - assert_eq!(run_output(args), ~"foobar\n"); + assert_eq!(run_output(args), "foobar\n".to_owned()); }) #[cfg(unix, not(target_os="android"))] @@ -513,19 +514,19 @@ mod tests { let cwd = Path::new("/"); let args = ProcessConfig { program: "/bin/sh", - args: &[~"-c", ~"pwd"], + args: &["-c".to_owned(), "pwd".to_owned()], cwd: Some(&cwd), stdout: CreatePipe(false, true), .. ProcessConfig::new() }; - assert_eq!(run_output(args), ~"/\n"); + assert_eq!(run_output(args), "/\n".to_owned()); }) #[cfg(unix, not(target_os="android"))] iotest!(fn stdin_works() { let args = ProcessConfig { program: "/bin/sh", - args: &[~"-c", ~"read line; echo $line"], + args: &["-c".to_owned(), "read line; echo $line".to_owned()], stdin: CreatePipe(true, false), stdout: CreatePipe(false, true), .. ProcessConfig::new() @@ -535,7 +536,7 @@ mod tests { drop(p.stdin.take()); let out = read_all(p.stdout.get_mut_ref() as &mut Reader); assert!(p.wait().success()); - assert_eq!(out, ~"foobar\n"); + assert_eq!(out, "foobar\n".to_owned()); }) #[cfg(not(target_os="android"))] @@ -564,7 +565,7 @@ mod tests { use libc; let args = ProcessConfig { program: "/bin/sh", - args: &[~"-c", ~"true"], + args: &["-c".to_owned(), "true".to_owned()], uid: Some(unsafe { libc::getuid() as uint }), gid: Some(unsafe { libc::getgid() as uint }), .. ProcessConfig::new() @@ -609,11 +610,11 @@ mod tests { iotest!(fn test_process_output_output() { let ProcessOutput {status, output, error} - = Process::output("echo", [~"hello"]).unwrap(); + = Process::output("echo", ["hello".to_owned()]).unwrap(); let output_str = str::from_utf8(output.as_slice()).unwrap(); assert!(status.success()); - assert_eq!(output_str.trim().to_owned(), ~"hello"); + assert_eq!(output_str.trim().to_owned(), "hello".to_owned()); // FIXME #7224 if !running_on_valgrind() { assert_eq!(error, Vec::new()); @@ -623,7 +624,7 @@ mod tests { #[cfg(not(target_os="android"))] iotest!(fn test_process_output_error() { let ProcessOutput {status, output, error} - = Process::output("mkdir", [~"."]).unwrap(); + = Process::output("mkdir", [".".to_owned()]).unwrap(); assert!(status.matches_exit_status(1)); assert_eq!(output, Vec::new()); @@ -646,12 +647,12 @@ mod tests { #[cfg(not(target_os="android"))] iotest!(fn test_wait_with_output_once() { - let mut prog = Process::new("echo", [~"hello"]).unwrap(); + let mut prog = Process::new("echo", ["hello".to_owned()]).unwrap(); let ProcessOutput {status, output, error} = prog.wait_with_output(); let output_str = str::from_utf8(output.as_slice()).unwrap(); assert!(status.success()); - assert_eq!(output_str.trim().to_owned(), ~"hello"); + assert_eq!(output_str.trim().to_owned(), "hello".to_owned()); // FIXME #7224 if !running_on_valgrind() { assert_eq!(error, Vec::new()); @@ -660,13 +661,13 @@ mod tests { #[cfg(not(target_os="android"))] iotest!(fn test_wait_with_output_twice() { - let mut prog = Process::new("echo", [~"hello"]).unwrap(); + let mut prog = Process::new("echo", ["hello".to_owned()]).unwrap(); let ProcessOutput {status, output, error} = prog.wait_with_output(); let output_str = str::from_utf8(output.as_slice()).unwrap(); assert!(status.success()); - assert_eq!(output_str.trim().to_owned(), ~"hello"); + assert_eq!(output_str.trim().to_owned(), "hello".to_owned()); // FIXME #7224 if !running_on_valgrind() { assert_eq!(error, Vec::new()); @@ -694,7 +695,7 @@ mod tests { pub fn run_pwd(dir: Option<&Path>) -> Process { Process::configure(ProcessConfig { program: "/system/bin/sh", - args: &[~"-c",~"pwd"], + args: &["-c".to_owned(),"pwd".to_owned()], cwd: dir.map(|a| &*a), .. ProcessConfig::new() }).unwrap() @@ -704,7 +705,7 @@ mod tests { pub fn run_pwd(dir: Option<&Path>) -> Process { Process::configure(ProcessConfig { program: "cmd", - args: &[~"/c", ~"cd"], + args: &["/c".to_owned(), "cd".to_owned()], cwd: dir.map(|a| &*a), .. ProcessConfig::new() }).unwrap() @@ -754,7 +755,7 @@ mod tests { pub fn run_env(env: Option<~[(~str, ~str)]>) -> Process { Process::configure(ProcessConfig { program: "/system/bin/sh", - args: &[~"-c",~"set"], + args: &["-c".to_owned(),"set".to_owned()], env: env.as_ref().map(|e| e.as_slice()), .. ProcessConfig::new() }).unwrap() @@ -764,7 +765,7 @@ mod tests { pub fn run_env(env: Option<~[(~str, ~str)]>) -> Process { Process::configure(ProcessConfig { program: "cmd", - args: &[~"/c", ~"set"], + args: &["/c".to_owned(), "set".to_owned()], env: env.as_ref().map(|e| e.as_slice()), .. ProcessConfig::new() }).unwrap() @@ -795,7 +796,7 @@ mod tests { let r = os::env(); for &(ref k, ref v) in r.iter() { // don't check android RANDOM variables - if *k != ~"RANDOM" { + if *k != "RANDOM".to_owned() { assert!(output.contains(format!("{}={}", *k, *v)) || output.contains(format!("{}=\'{}\'", *k, *v))); } @@ -803,7 +804,7 @@ mod tests { }) iotest!(fn test_add_to_env() { - let new_env = ~[(~"RUN_TEST_NEW_ENV", ~"123")]; + let new_env = ~[("RUN_TEST_NEW_ENV".to_owned(), "123".to_owned())]; let mut prog = run_env(Some(new_env)); let result = prog.wait_with_output(); @@ -815,14 +816,14 @@ mod tests { #[cfg(unix)] pub fn sleeper() -> Process { - Process::new("sleep", [~"1000"]).unwrap() + Process::new("sleep", ["1000".to_owned()]).unwrap() } #[cfg(windows)] pub fn sleeper() -> Process { // There's a `timeout` command on windows, but it doesn't like having // its output piped, so instead just ping ourselves a few times with // gaps inbetweeen so we're sure this process is alive for awhile - Process::new("ping", [~"127.0.0.1", ~"-n", ~"1000"]).unwrap() + Process::new("ping", ["127.0.0.1".to_owned(), "-n".to_owned(), "1000".to_owned()]).unwrap() } iotest!(fn test_kill() { diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 34a57884398..96439439e7a 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -411,7 +411,7 @@ mod tests { set_stdout(~w); println!("hello!"); }); - assert_eq!(r.read_to_str().unwrap(), ~"hello!\n"); + assert_eq!(r.read_to_str().unwrap(), "hello!\n".to_owned()); }) iotest!(fn capture_stderr() { diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 78a66f1f762..a6199aa43ab 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -354,38 +354,39 @@ mod tests { use prelude::*; use super::*; use task; + use str::StrSlice; #[test] fn test_tls_multitask() { static my_key: Key<~str> = &Key; - set(my_key, ~"parent data"); + set(my_key, "parent data".to_owned()); task::spawn(proc() { // TLS shouldn't carry over. assert!(get(my_key, |k| k.map(|k| (*k).clone())).is_none()); - set(my_key, ~"child data"); + set(my_key, "child data".to_owned()); assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == - ~"child data"); + "child data".to_owned()); // should be cleaned up for us }); // Must work multiple times - assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data"); - assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data"); - assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"parent data"); + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == "parent data".to_owned()); + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == "parent data".to_owned()); + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == "parent data".to_owned()); } #[test] fn test_tls_overwrite() { static my_key: Key<~str> = &Key; - set(my_key, ~"first data"); - set(my_key, ~"next data"); // Shouldn't leak. - assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == ~"next data"); + set(my_key, "first data".to_owned()); + set(my_key, "next data".to_owned()); // Shouldn't leak. + assert!(get(my_key, |k| k.map(|k| (*k).clone())).unwrap() == "next data".to_owned()); } #[test] fn test_tls_pop() { static my_key: Key<~str> = &Key; - set(my_key, ~"weasel"); - assert!(pop(my_key).unwrap() == ~"weasel"); + set(my_key, "weasel".to_owned()); + assert!(pop(my_key).unwrap() == "weasel".to_owned()); // Pop must remove the data from the map. assert!(pop(my_key).is_none()); } @@ -396,17 +397,17 @@ mod tests { modify(my_key, |data| { match data { Some(ref val) => fail!("unwelcome value: {}", *val), - None => Some(~"first data") + None => Some("first data".to_owned()) } }); modify(my_key, |data| { match data.as_ref().map(|s| s.as_slice()) { - Some("first data") => Some(~"next data"), + Some("first data") => Some("next data".to_owned()), Some(ref val) => fail!("wrong value: {}", *val), None => fail!("missing value") } }); - assert!(pop(my_key).unwrap() == ~"next data"); + assert!(pop(my_key).unwrap() == "next data".to_owned()); } #[test] @@ -419,7 +420,7 @@ mod tests { // a stack smaller than 1 MB. static my_key: Key<~str> = &Key; task::spawn(proc() { - set(my_key, ~"hax"); + set(my_key, "hax".to_owned()); }); } @@ -429,7 +430,7 @@ mod tests { static box_key: Key<@()> = &Key; static int_key: Key<int> = &Key; task::spawn(proc() { - set(str_key, ~"string data"); + set(str_key, "string data".to_owned()); set(box_key, @()); set(int_key, 42); }); @@ -442,8 +443,8 @@ mod tests { static box_key: Key<@()> = &Key; static int_key: Key<int> = &Key; task::spawn(proc() { - set(str_key, ~"string data"); - set(str_key, ~"string data 2"); + set(str_key, "string data".to_owned()); + set(str_key, "string data 2".to_owned()); set(box_key, @()); set(box_key, @()); set(int_key, 42); @@ -460,11 +461,11 @@ mod tests { static str_key: Key<~str> = &Key; static box_key: Key<@()> = &Key; static int_key: Key<int> = &Key; - set(str_key, ~"parent data"); + set(str_key, "parent data".to_owned()); set(box_key, @()); task::spawn(proc() { // spawn_linked - set(str_key, ~"string data"); + set(str_key, "string data".to_owned()); set(box_key, @()); set(int_key, 42); fail!(); diff --git a/src/libstd/mem.rs b/src/libstd/mem.rs index 282cfe51782..d562aa73d78 100644 --- a/src/libstd/mem.rs +++ b/src/libstd/mem.rs @@ -262,6 +262,7 @@ pub fn drop<T>(_x: T) { } mod tests { use mem::*; use option::{Some,None}; + use str::StrSlice; #[test] fn size_of_basic() { @@ -352,7 +353,7 @@ mod tests { #[test] fn test_replace() { - let mut x = Some(~"test"); + let mut x = Some("test".to_owned()); let y = replace(&mut x, None); assert!(x.is_none()); assert!(y.is_some()); diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 3228b5a1a49..a6b0ccf3a87 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -298,6 +298,7 @@ mod tests { use num::Bitwise; use num::CheckedDiv; use num::ToStrRadix; + use str::StrSlice; #[test] fn test_overflows() { @@ -419,39 +420,39 @@ mod tests { #[test] fn test_to_str() { - assert_eq!((0 as $T).to_str_radix(10u), ~"0"); - assert_eq!((1 as $T).to_str_radix(10u), ~"1"); - assert_eq!((-1 as $T).to_str_radix(10u), ~"-1"); - assert_eq!((127 as $T).to_str_radix(16u), ~"7f"); - assert_eq!((100 as $T).to_str_radix(10u), ~"100"); + assert_eq!((0 as $T).to_str_radix(10u), "0".to_owned()); + assert_eq!((1 as $T).to_str_radix(10u), "1".to_owned()); + assert_eq!((-1 as $T).to_str_radix(10u), "-1".to_owned()); + assert_eq!((127 as $T).to_str_radix(16u), "7f".to_owned()); + assert_eq!((100 as $T).to_str_radix(10u), "100".to_owned()); } #[test] fn test_int_to_str_overflow() { let mut i8_val: i8 = 127_i8; - assert_eq!(i8_val.to_str(), ~"127"); + assert_eq!(i8_val.to_str(), "127".to_owned()); i8_val += 1 as i8; - assert_eq!(i8_val.to_str(), ~"-128"); + assert_eq!(i8_val.to_str(), "-128".to_owned()); let mut i16_val: i16 = 32_767_i16; - assert_eq!(i16_val.to_str(), ~"32767"); + assert_eq!(i16_val.to_str(), "32767".to_owned()); i16_val += 1 as i16; - assert_eq!(i16_val.to_str(), ~"-32768"); + assert_eq!(i16_val.to_str(), "-32768".to_owned()); let mut i32_val: i32 = 2_147_483_647_i32; - assert_eq!(i32_val.to_str(), ~"2147483647"); + assert_eq!(i32_val.to_str(), "2147483647".to_owned()); i32_val += 1 as i32; - assert_eq!(i32_val.to_str(), ~"-2147483648"); + assert_eq!(i32_val.to_str(), "-2147483648".to_owned()); let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; - assert_eq!(i64_val.to_str(), ~"9223372036854775807"); + assert_eq!(i64_val.to_str(), "9223372036854775807".to_owned()); i64_val += 1 as i64; - assert_eq!(i64_val.to_str(), ~"-9223372036854775808"); + assert_eq!(i64_val.to_str(), "-9223372036854775808".to_owned()); } #[test] diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 61723f339ae..9b9aee672a0 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -234,6 +234,7 @@ mod tests { use num::CheckedDiv; use num::Bitwise; use num::ToStrRadix; + use str::StrSlice; use u16; #[test] @@ -274,13 +275,13 @@ mod tests { #[test] pub fn test_to_str() { - assert_eq!((0 as $T).to_str_radix(10u), ~"0"); - assert_eq!((1 as $T).to_str_radix(10u), ~"1"); - assert_eq!((2 as $T).to_str_radix(10u), ~"2"); - assert_eq!((11 as $T).to_str_radix(10u), ~"11"); - assert_eq!((11 as $T).to_str_radix(16u), ~"b"); - assert_eq!((255 as $T).to_str_radix(16u), ~"ff"); - assert_eq!((0xff as $T).to_str_radix(10u), ~"255"); + assert_eq!((0 as $T).to_str_radix(10u), "0".to_owned()); + assert_eq!((1 as $T).to_str_radix(10u), "1".to_owned()); + assert_eq!((2 as $T).to_str_radix(10u), "2".to_owned()); + assert_eq!((11 as $T).to_str_radix(10u), "11".to_owned()); + assert_eq!((11 as $T).to_str_radix(16u), "b".to_owned()); + assert_eq!((255 as $T).to_str_radix(16u), "ff".to_owned()); + assert_eq!((0xff as $T).to_str_radix(10u), "255".to_owned()); } #[test] @@ -313,28 +314,28 @@ mod tests { #[test] fn test_uint_to_str_overflow() { let mut u8_val: u8 = 255_u8; - assert_eq!(u8_val.to_str(), ~"255"); + assert_eq!(u8_val.to_str(), "255".to_owned()); u8_val += 1 as u8; - assert_eq!(u8_val.to_str(), ~"0"); + assert_eq!(u8_val.to_str(), "0".to_owned()); let mut u16_val: u16 = 65_535_u16; - assert_eq!(u16_val.to_str(), ~"65535"); + assert_eq!(u16_val.to_str(), "65535".to_owned()); u16_val += 1 as u16; - assert_eq!(u16_val.to_str(), ~"0"); + assert_eq!(u16_val.to_str(), "0".to_owned()); let mut u32_val: u32 = 4_294_967_295_u32; - assert_eq!(u32_val.to_str(), ~"4294967295"); + assert_eq!(u32_val.to_str(), "4294967295".to_owned()); u32_val += 1 as u32; - assert_eq!(u32_val.to_str(), ~"0"); + assert_eq!(u32_val.to_str(), "0".to_owned()); let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; - assert_eq!(u64_val.to_str(), ~"18446744073709551615"); + assert_eq!(u64_val.to_str(), "18446744073709551615".to_owned()); u64_val += 1 as u64; - assert_eq!(u64_val.to_str(), ~"0"); + assert_eq!(u64_val.to_str(), "0".to_owned()); } #[test] diff --git a/src/libstd/option.rs b/src/libstd/option.rs index ca1ea0169e6..557e2043381 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -194,7 +194,7 @@ impl<T> Option<T> { /// to the value inside the original. /// /// ``` - /// let num_as_str: Option<~str> = Some(~"10"); + /// let num_as_str: Option<~str> = Some("10".to_owned()); /// // First, cast `Option<~str>` to `Option<&~str>` with `as_ref`, /// // then consume *that* with `map`, leaving `num_as_str` on the stack. /// let num_as_int: Option<uint> = num_as_str.as_ref().map(|n| n.len()); @@ -294,7 +294,7 @@ impl<T> Option<T> { /// Convert an `Option<~str>` into an `Option<uint>`, consuming the original: /// /// ``` - /// let num_as_str: Option<~str> = Some(~"10"); + /// let num_as_str: Option<~str> = Some("10".to_owned()); /// // `Option::map` takes self *by value*, consuming `num_as_str` /// let num_as_int: Option<uint> = num_as_str.map(|n| n.len()); /// ``` @@ -630,7 +630,7 @@ mod tests { #[test] fn test_get_str() { - let x = ~"test"; + let x = "test".to_owned(); let addr_x = x.as_ptr(); let opt = Some(x); let y = opt.unwrap(); @@ -751,7 +751,7 @@ mod tests { #[test] fn test_unwrap() { assert_eq!(Some(1).unwrap(), 1); - assert_eq!(Some(~"hello").unwrap(), ~"hello"); + assert_eq!(Some("hello".to_owned()).unwrap(), "hello".to_owned()); } #[test] diff --git a/src/libstd/os.rs b/src/libstd/os.rs index dbb95304873..97e01efa3a9 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1525,7 +1525,7 @@ mod tests { fn make_rand_name() -> ~str { let mut rng = rand::task_rng(); - let n = ~"TEST" + rng.gen_ascii_str(10u); + let n = "TEST".to_owned() + rng.gen_ascii_str(10u); assert!(getenv(n).is_none()); n } @@ -1534,7 +1534,7 @@ mod tests { fn test_setenv() { let n = make_rand_name(); setenv(n, "VALUE"); - assert_eq!(getenv(n), option::Some(~"VALUE")); + assert_eq!(getenv(n), option::Some("VALUE".to_owned())); } #[test] @@ -1551,9 +1551,9 @@ mod tests { let n = make_rand_name(); setenv(n, "1"); setenv(n, "2"); - assert_eq!(getenv(n), option::Some(~"2")); + assert_eq!(getenv(n), option::Some("2".to_owned())); setenv(n, ""); - assert_eq!(getenv(n), option::Some(~"")); + assert_eq!(getenv(n), option::Some("".to_owned())); } // Windows GetEnvironmentVariable requires some extra work to make sure @@ -1561,7 +1561,7 @@ mod tests { #[test] #[ignore] fn test_getenv_big() { - let mut s = ~""; + let mut s = "".to_owned(); let mut i = 0; while i < 100 { s = s + "aaaaaaaaaa"; @@ -1627,10 +1627,10 @@ mod tests { let mut e = env(); setenv(n, "VALUE"); - assert!(!e.contains(&(n.clone(), ~"VALUE"))); + assert!(!e.contains(&(n.clone(), "VALUE".to_owned()))); e = env(); - assert!(e.contains(&(n, ~"VALUE"))); + assert!(e.contains(&(n, "VALUE".to_owned()))); } #[test] diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 47f9604d63f..4affea37e35 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -459,6 +459,7 @@ mod tests { use prelude::*; use super::*; use str; + use str::StrSlice; macro_rules! t( (s: $path:expr, $exp:expr) => ( @@ -766,7 +767,7 @@ mod tests { t!(s: "a/b/c", ["d", "e"], "a/b/c/d/e"); t!(s: "a/b/c", ["d", "/e"], "/e"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); - t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); + t!(s: "a/b/c", ["d".to_owned(), "e".to_owned()], "a/b/c/d/e"); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [b!("d"), b!("/e"), b!("f")], b!("/e/f")); t!(v: b!("a/b/c"), [Vec::from_slice(b!("d")), Vec::from_slice(b!("e"))], b!("a/b/c/d/e")); @@ -871,7 +872,7 @@ mod tests { t!(s: "a/b/c", ["d", "e"], "a/b/c/d/e"); t!(s: "a/b/c", ["..", "d"], "a/b/d"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); - t!(s: "a/b/c", [~"d", ~"e"], "a/b/c/d/e"); + t!(s: "a/b/c", ["d".to_owned(), "e".to_owned()], "a/b/c/d/e"); t!(v: b!("a/b/c"), [b!("d"), b!("e")], b!("a/b/c/d/e")); t!(v: b!("a/b/c"), [Vec::from_slice(b!("d")), Vec::from_slice(b!("e"))], b!("a/b/c/d/e")); } diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 58c7aaa2d32..74ca8dc5785 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1314,9 +1314,9 @@ mod tests { #[test] fn test_display_str() { let path = Path::new("foo"); - assert_eq!(path.display().to_str(), ~"foo"); + assert_eq!(path.display().to_str(), "foo".to_owned()); let path = Path::new(b!("\\")); - assert_eq!(path.filename_display().to_str(), ~""); + assert_eq!(path.filename_display().to_str(), "".to_owned()); let path = Path::new("foo"); let mo = path.display().as_maybe_owned(); @@ -1577,7 +1577,7 @@ mod tests { t!(s: "a\\b\\c", ["d", "e"], "a\\b\\c\\d\\e"); t!(s: "a\\b\\c", ["d", "\\e"], "\\e"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); - t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); + t!(s: "a\\b\\c", ["d".to_owned(), "e".to_owned()], "a\\b\\c\\d\\e"); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [b!("d"), b!("\\e"), b!("f")], b!("\\e\\f")); t!(v: b!("a\\b\\c"), [Vec::from_slice(b!("d")), Vec::from_slice(b!("e"))], @@ -1718,7 +1718,7 @@ mod tests { t!(s: "a\\b\\c", ["d", "e"], "a\\b\\c\\d\\e"); t!(s: "a\\b\\c", ["..", "d"], "a\\b\\d"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); - t!(s: "a\\b\\c", [~"d", ~"e"], "a\\b\\c\\d\\e"); + t!(s: "a\\b\\c", ["d".to_owned(), "e".to_owned()], "a\\b\\c\\d\\e"); t!(v: b!("a\\b\\c"), [b!("d"), b!("e")], b!("a\\b\\c\\d\\e")); t!(v: b!("a\\b\\c"), [Vec::from_slice(b!("d")), Vec::from_slice(b!("e"))], b!("a\\b\\c\\d\\e")); diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 61238f508c1..668edbcc42f 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -636,7 +636,8 @@ fn test_repr() { exact_test(&false, "false"); exact_test(&1.234, "1.234f64"); exact_test(&(&"hello"), "\"hello\""); - exact_test(&(~"he\u10f3llo"), "~\"he\\u10f3llo\""); + // FIXME What do I do about this one? + exact_test(&("he\u10f3llo".to_owned()), "~\"he\\u10f3llo\""); exact_test(&(@10), "@10"); exact_test(&(~10), "~10"); @@ -658,13 +659,13 @@ fn test_repr() { "@repr::P{a: 10, b: 1.234f64}"); exact_test(&(~P{a:10, b:1.234}), "~repr::P{a: 10, b: 1.234f64}"); - exact_test(&(10u8, ~"hello"), + exact_test(&(10u8, "hello".to_owned()), "(10u8, ~\"hello\")"); - exact_test(&(10u16, ~"hello"), + exact_test(&(10u16, "hello".to_owned()), "(10u16, ~\"hello\")"); - exact_test(&(10u32, ~"hello"), + exact_test(&(10u32, "hello".to_owned()), "(10u32, ~\"hello\")"); - exact_test(&(10u64, ~"hello"), + exact_test(&(10u64, "hello".to_owned()), "(10u64, ~\"hello\")"); exact_test(&(&[1, 2]), "&[1, 2]"); diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 493ff8c485f..0f993598747 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -623,37 +623,41 @@ pub fn fold_<T,E,Iter:Iterator<Result<T,E>>>(iterator: Iter) -> Result<(),E> { mod tests { use super::*; use prelude::*; + use str::StrSlice; use iter::range; pub fn op1() -> Result<int, ~str> { Ok(666) } - pub fn op2() -> Result<int, ~str> { Err(~"sadface") } + pub fn op2() -> Result<int, ~str> { Err("sadface".to_owned()) } #[test] pub fn test_and() { assert_eq!(op1().and(Ok(667)).unwrap(), 667); - assert_eq!(op1().and(Err::<(), ~str>(~"bad")).unwrap_err(), ~"bad"); + assert_eq!(op1().and(Err::<(), ~str>("bad".to_owned())).unwrap_err(), "bad".to_owned()); - assert_eq!(op2().and(Ok(667)).unwrap_err(), ~"sadface"); - assert_eq!(op2().and(Err::<(), ~str>(~"bad")).unwrap_err(), ~"sadface"); + assert_eq!(op2().and(Ok(667)).unwrap_err(), "sadface".to_owned()); + assert_eq!(op2().and(Err::<(), ~str>("bad".to_owned())).unwrap_err(), "sadface".to_owned()); } #[test] pub fn test_and_then() { assert_eq!(op1().and_then(|i| Ok::<int, ~str>(i + 1)).unwrap(), 667); - assert_eq!(op1().and_then(|_| Err::<int, ~str>(~"bad")).unwrap_err(), ~"bad"); + assert_eq!(op1().and_then(|_| Err::<int, ~str>("bad".to_owned())).unwrap_err(), + "bad".to_owned()); - assert_eq!(op2().and_then(|i| Ok::<int, ~str>(i + 1)).unwrap_err(), ~"sadface"); - assert_eq!(op2().and_then(|_| Err::<int, ~str>(~"bad")).unwrap_err(), ~"sadface"); + assert_eq!(op2().and_then(|i| Ok::<int, ~str>(i + 1)).unwrap_err(), + "sadface".to_owned()); + assert_eq!(op2().and_then(|_| Err::<int, ~str>("bad".to_owned())).unwrap_err(), + "sadface".to_owned()); } #[test] pub fn test_or() { assert_eq!(op1().or(Ok(667)).unwrap(), 666); - assert_eq!(op1().or(Err(~"bad")).unwrap(), 666); + assert_eq!(op1().or(Err("bad".to_owned())).unwrap(), 666); assert_eq!(op2().or(Ok(667)).unwrap(), 667); - assert_eq!(op2().or(Err(~"bad")).unwrap_err(), ~"bad"); + assert_eq!(op2().or(Err("bad".to_owned())).unwrap_err(), "bad".to_owned()); } #[test] @@ -662,19 +666,20 @@ mod tests { assert_eq!(op1().or_else(|e| Err::<int, ~str>(e + "!")).unwrap(), 666); assert_eq!(op2().or_else(|_| Ok::<int, ~str>(667)).unwrap(), 667); - assert_eq!(op2().or_else(|e| Err::<int, ~str>(e + "!")).unwrap_err(), ~"sadface!"); + assert_eq!(op2().or_else(|e| Err::<int, ~str>(e + "!")).unwrap_err(), + "sadface!".to_owned()); } #[test] pub fn test_impl_map() { - assert_eq!(Ok::<~str, ~str>(~"a").map(|x| x + "b"), Ok(~"ab")); - assert_eq!(Err::<~str, ~str>(~"a").map(|x| x + "b"), Err(~"a")); + assert_eq!(Ok::<~str, ~str>("a".to_owned()).map(|x| x + "b"), Ok("ab".to_owned())); + assert_eq!(Err::<~str, ~str>("a".to_owned()).map(|x| x + "b"), Err("a".to_owned())); } #[test] pub fn test_impl_map_err() { - assert_eq!(Ok::<~str, ~str>(~"a").map_err(|x| x + "b"), Ok(~"a")); - assert_eq!(Err::<~str, ~str>(~"a").map_err(|x| x + "b"), Err(~"ab")); + assert_eq!(Ok::<~str, ~str>("a".to_owned()).map_err(|x| x + "b"), Ok("a".to_owned())); + assert_eq!(Err::<~str, ~str>("a".to_owned()).map_err(|x| x + "b"), Err("ab".to_owned())); } #[test] @@ -720,25 +725,25 @@ mod tests { #[test] pub fn test_to_str() { let ok: Result<int, ~str> = Ok(100); - let err: Result<int, ~str> = Err(~"Err"); + let err: Result<int, ~str> = Err("Err".to_owned()); - assert_eq!(ok.to_str(), ~"Ok(100)"); - assert_eq!(err.to_str(), ~"Err(Err)"); + assert_eq!(ok.to_str(), "Ok(100)".to_owned()); + assert_eq!(err.to_str(), "Err(Err)".to_owned()); } #[test] pub fn test_fmt_default() { let ok: Result<int, ~str> = Ok(100); - let err: Result<int, ~str> = Err(~"Err"); + let err: Result<int, ~str> = Err("Err".to_owned()); - assert_eq!(format!("{}", ok), ~"Ok(100)"); - assert_eq!(format!("{}", err), ~"Err(Err)"); + assert_eq!(format!("{}", ok), "Ok(100)".to_owned()); + assert_eq!(format!("{}", err), "Err(Err)".to_owned()); } #[test] pub fn test_unwrap_or() { let ok: Result<int, ~str> = Ok(100); - let ok_err: Result<int, ~str> = Err(~"Err"); + let ok_err: Result<int, ~str> = Err("Err".to_owned()); assert_eq!(ok.unwrap_or(50), 100); assert_eq!(ok_err.unwrap_or(50), 50); @@ -747,7 +752,7 @@ mod tests { #[test] pub fn test_unwrap_or_else() { fn handler(msg: ~str) -> int { - if msg == ~"I got this." { + if msg == "I got this.".to_owned() { 50 } else { fail!("BadBad") @@ -755,7 +760,7 @@ mod tests { } let ok: Result<int, ~str> = Ok(100); - let ok_err: Result<int, ~str> = Err(~"I got this."); + let ok_err: Result<int, ~str> = Err("I got this.".to_owned()); assert_eq!(ok.unwrap_or_handle(handler), 100); assert_eq!(ok_err.unwrap_or_handle(handler), 50); @@ -765,14 +770,14 @@ mod tests { #[should_fail] pub fn test_unwrap_or_else_failure() { fn handler(msg: ~str) -> int { - if msg == ~"I got this." { + if msg == "I got this.".to_owned() { 50 } else { fail!("BadBad") } } - let bad_err: Result<int, ~str> = Err(~"Unrecoverable mess."); + let bad_err: Result<int, ~str> = Err("Unrecoverable mess.".to_owned()); let _ : int = bad_err.unwrap_or_handle(handler); } } diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index abe2e2ab1dc..8b9b8a7498b 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -67,6 +67,7 @@ mod imp { use clone::Clone; use option::{Option, Some, None}; use iter::Iterator; + use str::StrSlice; use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT}; use mem; #[cfg(not(test))] use ptr::RawPtr; diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index a3664b45a41..f75b5315207 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -413,11 +413,11 @@ mod test { fn tls() { use local_data; local_data_key!(key: @~str) - local_data::set(key, @~"data"); - assert!(*local_data::get(key, |k| k.map(|k| *k)).unwrap() == ~"data"); + local_data::set(key, @"data".to_owned()); + assert!(*local_data::get(key, |k| k.map(|k| *k)).unwrap() == "data".to_owned()); local_data_key!(key2: @~str) - local_data::set(key2, @~"data"); - assert!(*local_data::get(key2, |k| k.map(|k| *k)).unwrap() == ~"data"); + local_data::set(key2, @"data".to_owned()); + assert!(*local_data::get(key2, |k| k.map(|k| *k)).unwrap() == "data".to_owned()); } #[test] diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs index 4210b2ec670..6c55195e627 100644 --- a/src/libstd/slice.rs +++ b/src/libstd/slice.rs @@ -1142,7 +1142,7 @@ pub trait OwnedVector<T> { /// # Examples /// /// ```rust - /// let v = ~[~"a", ~"b"]; + /// let v = ~["a".to_owned(), "b".to_owned()]; /// for s in v.move_iter() { /// // s has type ~str, not &~str /// println!("{}", s); @@ -1602,15 +1602,15 @@ pub trait MutableVector<'a, T> { /// # Example /// /// ```rust - /// let mut v = ~[~"foo", ~"bar", ~"baz"]; + /// let mut v = ~["foo".to_owned(), "bar".to_owned(), "baz".to_owned()]; /// /// unsafe { - /// // `~"baz"` is deallocated. - /// v.unsafe_set(2, ~"qux"); + /// // `"baz".to_owned()` is deallocated. + /// v.unsafe_set(2, "qux".to_owned()); /// /// // Out of bounds: could cause a crash, or overwriting /// // other data, or something else. - /// // v.unsafe_set(10, ~"oops"); + /// // v.unsafe_set(10, "oops".to_owned()); /// } /// ``` unsafe fn unsafe_set(self, index: uint, val: T); @@ -1622,10 +1622,10 @@ pub trait MutableVector<'a, T> { /// # Example /// /// ```rust - /// let mut v = [~"foo", ~"bar"]; + /// let mut v = ["foo".to_owned(), "bar".to_owned()]; /// - /// // memory leak! `~"bar"` is not deallocated. - /// unsafe { v.init_elem(1, ~"baz"); } + /// // memory leak! `"bar".to_owned()` is not deallocated. + /// unsafe { v.init_elem(1, "baz".to_owned()); } /// ``` unsafe fn init_elem(self, i: uint, val: T); @@ -2763,7 +2763,7 @@ mod tests { assert_eq!(it.next(), None); } { - let v = [~"Hello"]; + let v = ["Hello".to_owned()]; let mut it = v.permutations(); assert_eq!(it.next(), None); } @@ -3404,10 +3404,10 @@ mod tests { }) ) let empty: ~[int] = ~[]; - test_show_vec!(empty, ~"[]"); - test_show_vec!(~[1], ~"[1]"); - test_show_vec!(~[1, 2, 3], ~"[1, 2, 3]"); - test_show_vec!(~[~[], ~[1u], ~[1u, 1u]], ~"[[], [1], [1, 1]]"); + test_show_vec!(empty, "[]".to_owned()); + test_show_vec!(~[1], "[1]".to_owned()); + test_show_vec!(~[1, 2, 3], "[1, 2, 3]".to_owned()); + test_show_vec!(~[~[], ~[1u], ~[1u, 1u]], "[[], [1], [1, 1]]".to_owned()); } #[test] @@ -3507,11 +3507,11 @@ mod tests { let xs = vec![Foo, Foo, Foo]; assert_eq!(format!("{:?}", xs.slice(0, 2).to_owned()), - ~"~[slice::tests::Foo, slice::tests::Foo]"); + "~[slice::tests::Foo, slice::tests::Foo]".to_owned()); let xs: [Foo, ..3] = [Foo, Foo, Foo]; assert_eq!(format!("{:?}", xs.slice(0, 2).to_owned()), - ~"~[slice::tests::Foo, slice::tests::Foo]"); + "~[slice::tests::Foo, slice::tests::Foo]".to_owned()); cnt = 0; for f in xs.iter() { assert!(*f == Foo); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index ed4a8c652f7..3c03bddb293 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -33,7 +33,7 @@ As an example, here's a few different kinds of strings. ```rust fn main() { - let owned_string = ~"I am an owned string"; + let owned_string = "I am an owned string".to_owned(); let borrowed_string1 = "This string is borrowed with the 'static lifetime"; let borrowed_string2: &str = owned_string; // owned strings can be borrowed } @@ -163,7 +163,7 @@ pub trait StrVector { impl<'a, S: Str> StrVector for &'a [S] { fn concat(&self) -> ~str { - if self.is_empty() { return ~""; } + if self.is_empty() { return "".to_owned(); } // `len` calculation may overflow but push_str but will check boundaries let len = self.iter().map(|s| s.as_slice().len()).sum(); @@ -178,7 +178,7 @@ impl<'a, S: Str> StrVector for &'a [S] { } fn connect(&self, sep: &str) -> ~str { - if self.is_empty() { return ~""; } + if self.is_empty() { return "".to_owned(); } // concat is faster if sep.is_empty() { return self.concat(); } @@ -974,7 +974,7 @@ pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { /// // 𝄞music /// let mut v = [0xD834, 0xDD1E, 0x006d, 0x0075, /// 0x0073, 0x0069, 0x0063]; -/// assert_eq!(str::from_utf16(v), Some(~"𝄞music")); +/// assert_eq!(str::from_utf16(v), Some("𝄞music".to_owned())); /// /// // 𝄞mu<invalid>ic /// v[4] = 0xD800; @@ -1004,7 +1004,7 @@ pub fn from_utf16(v: &[u16]) -> Option<~str> { /// 0xD834]; /// /// assert_eq!(str::from_utf16_lossy(v), -/// ~"𝄞mus\uFFFDic\uFFFD"); +/// "𝄞mus\uFFFDic\uFFFD".to_owned()); /// ``` pub fn from_utf16_lossy(v: &[u16]) -> ~str { utf16_items(v).map(|c| c.to_char_lossy()).collect() @@ -1451,7 +1451,7 @@ pub mod raw { let a = ~[65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; let b = a.as_ptr(); let c = from_buf_len(b, 3u); - assert_eq!(c, ~"AAA"); + assert_eq!(c, "AAA".to_owned()); } } } @@ -2776,7 +2776,7 @@ impl<'a> Default for &'a str { } impl Default for ~str { - fn default() -> ~str { ~"" } + fn default() -> ~str { "".to_owned() } } #[cfg(test)] @@ -2789,9 +2789,9 @@ mod tests { #[test] fn test_eq() { - assert!((eq(&~"", &~""))); - assert!((eq(&~"foo", &~"foo"))); - assert!((!eq(&~"foo", &~"bar"))); + assert!((eq(&"".to_owned(), &"".to_owned()))); + assert!((eq(&"foo".to_owned(), &"foo".to_owned()))); + assert!((!eq(&"foo".to_owned(), &"bar".to_owned()))); } #[test] @@ -2851,17 +2851,17 @@ mod tests { #[test] fn test_collect() { - let empty = ~""; + let empty = "".to_owned(); let s: ~str = empty.chars().collect(); assert_eq!(empty, s); - let data = ~"ประเทศไทย中"; + let data = "ประเทศไทย中".to_owned(); let s: ~str = data.chars().collect(); assert_eq!(data, s); } #[test] fn test_into_bytes() { - let data = ~"asdf"; + let data = "asdf".to_owned(); let buf = data.into_bytes(); assert_eq!(bytes!("asdf"), buf.as_slice()); } @@ -2877,7 +2877,7 @@ mod tests { assert_eq!(data.slice(2u, 6u).find_str("ab"), Some(3u - 2u)); assert!(data.slice(2u, 4u).find_str("ab").is_none()); - let mut data = ~"ประเทศไทย中华Việt Nam"; + let mut data = "ประเทศไทย中华Việt Nam".to_owned(); data = data + data; assert!(data.find_str("ไท华").is_none()); assert_eq!(data.slice(0u, 43u).find_str(""), Some(0u)); @@ -2914,10 +2914,11 @@ mod tests { fn t(v: &[~str], s: &str) { assert_eq!(v.concat(), s.to_str()); } - t([~"you", ~"know", ~"I'm", ~"no", ~"good"], "youknowI'mnogood"); + t(["you".to_owned(), "know".to_owned(), "I'm".to_owned(), + "no".to_owned(), "good".to_owned()], "youknowI'mnogood"); let v: &[~str] = []; t(v, ""); - t([~"hi"], "hi"); + t(["hi".to_owned()], "hi"); } #[test] @@ -2925,11 +2926,12 @@ mod tests { fn t(v: &[~str], sep: &str, s: &str) { assert_eq!(v.connect(sep), s.to_str()); } - t([~"you", ~"know", ~"I'm", ~"no", ~"good"], + t(["you".to_owned(), "know".to_owned(), "I'm".to_owned(), + "no".to_owned(), "good".to_owned()], " ", "you know I'm no good"); let v: &[~str] = []; t(v, " ", ""); - t([~"hi"], " ", "hi"); + t(["hi".to_owned()], " ", "hi"); } #[test] @@ -2956,11 +2958,11 @@ mod tests { #[test] fn test_repeat() { - assert_eq!("x".repeat(4), ~"xxxx"); - assert_eq!("hi".repeat(4), ~"hihihihi"); - assert_eq!("ไท华".repeat(3), ~"ไท华ไท华ไท华"); - assert_eq!("".repeat(4), ~""); - assert_eq!("hi".repeat(0), ~""); + assert_eq!("x".repeat(4), "xxxx".to_owned()); + assert_eq!("hi".repeat(4), "hihihihi".to_owned()); + assert_eq!("ไท华".repeat(3), "ไท华ไท华ไท华".to_owned()); + assert_eq!("".repeat(4), "".to_owned()); + assert_eq!("hi".repeat(0), "".to_owned()); } #[test] @@ -3022,51 +3024,51 @@ mod tests { #[test] fn test_replace() { let a = "a"; - assert_eq!("".replace(a, "b"), ~""); - assert_eq!("a".replace(a, "b"), ~"b"); - assert_eq!("ab".replace(a, "b"), ~"bb"); + assert_eq!("".replace(a, "b"), "".to_owned()); + assert_eq!("a".replace(a, "b"), "b".to_owned()); + assert_eq!("ab".replace(a, "b"), "bb".to_owned()); let test = "test"; assert!(" test test ".replace(test, "toast") == - ~" toast toast "); - assert_eq!(" test test ".replace(test, ""), ~" "); + " toast toast ".to_owned()); + assert_eq!(" test test ".replace(test, ""), " ".to_owned()); } #[test] fn test_replace_2a() { - let data = ~"ประเทศไทย中华"; - let repl = ~"دولة الكويت"; + let data = "ประเทศไทย中华".to_owned(); + let repl = "دولة الكويت".to_owned(); - let a = ~"ประเ"; - let a2 = ~"دولة الكويتทศไทย中华"; + let a = "ประเ".to_owned(); + let a2 = "دولة الكويتทศไทย中华".to_owned(); assert_eq!(data.replace(a, repl), a2); } #[test] fn test_replace_2b() { - let data = ~"ประเทศไทย中华"; - let repl = ~"دولة الكويت"; + let data = "ประเทศไทย中华".to_owned(); + let repl = "دولة الكويت".to_owned(); - let b = ~"ะเ"; - let b2 = ~"ปรدولة الكويتทศไทย中华"; + let b = "ะเ".to_owned(); + let b2 = "ปรدولة الكويتทศไทย中华".to_owned(); assert_eq!(data.replace(b, repl), b2); } #[test] fn test_replace_2c() { - let data = ~"ประเทศไทย中华"; - let repl = ~"دولة الكويت"; + let data = "ประเทศไทย中华".to_owned(); + let repl = "دولة الكويت".to_owned(); - let c = ~"中华"; - let c2 = ~"ประเทศไทยدولة الكويت"; + let c = "中华".to_owned(); + let c2 = "ประเทศไทยدولة الكويت".to_owned(); assert_eq!(data.replace(c, repl), c2); } #[test] fn test_replace_2d() { - let data = ~"ประเทศไทย中华"; - let repl = ~"دولة الكويت"; + let data = "ประเทศไทย中华".to_owned(); + let repl = "دولة الكويت".to_owned(); - let d = ~"ไท华"; + let d = "ไท华".to_owned(); assert_eq!(data.replace(d, repl), data); } @@ -3331,7 +3333,7 @@ mod tests { let a = ~[65, 65, 65, 65, 65, 65, 65, 0]; let b = a.as_ptr(); let c = raw::from_c_str(b); - assert_eq!(c, ~"AAAAAAA"); + assert_eq!(c, "AAAAAAA".to_owned()); } } @@ -3353,7 +3355,7 @@ mod tests { fn test_as_bytes_fail() { // Don't double free. (I'm not sure if this exercises the // original problem code path anymore.) - let s = ~""; + let s = "".to_owned(); let _bytes = s.as_bytes(); fail!(); } @@ -3395,7 +3397,7 @@ mod tests { #[test] fn vec_str_conversions() { - let s1: ~str = ~"All mimsy were the borogoves"; + let s1: ~str = "All mimsy were the borogoves".to_owned(); let v: ~[u8] = s1.as_bytes().to_owned(); let s2: ~str = from_utf8(v).unwrap().to_owned(); @@ -3423,7 +3425,7 @@ mod tests { assert!(!"abcde".contains("def")); assert!(!"".contains("a")); - let data = ~"ประเทศไทย中华Việt Nam"; + let data = "ประเทศไทย中华Việt Nam".to_owned(); assert!(data.contains("ประเ")); assert!(data.contains("ะเ")); assert!(data.contains("中华")); @@ -3441,13 +3443,13 @@ mod tests { #[test] fn test_utf16() { let pairs = - [(~"𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n", + [("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n".to_owned(), ~[0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16, 0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf46_u16, 0xd800_u16, 0xdf39_u16, 0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf30_u16, 0x000a_u16]), - (~"𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n", + ("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n".to_owned(), ~[0xd801_u16, 0xdc12_u16, 0xd801_u16, 0xdc49_u16, 0xd801_u16, 0xdc2e_u16, 0xd801_u16, 0xdc40_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16, @@ -3455,7 +3457,7 @@ mod tests { 0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc4d_u16, 0x000a_u16]), - (~"𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n", + ("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n".to_owned(), ~[0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16, 0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf04_u16, 0xd800_u16, 0xdf11_u16, 0xd800_u16, 0xdf09_u16, @@ -3464,7 +3466,7 @@ mod tests { 0xdf04_u16, 0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]), - (~"𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n", + ("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n".to_owned(), ~[0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16, 0xd801_u16, 0xdc88_u16, 0xd801_u16, 0xdc91_u16, 0xd801_u16, 0xdc9b_u16, 0xd801_u16, 0xdc92_u16, @@ -3477,7 +3479,7 @@ mod tests { 0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16, 0x000a_u16 ]), // Issue #12318, even-numbered non-BMP planes - (~"\U00020000", + ("\U00020000".to_owned(), ~[0xD840, 0xDC00])]; for p in pairs.iter() { @@ -3512,15 +3514,15 @@ mod tests { fn test_utf16_lossy() { // completely positive cases tested above. // lead + eof - assert_eq!(from_utf16_lossy([0xD800]), ~"\uFFFD"); + assert_eq!(from_utf16_lossy([0xD800]), "\uFFFD".to_owned()); // lead + lead - assert_eq!(from_utf16_lossy([0xD800, 0xD800]), ~"\uFFFD\uFFFD"); + assert_eq!(from_utf16_lossy([0xD800, 0xD800]), "\uFFFD\uFFFD".to_owned()); // isolated trail - assert_eq!(from_utf16_lossy([0x0061, 0xDC00]), ~"a\uFFFD"); + assert_eq!(from_utf16_lossy([0x0061, 0xDC00]), "a\uFFFD".to_owned()); // general - assert_eq!(from_utf16_lossy([0xD800, 0xd801, 0xdc8b, 0xD800]), ~"\uFFFD𐒋\uFFFD"); + assert_eq!(from_utf16_lossy([0xD800, 0xd801, 0xdc8b, 0xD800]), "\uFFFD𐒋\uFFFD".to_owned()); } #[test] @@ -3543,7 +3545,7 @@ mod tests { #[test] fn test_char_at() { - let s = ~"ศไทย中华Việt Nam"; + let s = "ศไทย中华Việt Nam".to_owned(); let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = 0; for ch in v.iter() { @@ -3554,7 +3556,7 @@ mod tests { #[test] fn test_char_at_reverse() { - let s = ~"ศไทย中华Việt Nam"; + let s = "ศไทย中华Việt Nam".to_owned(); let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = s.len(); for ch in v.rev_iter() { @@ -3565,27 +3567,27 @@ mod tests { #[test] fn test_escape_unicode() { - assert_eq!("abc".escape_unicode(), ~"\\x61\\x62\\x63"); - assert_eq!("a c".escape_unicode(), ~"\\x61\\x20\\x63"); - assert_eq!("\r\n\t".escape_unicode(), ~"\\x0d\\x0a\\x09"); - assert_eq!("'\"\\".escape_unicode(), ~"\\x27\\x22\\x5c"); - assert_eq!("\x00\x01\xfe\xff".escape_unicode(), ~"\\x00\\x01\\xfe\\xff"); - assert_eq!("\u0100\uffff".escape_unicode(), ~"\\u0100\\uffff"); - assert_eq!("\U00010000\U0010ffff".escape_unicode(), ~"\\U00010000\\U0010ffff"); - assert_eq!("ab\ufb00".escape_unicode(), ~"\\x61\\x62\\ufb00"); - assert_eq!("\U0001d4ea\r".escape_unicode(), ~"\\U0001d4ea\\x0d"); + assert_eq!("abc".escape_unicode(), "\\x61\\x62\\x63".to_owned()); + assert_eq!("a c".escape_unicode(), "\\x61\\x20\\x63".to_owned()); + assert_eq!("\r\n\t".escape_unicode(), "\\x0d\\x0a\\x09".to_owned()); + assert_eq!("'\"\\".escape_unicode(), "\\x27\\x22\\x5c".to_owned()); + assert_eq!("\x00\x01\xfe\xff".escape_unicode(), "\\x00\\x01\\xfe\\xff".to_owned()); + assert_eq!("\u0100\uffff".escape_unicode(), "\\u0100\\uffff".to_owned()); + assert_eq!("\U00010000\U0010ffff".escape_unicode(), "\\U00010000\\U0010ffff".to_owned()); + assert_eq!("ab\ufb00".escape_unicode(), "\\x61\\x62\\ufb00".to_owned()); + assert_eq!("\U0001d4ea\r".escape_unicode(), "\\U0001d4ea\\x0d".to_owned()); } #[test] fn test_escape_default() { - assert_eq!("abc".escape_default(), ~"abc"); - assert_eq!("a c".escape_default(), ~"a c"); - assert_eq!("\r\n\t".escape_default(), ~"\\r\\n\\t"); - assert_eq!("'\"\\".escape_default(), ~"\\'\\\"\\\\"); - assert_eq!("\u0100\uffff".escape_default(), ~"\\u0100\\uffff"); - assert_eq!("\U00010000\U0010ffff".escape_default(), ~"\\U00010000\\U0010ffff"); - assert_eq!("ab\ufb00".escape_default(), ~"ab\\ufb00"); - assert_eq!("\U0001d4ea\r".escape_default(), ~"\\U0001d4ea\\r"); + assert_eq!("abc".escape_default(), "abc".to_owned()); + assert_eq!("a c".escape_default(), "a c".to_owned()); + assert_eq!("\r\n\t".escape_default(), "\\r\\n\\t".to_owned()); + assert_eq!("'\"\\".escape_default(), "\\'\\\"\\\\".to_owned()); + assert_eq!("\u0100\uffff".escape_default(), "\\u0100\\uffff".to_owned()); + assert_eq!("\U00010000\U0010ffff".escape_default(), "\\U00010000\\U0010ffff".to_owned()); + assert_eq!("ab\ufb00".escape_default(), "ab\\ufb00".to_owned()); + assert_eq!("\U0001d4ea\r".escape_default(), "\\U0001d4ea\\r".to_owned()); } #[test] @@ -3599,7 +3601,7 @@ mod tests { #[test] fn test_char_range_at() { - let data = ~"b¢€𤭢𤭢€¢b"; + let data = "b¢€𤭢𤭢€¢b".to_owned(); assert_eq!('b', data.char_range_at(0).ch); assert_eq!('¢', data.char_range_at(1).ch); assert_eq!('€', data.char_range_at(3).ch); @@ -3629,15 +3631,15 @@ mod tests { ); t!("foo", "bar", "foobar"); - t!("foo", ~"bar", "foobar"); + t!("foo", "bar".to_owned(), "foobar"); t!("ศไทย中", "华Việt Nam", "ศไทย中华Việt Nam"); - t!("ศไทย中", ~"华Việt Nam", "ศไทย中华Việt Nam"); + t!("ศไทย中", "华Việt Nam".to_owned(), "ศไทย中华Việt Nam"); } #[test] fn test_iterator() { use iter::*; - let s = ~"ศไทย中华Việt Nam"; + let s = "ศไทย中华Việt Nam".to_owned(); let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = 0; @@ -3653,7 +3655,7 @@ mod tests { #[test] fn test_rev_iterator() { use iter::*; - let s = ~"ศไทย中华Việt Nam"; + let s = "ศไทย中华Việt Nam".to_owned(); let v = ~['m', 'a', 'N', ' ', 't', 'ệ','i','V','华','中','ย','ท','ไ','ศ']; let mut pos = 0; @@ -3676,7 +3678,7 @@ mod tests { #[test] fn test_bytesator() { - let s = ~"ศไทย中华Việt Nam"; + let s = "ศไทย中华Việt Nam".to_owned(); let v = [ 224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228, 184, 173, 229, 141, 142, 86, 105, 225, 187, 135, 116, 32, 78, 97, @@ -3692,7 +3694,7 @@ mod tests { #[test] fn test_bytes_revator() { - let s = ~"ศไทย中华Việt Nam"; + let s = "ศไทย中华Việt Nam".to_owned(); let v = [ 224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228, 184, 173, 229, 141, 142, 86, 105, 225, 187, 135, 116, 32, 78, 97, @@ -3849,30 +3851,30 @@ mod tests { #[test] fn test_nfd_chars() { - assert_eq!("abc".nfd_chars().collect::<~str>(), ~"abc"); - assert_eq!("\u1e0b\u01c4".nfd_chars().collect::<~str>(), ~"d\u0307\u01c4"); - assert_eq!("\u2026".nfd_chars().collect::<~str>(), ~"\u2026"); - assert_eq!("\u2126".nfd_chars().collect::<~str>(), ~"\u03a9"); - assert_eq!("\u1e0b\u0323".nfd_chars().collect::<~str>(), ~"d\u0323\u0307"); - assert_eq!("\u1e0d\u0307".nfd_chars().collect::<~str>(), ~"d\u0323\u0307"); - assert_eq!("a\u0301".nfd_chars().collect::<~str>(), ~"a\u0301"); - assert_eq!("\u0301a".nfd_chars().collect::<~str>(), ~"\u0301a"); - assert_eq!("\ud4db".nfd_chars().collect::<~str>(), ~"\u1111\u1171\u11b6"); - assert_eq!("\uac1c".nfd_chars().collect::<~str>(), ~"\u1100\u1162"); + assert_eq!("abc".nfd_chars().collect::<~str>(), "abc".to_owned()); + assert_eq!("\u1e0b\u01c4".nfd_chars().collect::<~str>(), "d\u0307\u01c4".to_owned()); + assert_eq!("\u2026".nfd_chars().collect::<~str>(), "\u2026".to_owned()); + assert_eq!("\u2126".nfd_chars().collect::<~str>(), "\u03a9".to_owned()); + assert_eq!("\u1e0b\u0323".nfd_chars().collect::<~str>(), "d\u0323\u0307".to_owned()); + assert_eq!("\u1e0d\u0307".nfd_chars().collect::<~str>(), "d\u0323\u0307".to_owned()); + assert_eq!("a\u0301".nfd_chars().collect::<~str>(), "a\u0301".to_owned()); + assert_eq!("\u0301a".nfd_chars().collect::<~str>(), "\u0301a".to_owned()); + assert_eq!("\ud4db".nfd_chars().collect::<~str>(), "\u1111\u1171\u11b6".to_owned()); + assert_eq!("\uac1c".nfd_chars().collect::<~str>(), "\u1100\u1162".to_owned()); } #[test] fn test_nfkd_chars() { - assert_eq!("abc".nfkd_chars().collect::<~str>(), ~"abc"); - assert_eq!("\u1e0b\u01c4".nfkd_chars().collect::<~str>(), ~"d\u0307DZ\u030c"); - assert_eq!("\u2026".nfkd_chars().collect::<~str>(), ~"..."); - assert_eq!("\u2126".nfkd_chars().collect::<~str>(), ~"\u03a9"); - assert_eq!("\u1e0b\u0323".nfkd_chars().collect::<~str>(), ~"d\u0323\u0307"); - assert_eq!("\u1e0d\u0307".nfkd_chars().collect::<~str>(), ~"d\u0323\u0307"); - assert_eq!("a\u0301".nfkd_chars().collect::<~str>(), ~"a\u0301"); - assert_eq!("\u0301a".nfkd_chars().collect::<~str>(), ~"\u0301a"); - assert_eq!("\ud4db".nfkd_chars().collect::<~str>(), ~"\u1111\u1171\u11b6"); - assert_eq!("\uac1c".nfkd_chars().collect::<~str>(), ~"\u1100\u1162"); + assert_eq!("abc".nfkd_chars().collect::<~str>(), "abc".to_owned()); + assert_eq!("\u1e0b\u01c4".nfkd_chars().collect::<~str>(), "d\u0307DZ\u030c".to_owned()); + assert_eq!("\u2026".nfkd_chars().collect::<~str>(), "...".to_owned()); + assert_eq!("\u2126".nfkd_chars().collect::<~str>(), "\u03a9".to_owned()); + assert_eq!("\u1e0b\u0323".nfkd_chars().collect::<~str>(), "d\u0323\u0307".to_owned()); + assert_eq!("\u1e0d\u0307".nfkd_chars().collect::<~str>(), "d\u0323\u0307".to_owned()); + assert_eq!("a\u0301".nfkd_chars().collect::<~str>(), "a\u0301".to_owned()); + assert_eq!("\u0301a".nfkd_chars().collect::<~str>(), "\u0301a".to_owned()); + assert_eq!("\ud4db".nfkd_chars().collect::<~str>(), "\u1111\u1171\u11b6".to_owned()); + assert_eq!("\uac1c".nfkd_chars().collect::<~str>(), "\u1100\u1162".to_owned()); } #[test] @@ -3926,9 +3928,9 @@ mod tests { v.iter().map(|x| x.len()).sum() } - let s = ~"01234"; + let s = "01234".to_owned(); assert_eq!(5, sum_len(["012", "", "34"])); - assert_eq!(5, sum_len([~"01", ~"2", ~"34", ~""])); + assert_eq!(5, sum_len(["01".to_owned(), "2".to_owned(), "34".to_owned(), "".to_owned()])); assert_eq!(5, sum_len([s.as_slice()])); } @@ -3947,10 +3949,10 @@ mod tests { #[test] fn test_str_from_utf8_owned() { let xs = bytes!("hello").to_owned(); - assert_eq!(from_utf8_owned(xs), Some(~"hello")); + assert_eq!(from_utf8_owned(xs), Some("hello".to_owned())); let xs = bytes!("ศไทย中华Việt Nam").to_owned(); - assert_eq!(from_utf8_owned(xs), Some(~"ศไทย中华Việt Nam")); + assert_eq!(from_utf8_owned(xs), Some("ศไทย中华Việt Nam".to_owned())); let xs = bytes!("hello", 0xff).to_owned(); assert_eq!(from_utf8_owned(xs), None); @@ -3965,32 +3967,34 @@ mod tests { assert_eq!(from_utf8_lossy(xs), Slice("ศไทย中华Việt Nam")); let xs = bytes!("Hello", 0xC2, " There", 0xFF, " Goodbye"); - assert_eq!(from_utf8_lossy(xs), Owned(~"Hello\uFFFD There\uFFFD Goodbye")); + assert_eq!(from_utf8_lossy(xs), Owned("Hello\uFFFD There\uFFFD Goodbye".to_owned())); let xs = bytes!("Hello", 0xC0, 0x80, " There", 0xE6, 0x83, " Goodbye"); - assert_eq!(from_utf8_lossy(xs), Owned(~"Hello\uFFFD\uFFFD There\uFFFD Goodbye")); + assert_eq!(from_utf8_lossy(xs), Owned("Hello\uFFFD\uFFFD There\uFFFD Goodbye".to_owned())); let xs = bytes!(0xF5, "foo", 0xF5, 0x80, "bar"); - assert_eq!(from_utf8_lossy(xs), Owned(~"\uFFFDfoo\uFFFD\uFFFDbar")); + assert_eq!(from_utf8_lossy(xs), Owned("\uFFFDfoo\uFFFD\uFFFDbar".to_owned())); let xs = bytes!(0xF1, "foo", 0xF1, 0x80, "bar", 0xF1, 0x80, 0x80, "baz"); - assert_eq!(from_utf8_lossy(xs), Owned(~"\uFFFDfoo\uFFFDbar\uFFFDbaz")); + assert_eq!(from_utf8_lossy(xs), Owned("\uFFFDfoo\uFFFDbar\uFFFDbaz".to_owned())); let xs = bytes!(0xF4, "foo", 0xF4, 0x80, "bar", 0xF4, 0xBF, "baz"); - assert_eq!(from_utf8_lossy(xs), Owned(~"\uFFFDfoo\uFFFDbar\uFFFD\uFFFDbaz")); + assert_eq!(from_utf8_lossy(xs), Owned("\uFFFDfoo\uFFFDbar\uFFFD\uFFFDbaz".to_owned())); let xs = bytes!(0xF0, 0x80, 0x80, 0x80, "foo", 0xF0, 0x90, 0x80, 0x80, "bar"); - assert_eq!(from_utf8_lossy(xs), Owned(~"\uFFFD\uFFFD\uFFFD\uFFFDfoo\U00010000bar")); + assert_eq!(from_utf8_lossy(xs), Owned("\uFFFD\uFFFD\uFFFD\uFFFD\ + foo\U00010000bar".to_owned())); // surrogates let xs = bytes!(0xED, 0xA0, 0x80, "foo", 0xED, 0xBF, 0xBF, "bar"); - assert_eq!(from_utf8_lossy(xs), Owned(~"\uFFFD\uFFFD\uFFFDfoo\uFFFD\uFFFD\uFFFDbar")); + assert_eq!(from_utf8_lossy(xs), Owned("\uFFFD\uFFFD\uFFFDfoo\ + \uFFFD\uFFFD\uFFFDbar".to_owned())); } #[test] fn test_from_str() { let owned: Option<~str> = from_str(&"string"); - assert_eq!(owned, Some(~"string")); + assert_eq!(owned, Some("string".to_owned())); } #[test] @@ -3998,18 +4002,18 @@ mod tests { let s = Slice("abcde"); assert_eq!(s.len(), 5); assert_eq!(s.as_slice(), "abcde"); - assert_eq!(s.to_str(), ~"abcde"); - assert_eq!(format!("{}", s), ~"abcde"); - assert!(s.lt(&Owned(~"bcdef"))); + assert_eq!(s.to_str(), "abcde".to_owned()); + assert_eq!(format!("{}", s), "abcde".to_owned()); + assert!(s.lt(&Owned("bcdef".to_owned()))); assert_eq!(Slice(""), Default::default()); - let o = Owned(~"abcde"); + let o = Owned("abcde".to_owned()); assert_eq!(o.len(), 5); assert_eq!(o.as_slice(), "abcde"); - assert_eq!(o.to_str(), ~"abcde"); - assert_eq!(format!("{}", o), ~"abcde"); + assert_eq!(o.to_str(), "abcde".to_owned()); + assert_eq!(format!("{}", o), "abcde".to_owned()); assert!(o.lt(&Slice("bcdef"))); - assert_eq!(Owned(~""), Default::default()); + assert_eq!(Owned("".to_owned()), Default::default()); assert!(s.cmp(&o) == Equal); assert!(s.equiv(&o)); @@ -4024,31 +4028,31 @@ mod tests { assert!(s.is_slice()); assert!(!s.is_owned()); - let o = Owned(~"abcde"); + let o = Owned("abcde".to_owned()); assert!(!o.is_slice()); assert!(o.is_owned()); } #[test] fn test_maybe_owned_clone() { - assert_eq!(Owned(~"abcde"), Slice("abcde").clone()); - assert_eq!(Owned(~"abcde"), Owned(~"abcde").clone()); + assert_eq!(Owned("abcde".to_owned()), Slice("abcde").clone()); + assert_eq!(Owned("abcde".to_owned()), Owned("abcde".to_owned()).clone()); assert_eq!(Slice("abcde"), Slice("abcde").clone()); - assert_eq!(Slice("abcde"), Owned(~"abcde").clone()); + assert_eq!(Slice("abcde"), Owned("abcde".to_owned()).clone()); } #[test] fn test_maybe_owned_into_owned() { - assert_eq!(Slice("abcde").into_owned(), ~"abcde"); - assert_eq!(Owned(~"abcde").into_owned(), ~"abcde"); + assert_eq!(Slice("abcde").into_owned(), "abcde".to_owned()); + assert_eq!(Owned("abcde".to_owned()).into_owned(), "abcde".to_owned()); } #[test] fn test_into_maybe_owned() { assert_eq!("abcde".into_maybe_owned(), Slice("abcde")); - assert_eq!((~"abcde").into_maybe_owned(), Slice("abcde")); - assert_eq!("abcde".into_maybe_owned(), Owned(~"abcde")); - assert_eq!((~"abcde").into_maybe_owned(), Owned(~"abcde")); + assert_eq!(("abcde".to_owned()).into_maybe_owned(), Slice("abcde")); + assert_eq!("abcde".into_maybe_owned(), Owned("abcde".to_owned())); + assert_eq!(("abcde".to_owned()).into_maybe_owned(), Owned("abcde".to_owned())); } } diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs index 498a6252a8f..7ac7700d8d3 100644 --- a/src/libstd/sync/arc.rs +++ b/src/libstd/sync/arc.rs @@ -181,12 +181,12 @@ mod tests { #[test] fn arclike_newN() { // Tests that the many-refcounts-at-once constructors don't leak. - let _ = UnsafeArc::new2(~~"hello"); - let x = UnsafeArc::newN(~~"hello", 0); + let _ = UnsafeArc::new2("hello".to_owned().to_owned()); + let x = UnsafeArc::newN("hello".to_owned().to_owned(), 0); assert_eq!(x.len(), 0) - let x = UnsafeArc::newN(~~"hello", 1); + let x = UnsafeArc::newN("hello".to_owned().to_owned(), 1); assert_eq!(x.len(), 1) - let x = UnsafeArc::newN(~~"hello", 10); + let x = UnsafeArc::newN("hello".to_owned().to_owned(), 10); assert_eq!(x.len(), 10) } } diff --git a/src/libstd/task.rs b/src/libstd/task.rs index df627809ea0..610df320fa5 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -48,6 +48,7 @@ use str::{Str, SendStr, IntoMaybeOwned}; #[cfg(test)] use any::{AnyOwnExt, AnyRefExt}; #[cfg(test)] use result; +#[cfg(test)] use str::StrSlice; /// Indicates the manner in which a task exited. /// @@ -297,7 +298,7 @@ fn test_unnamed_task() { #[test] fn test_owned_named_task() { - task().named(~"ada lovelace").spawn(proc() { + task().named("ada lovelace".to_owned()).spawn(proc() { with_task_name(|name| { assert!(name.unwrap() == "ada lovelace"); }) @@ -369,7 +370,7 @@ fn test_back_to_the_future_result() { #[test] fn test_try_success() { match try(proc() { - ~"Success!" + "Success!".to_owned() }).as_ref().map(|s| s.as_slice()) { result::Ok("Success!") => (), _ => fail!() @@ -499,12 +500,12 @@ fn test_try_fail_message_static_str() { #[test] fn test_try_fail_message_owned_str() { match try(proc() { - fail!(~"owned string"); + fail!("owned string".to_owned()); }) { Err(e) => { type T = ~str; assert!(e.is::<T>()); - assert_eq!(*e.move::<T>().unwrap(), ~"owned string"); + assert_eq!(*e.move::<T>().unwrap(), "owned string".to_owned()); } Ok(()) => fail!() } diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index ba3c1c0fc45..d29b0b3b07c 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -35,26 +35,27 @@ impl<T: fmt::Show> ToStr for T { #[cfg(test)] mod tests { use super::*; + use str::StrSlice; #[test] fn test_simple_types() { - assert_eq!(1i.to_str(), ~"1"); - assert_eq!((-1i).to_str(), ~"-1"); - assert_eq!(200u.to_str(), ~"200"); - assert_eq!(2u8.to_str(), ~"2"); - assert_eq!(true.to_str(), ~"true"); - assert_eq!(false.to_str(), ~"false"); - assert_eq!(().to_str(), ~"()"); - assert_eq!((~"hi").to_str(), ~"hi"); + assert_eq!(1i.to_str(), "1".to_owned()); + assert_eq!((-1i).to_str(), "-1".to_owned()); + assert_eq!(200u.to_str(), "200".to_owned()); + assert_eq!(2u8.to_str(), "2".to_owned()); + assert_eq!(true.to_str(), "true".to_owned()); + assert_eq!(false.to_str(), "false".to_owned()); + assert_eq!(().to_str(), "()".to_owned()); + assert_eq!(("hi".to_owned()).to_str(), "hi".to_owned()); } #[test] fn test_vectors() { let x: ~[int] = ~[]; - assert_eq!(x.to_str(), ~"[]"); - assert_eq!((~[1]).to_str(), ~"[1]"); - assert_eq!((~[1, 2, 3]).to_str(), ~"[1, 2, 3]"); + assert_eq!(x.to_str(), "[]".to_owned()); + assert_eq!((~[1]).to_str(), "[1]".to_owned()); + assert_eq!((~[1, 2, 3]).to_str(), "[1, 2, 3]".to_owned()); assert!((~[~[], ~[1], ~[1, 1]]).to_str() == - ~"[[], [1], [1, 1]]"); + "[[], [1], [1, 1]]".to_owned()); } } diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index 732b006b245..cf63ea43fdb 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -266,10 +266,11 @@ mod tests { use super::*; use clone::Clone; use cmp::*; + use str::StrSlice; #[test] fn test_clone() { - let a = (1, ~"2"); + let a = (1, "2".to_owned()); let b = a.clone(); assert_eq!(a, b); } @@ -342,8 +343,8 @@ mod tests { #[test] fn test_show() { - assert_eq!(format!("{}", (1,)), ~"(1,)"); - assert_eq!(format!("{}", (1, true)), ~"(1, true)"); - assert_eq!(format!("{}", (1, ~"hi", true)), ~"(1, hi, true)"); + assert_eq!(format!("{}", (1,)), "(1,)".to_owned()); + assert_eq!(format!("{}", (1, true)), "(1, true)".to_owned()); + assert_eq!(format!("{}", (1, "hi".to_owned(), true)), "(1, hi, true)".to_owned()); } } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 5480805478c..585bed83101 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -626,7 +626,7 @@ impl<T> Vec<T> { /// # Example /// /// ```rust - /// let v = vec!(~"a", ~"b"); + /// let v = vec!("a".to_owned(), "b".to_owned()); /// for s in v.move_iter() { /// // s has type ~str, not &~str /// println!("{}", s); @@ -830,13 +830,13 @@ impl<T> Vec<T> { /// /// # Example /// ```rust - /// let mut v = vec!(~"foo", ~"bar", ~"baz", ~"qux"); + /// let mut v = vec!("foo".to_owned(), "bar".to_owned(), "baz".to_owned(), "qux".to_owned()); /// - /// assert_eq!(v.swap_remove(1), Some(~"bar")); - /// assert_eq!(v, vec!(~"foo", ~"qux", ~"baz")); + /// assert_eq!(v.swap_remove(1), Some("bar".to_owned())); + /// assert_eq!(v, vec!("foo".to_owned(), "qux".to_owned(), "baz".to_owned())); /// - /// assert_eq!(v.swap_remove(0), Some(~"foo")); - /// assert_eq!(v, vec!(~"baz", ~"qux")); + /// assert_eq!(v.swap_remove(0), Some("foo".to_owned())); + /// assert_eq!(v, vec!("baz".to_owned(), "qux".to_owned())); /// /// assert_eq!(v.swap_remove(2), None); /// ``` |
