From 9573218001c4109ed162ad664c87ba033c7f4e2c Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 25 Aug 2024 16:14:23 -0700 Subject: [PATCH] fix **/.lua matching in the root --- filenamegen/Cargo.toml | 2 +- filenamegen/src/lib.rs | 20 ++++++++++++++++++++ filenamegen/src/recursivewalker.rs | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/filenamegen/Cargo.toml b/filenamegen/Cargo.toml index 3412c35..303e42f 100644 --- a/filenamegen/Cargo.toml +++ b/filenamegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "filenamegen" -version = "0.2.6" +version = "0.2.7" authors = ["Wez Furlong"] edition = "2021" description = "Shell-style filename generation aka globbing" diff --git a/filenamegen/src/lib.rs b/filenamegen/src/lib.rs index 55fb1fa..c6348e4 100644 --- a/filenamegen/src/lib.rs +++ b/filenamegen/src/lib.rs @@ -360,6 +360,26 @@ mod test { Ok(()) } + #[test] + fn test_lua_toml() -> anyhow::Result<()> { + let root = make_fixture()?; + touch_files_in( + &root, + &["simple.lua", "assets/policy-extras/bar.lua", "assets/policy-extras/shaping.toml"], + )?; + let glob = Glob::new("**/*.{lua,toml}")?; + assert_eq!( + glob.walk(&root), + vec![ + PathBuf::from("assets/policy-extras/bar.lua"), + PathBuf::from("assets/policy-extras/shaping.toml"), + PathBuf::from("simple.lua"), + ] + ); + + Ok(()) + } + #[test] fn test_more() -> anyhow::Result<()> { let root = make_fixture()?; diff --git a/filenamegen/src/recursivewalker.rs b/filenamegen/src/recursivewalker.rs index d1c3778..09032b1 100644 --- a/filenamegen/src/recursivewalker.rs +++ b/filenamegen/src/recursivewalker.rs @@ -20,9 +20,9 @@ impl RecursiveWalker { Node::RecursiveMatch.append_regex(&mut pattern); for node in nodes { #[cfg(not(windows))] - pattern.push('/'); + pattern.push_str("/?"); #[cfg(windows)] - pattern.push_str("[/\\\\]"); + pattern.push_str("[/\\\\]?"); node.append_regex(&mut pattern); } pattern.push('$');