// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms.
// ignore-windows TempDir may cause IoError on windows: #10462
#![cfg_attr(test, deny(warnings))]
externcrate glob; externcrate tempdir;
use glob::glob; use std::env; use std::fs; use std::path::PathBuf; use tempdir::TempDir;
let root = TempDir::new("glob-tests"); let root = root.ok().expect("Should have created a temp directory");
assert!(env::set_current_dir(root.path()).is_ok());
// windows does not allow `*` or `?` characters to exist in filenames if env::consts::FAMILY != "windows" {
mk_file("bbb/specials/*", false);
mk_file("bbb/specials/?", false);
}
// followed by a wildcard
assert_eq!(
glob_vec("r/**/*.md"),
vec!(
PathBuf::from("r/another/a.md"),
PathBuf::from("r/current_dir.md"),
PathBuf::from("r/one/a.md"),
PathBuf::from("r/one/another/a.md"),
PathBuf::from("r/one/another/deep/spelunking.md"),
PathBuf::from("r/three/c.md"),
PathBuf::from("r/two/b.md")
)
);
// followed by a precise pattern
assert_eq!(
glob_vec("r/one/**/a.md"),
vec!(
PathBuf::from("r/one/a.md"),
PathBuf::from("r/one/another/a.md")
)
);
// followed by another recursive pattern // collapses consecutive recursives into one
assert_eq!(
glob_vec("r/one/**/**/a.md"),
vec!(
PathBuf::from("r/one/a.md"),
PathBuf::from("r/one/another/a.md")
)
);
// followed by two precise patterns
assert_eq!(
glob_vec("r/**/another/a.md"),
vec!(
PathBuf::from("r/another/a.md"),
PathBuf::from("r/one/another/a.md")
)
);
// windows should support both / and \ as directory separators if env::consts::FAMILY == "windows" {
assert_eq!(glob_vec("aaa\\apple"), vec!(PathBuf::from("aaa/apple")));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.