summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGal Ofri <galmenashofri@gmail.com>2023-04-13 08:28:16 +0300
committerAndrew Gallant <jamslam@gmail.com>2023-07-08 18:52:42 -0400
commit36194c27427a6df76963da472b13c36f47410824 (patch)
treeb0b2ce2422eb419d470fa2eb590e2f4b65dbdbaf /tests
parent0c1cbd99f36e4b97cbb915e9c5a7c0c091522105 (diff)
test: test that regex inline flags work as intended
This was originally fixed by using non-capturing groups when joining patterns in crates/core/args.rs, but before that landed, it ended up getting fixed via a refactor in the course of migrating to regex 1.9. Namely, it's now fixed by pushing pattern joining down into the regex layer, so that patterns can be joined in the most effective way possible. Still, #2488 contains a useful test, so we bring that in here. The test actually failed for `rg -e ')('`, since it expected the command to fail with a syntax error. But my refactor actually causes this command to succeed. And indeed, #2488 worked around this by special casing a single pattern. That work-around fixes it for the single pattern case, but doesn't fix it for the -w or -X or multi-pattern case. So for now, we're content to leave well enough alone. The only real way to fix this for real is to parse each regexp individual and verify that each is valid on its own. It's not clear that doing so is worth it. Fixes #2480, Closes #2488
Diffstat (limited to 'tests')
-rw-r--r--tests/regression.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/regression.rs b/tests/regression.rs
index e2c56968..1cc7d5a2 100644
--- a/tests/regression.rs
+++ b/tests/regression.rs
@@ -1126,3 +1126,37 @@ rgtest!(r2236, |dir: Dir, mut cmd: TestCommand| {
dir.create("foo/bar", "test\n");
cmd.args(&["test"]).assert_err();
});
+
+// See: https://github.com/BurntSushi/ripgrep/issues/2480
+rgtest!(r2480, |dir: Dir, mut cmd: TestCommand| {
+ dir.create("file", "FooBar\n");
+
+ // no regression in empty pattern behavior
+ cmd.args(&["-e", "", "file"]);
+ eqnice!("FooBar\n", cmd.stdout());
+
+ // no regression in single pattern behavior
+ let mut cmd = dir.command();
+ cmd.args(&["-e", ")(", "file"]);
+ eqnice!("FooBar\n", cmd.stdout());
+
+ // no regression in multiple patterns behavior
+ let mut cmd = dir.command();
+ cmd.args(&["--only-matching", "-e", "Foo", "-e", "Bar", "file"]);
+ eqnice!("Foo\nBar\n", cmd.stdout());
+
+ // no regression in capture groups behavior
+ let mut cmd = dir.command();
+ cmd.args(&["-e", "Fo(oB)a(r)", "--replace", "${0}_${1}_${2}${3}", "file"]);
+ eqnice!("FooBar_oB_r\n", cmd.stdout()); // note: ${3} expected to be empty
+
+ // flag does not leak into next pattern on match
+ let mut cmd = dir.command();
+ cmd.args(&["--only-matching", "-e", "(?i)foo", "-e", "bar", "file"]);
+ eqnice!("Foo\n", cmd.stdout());
+
+ // flag does not leak into next pattern on mismatch
+ let mut cmd = dir.command();
+ cmd.args(&["--only-matching", "-e", "(?i)notfoo", "-e", "bar", "file"]);
+ cmd.assert_err();
+});