diff --git a/src/glob/parser/main.rs b/src/glob/parser/main.rs index 6caeb45..96aa50f 100644 --- a/src/glob/parser/main.rs +++ b/src/glob/parser/main.rs @@ -4,10 +4,8 @@ use crate::glob::{Glob, Matcher}; pub fn parse(glob: &str) -> Glob { let mut retval = Glob(vec![]); let mut stack = AltStack::new(); - let mut found_sep: bool = false; for segment in glob.split('/') { retval.append_char('/'); - found_sep = retval.0.len() > 1; let mut chars = segment.chars().peekable(); while let Some(c) = chars.next() { match c { @@ -64,7 +62,7 @@ pub fn parse(glob: &str) -> Glob { break; } } - if found_sep { + if glob.contains("/") { *retval.0.first_mut().unwrap() = Matcher::End; } if let Some(Matcher::Sep) = retval.0.last() { diff --git a/src/tests/glob.rs b/src/tests/glob.rs index be7059c..2f9f6a8 100644 --- a/src/tests/glob.rs +++ b/src/tests/glob.rs @@ -44,6 +44,31 @@ fn path() { ); } +#[test] +fn root_star() { + test( + "/*", + ["/foo.txt", "/bar.xml", "/baz.json"], + ["/bar/foo/baz.txt", "/baz/bar/foo.xml", "/bar/foo.txt"], + ); +} + +#[test] +fn root_double_star() { + test( + "/**", + [ + "/foo.txt", + "/bar.xml", + "/baz.json", + "/bar/foo/baz.txt", + "/baz/bar/foo.xml", + "/bar/foo.txt", + ], + [], + ); +} + #[test] fn star() { test("*", ["/*", "/a"], []);