From 31074fdf2eb99b36100a04a7712ebf62df55d03a Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sat, 12 Apr 2014 20:56:23 +1000 Subject: [PATCH] std: update & de-~[] path's tests. --- src/libstd/path/mod.rs | 2 ++ src/libstd/path/posix.rs | 45 ++++++++++++++------------------- src/libstd/path/windows.rs | 52 +++++++++++++++----------------------- 3 files changed, 42 insertions(+), 57 deletions(-) diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index 88be22901a448..6a1f9c1a4c78e 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -63,6 +63,8 @@ println!("path exists: {}", path.exists()); */ +#![deny(deprecated_owned_vector)] + use container::Container; use c_str::CString; use clone::Clone; diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 72832f0a44fc0..1a80e52359d24 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -518,9 +518,9 @@ mod tests { t!(s: Path::new("foo/../../.."), "../.."); t!(s: Path::new("foo/../../bar"), "../bar"); - assert!(Path::new(b!("foo/bar")).into_vec() == b!("foo/bar").to_owned()); - assert!(Path::new(b!("/foo/../../bar")).into_vec() == - b!("/bar").to_owned()); + assert_eq!(Path::new(b!("foo/bar")).into_vec().as_slice(), b!("foo/bar")); + assert_eq!(Path::new(b!("/foo/../../bar")).into_vec().as_slice(), + b!("/bar")); let p = Path::new(b!("foo/bar", 0x80)); assert!(p.as_str() == None); @@ -769,7 +769,7 @@ mod tests { t!(s: "a/b/c", [~"d", ~"e"], "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"), [b!("d").to_owned(), b!("e").to_owned()], 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")); } #[test] @@ -873,7 +873,7 @@ mod tests { t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", [~"d", ~"e"], "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").to_owned(), b!("e").to_owned()], 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")); } #[test] @@ -1186,13 +1186,13 @@ mod tests { (s: $path:expr, $exp:expr) => ( { let path = Path::new($path); - let comps = path.components().collect::<~[&[u8]]>(); + let comps = path.components().collect::>(); let exp: &[&str] = $exp; - let exps = exp.iter().map(|x| x.as_bytes()).collect::<~[&[u8]]>(); + let exps = exp.iter().map(|x| x.as_bytes()).collect::>(); assert!(comps == exps, "components: Expected {:?}, found {:?}", comps, exps); - let comps = path.rev_components().collect::<~[&[u8]]>(); - let exps = exps.move_rev_iter().collect::<~[&[u8]]>(); + let comps = path.rev_components().collect::>(); + let exps = exps.move_iter().rev().collect::>(); assert!(comps == exps, "rev_components: Expected {:?}, found {:?}", comps, exps); } @@ -1200,15 +1200,12 @@ mod tests { (v: [$($arg:expr),+], [$([$($exp:expr),*]),*]) => ( { let path = Path::new(b!($($arg),+)); - let comps = path.components().collect::<~[&[u8]]>(); + let comps = path.components().collect::>(); let exp: &[&[u8]] = [$(b!($($exp),*)),*]; - assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}", - comps.as_slice(), exp); - let comps = path.rev_components().collect::<~[&[u8]]>(); - let exp = exp.rev_iter().map(|&x|x).collect::<~[&[u8]]>(); - assert!(comps.as_slice() == exp, - "rev_components: Expected {:?}, found {:?}", - comps.as_slice(), exp); + assert_eq!(comps.as_slice(), exp); + let comps = path.rev_components().collect::>(); + let exp = exp.rev_iter().map(|&x|x).collect::>(); + assert_eq!(comps, exp) } ) ) @@ -1235,16 +1232,12 @@ mod tests { (v: [$($arg:expr),+], $exp:expr) => ( { let path = Path::new(b!($($arg),+)); - let comps = path.str_components().collect::<~[Option<&str>]>(); + let comps = path.str_components().collect::>>(); let exp: &[Option<&str>] = $exp; - assert!(comps.as_slice() == exp, - "str_components: Expected {:?}, found {:?}", - comps.as_slice(), exp); - let comps = path.rev_str_components().collect::<~[Option<&str>]>(); - let exp = exp.rev_iter().map(|&x|x).collect::<~[Option<&str>]>(); - assert!(comps.as_slice() == exp, - "rev_str_components: Expected {:?}, found {:?}", - comps.as_slice(), exp); + assert_eq!(comps.as_slice(), exp); + let comps = path.rev_str_components().collect::>>(); + let exp = exp.rev_iter().map(|&x|x).collect::>>(); + assert_eq!(comps, exp); } ) ) diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 739e13ea4ed10..435b64e8d2afd 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1225,9 +1225,8 @@ mod tests { t!(s: Path::new("foo\\..\\..\\.."), "..\\.."); t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar"); - assert_eq!(Path::new(b!("foo\\bar")).into_vec(), b!("foo\\bar").to_owned()); - assert_eq!(Path::new(b!("\\foo\\..\\..\\bar")).into_vec(), - b!("\\bar").to_owned()); + assert_eq!(Path::new(b!("foo\\bar")).into_vec().as_slice(), b!("foo\\bar")); + assert_eq!(Path::new(b!("\\foo\\..\\..\\bar")).into_vec().as_slice(), b!("\\bar")); t!(s: Path::new("\\\\a"), "\\a"); t!(s: Path::new("\\\\a\\"), "\\a"); @@ -1581,7 +1580,8 @@ mod tests { t!(s: "a\\b\\c", [~"d", ~"e"], "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"), [b!("d").to_owned(), b!("e").to_owned()], 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")); } #[test] @@ -1720,7 +1720,8 @@ mod tests { t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", [~"d", ~"e"], "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").to_owned(), b!("e").to_owned()], 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")); } #[test] @@ -2235,33 +2236,25 @@ mod tests { { let path = Path::new($path); let comps = path.str_components().map(|x|x.unwrap()) - .collect::<~[&str]>(); + .collect::>(); let exp: &[&str] = $exp; - assert!(comps.as_slice() == exp, - "str_components: Expected {:?}, found {:?}", - comps.as_slice(), exp); + assert_eq!(comps.as_slice(), exp); let comps = path.rev_str_components().map(|x|x.unwrap()) - .collect::<~[&str]>(); - let exp = exp.rev_iter().map(|&x|x).collect::<~[&str]>(); - assert!(comps.as_slice() == exp, - "rev_str_components: Expected {:?}, found {:?}", - comps.as_slice(), exp); + .collect::>(); + let exp = exp.rev_iter().map(|&x|x).collect::>(); + assert_eq!(comps, exp); } ); (v: [$($arg:expr),+], $exp:expr) => ( { let path = Path::new(b!($($arg),+)); - let comps = path.str_components().map(|x|x.unwrap()).collect::<~[&str]>(); + let comps = path.str_components().map(|x|x.unwrap()).collect::>(); let exp: &[&str] = $exp; - assert!(comps.as_slice() == exp, - "str_components: Expected {:?}, found {:?}", - comps.as_slice(), exp); + assert_eq!(comps.as_slice(), exp); let comps = path.rev_str_components().map(|x|x.unwrap()) - .collect::<~[&str]>(); - let exp = exp.rev_iter().map(|&x|x).collect::<~[&str]>(); - assert!(comps.as_slice() == exp, - "rev_str_components: Expected {:?}, found {:?}", - comps.as_slice(), exp); + .collect::>(); + let exp = exp.rev_iter().map(|&x|x).collect::>(); + assert_eq!(comps, exp); } ) ) @@ -2312,15 +2305,12 @@ mod tests { (s: $path:expr, $exp:expr) => ( { let path = Path::new($path); - let comps = path.components().collect::<~[&[u8]]>(); + let comps = path.components().collect::>(); let exp: &[&[u8]] = $exp; - assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}", - comps.as_slice(), exp); - let comps = path.rev_components().collect::<~[&[u8]]>(); - let exp = exp.rev_iter().map(|&x|x).collect::<~[&[u8]]>(); - assert!(comps.as_slice() == exp, - "rev_components: Expected {:?}, found {:?}", - comps.as_slice(), exp); + assert_eq!(comps.as_slice(), exp); + let comps = path.rev_components().collect::>(); + let exp = exp.rev_iter().map(|&x|x).collect::>(); + assert_eq!(comps, exp); } ) )