Skip to content

Commit a0af270

Browse files
fb-ikhlepitkoJohnTitor
authored andcommitted
Added some tests for function.
1 parent 949a5b0 commit a0af270

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/glob-std.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
extern crate glob;
1616
extern crate tempdir;
1717

18-
use glob::glob;
18+
use glob::{glob, glob_with};
1919
use std::env;
2020
use std::fs;
2121
use std::path::PathBuf;
@@ -35,6 +35,10 @@ fn main() {
3535
glob(pattern).unwrap().map(|r| r.unwrap()).collect()
3636
}
3737

38+
fn glob_with_vec(pattern: &str, options: &glob::MatchOptions) -> Vec<PathBuf> {
39+
glob_with(pattern, options).unwrap().map(|r| r.unwrap()).collect()
40+
}
41+
3842
let root = TempDir::new("glob-tests");
3943
let root = root.ok().expect("Should have created a temp directory");
4044
assert!(env::set_current_dir(root.path()).is_ok());
@@ -288,6 +292,26 @@ fn main() {
288292
vec!(PathBuf::from("bbb/specials/]"))
289293
);
290294

295+
mk_file("i", true);
296+
mk_file("i/qwe", true);
297+
mk_file("i/qwe/.aaa", false);
298+
mk_file("i/qwe/.bbb", true);
299+
mk_file("i/qwe/.bbb/ccc", false);
300+
mk_file("i/qwe/.bbb/.ddd", false);
301+
mk_file("i/qwe/eee", false);
302+
303+
let options = glob::MatchOptions {
304+
case_sensitive: false,
305+
require_literal_separator: true,
306+
require_literal_leading_dot: true,
307+
};
308+
assert_eq!(glob_with_vec("i/**/*a*", &options), Vec::<PathBuf>::new());
309+
assert_eq!(glob_with_vec("i/**/*c*", &options), Vec::<PathBuf>::new());
310+
assert_eq!(glob_with_vec("i/**/*d*", &options), Vec::<PathBuf>::new());
311+
assert_eq!(glob_with_vec("i/**/*e*", &options), vec!(
312+
PathBuf::from("i/qwe/eee")
313+
));
314+
291315
if env::consts::FAMILY != "windows" {
292316
assert_eq!(
293317
glob_vec("bbb/specials/[*]"),

0 commit comments

Comments
 (0)