Skip to content

Commit

Permalink
std: update & de-~[] path's tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
huonw committed Apr 12, 2014
1 parent 1283caa commit 31074fd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 57 deletions.
2 changes: 2 additions & 0 deletions src/libstd/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ println!("path exists: {}", path.exists());
*/

#![deny(deprecated_owned_vector)]

use container::Container;
use c_str::CString;
use clone::Clone;
Expand Down
45 changes: 19 additions & 26 deletions src/libstd/path/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -1186,29 +1186,26 @@ mod tests {
(s: $path:expr, $exp:expr) => (
{
let path = Path::new($path);
let comps = path.components().collect::<~[&[u8]]>();
let comps = path.components().collect::<Vec<&[u8]>>();
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::<Vec<&[u8]>>();
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::<Vec<&[u8]>>();
let exps = exps.move_iter().rev().collect::<Vec<&[u8]>>();
assert!(comps == exps, "rev_components: Expected {:?}, found {:?}",
comps, exps);
}
);
(v: [$($arg:expr),+], [$([$($exp:expr),*]),*]) => (
{
let path = Path::new(b!($($arg),+));
let comps = path.components().collect::<~[&[u8]]>();
let comps = path.components().collect::<Vec<&[u8]>>();
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::<Vec<&[u8]>>();
let exp = exp.rev_iter().map(|&x|x).collect::<Vec<&[u8]>>();
assert_eq!(comps, exp)
}
)
)
Expand All @@ -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::<Vec<Option<&str>>>();
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::<Vec<Option<&str>>>();
let exp = exp.rev_iter().map(|&x|x).collect::<Vec<Option<&str>>>();
assert_eq!(comps, exp);
}
)
)
Expand Down
52 changes: 21 additions & 31 deletions src/libstd/path/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -2235,33 +2236,25 @@ mod tests {
{
let path = Path::new($path);
let comps = path.str_components().map(|x|x.unwrap())
.collect::<~[&str]>();
.collect::<Vec<&str>>();
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::<Vec<&str>>();
let exp = exp.rev_iter().map(|&x|x).collect::<Vec<&str>>();
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::<Vec<&str>>();
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::<Vec<&str>>();
let exp = exp.rev_iter().map(|&x|x).collect::<Vec<&str>>();
assert_eq!(comps, exp);
}
)
)
Expand Down Expand Up @@ -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::<Vec<&[u8]>>();
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::<Vec<&[u8]>>();
let exp = exp.rev_iter().map(|&x|x).collect::<Vec<&[u8]>>();
assert_eq!(comps, exp);
}
)
)
Expand Down

1 comment on commit 31074fd

@alexcrichton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

Please sign in to comment.