summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2023-11-22 16:04:26 -0500
committerAndrew Gallant <jamslam@gmail.com>2023-11-25 15:03:53 -0500
commit038524a580072e9346ee9f782679618e380f4f2e (patch)
tree6a62cc085639a86ab1415ab17fe813f5e949c2d7 /tests
parent8f9557d183d91aca8f72ce8c8401bcfb221e76c6 (diff)
printer: trim before applying max column windowing
Previously, we were applying the -M/--max-columns flag *before* triming prefix ASCII whitespace. But this doesn't make a whole lot of sense. We should be trimming first, but the result of trimming is ultimately what we'll be printing and that's what -M/--max-columns should be applied to. Fixes #2458
Diffstat (limited to 'tests')
-rw-r--r--tests/feature.rs104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/feature.rs b/tests/feature.rs
index 5321d110..ce5459c2 100644
--- a/tests/feature.rs
+++ b/tests/feature.rs
@@ -657,6 +657,110 @@ but Doctor Watson has to have it taken out for him and dusted,
eqnice!(expected, cmd.stdout());
});
+rgtest!(f917_trim_multi_standard, |dir: Dir, mut cmd: TestCommand| {
+ const HAYSTACK: &str = " 0123456789abcdefghijklmnopqrstuvwxyz";
+ dir.create("haystack", HAYSTACK);
+ cmd.args(&["--multiline", "--trim", "-r$0", "--no-filename", r"a\n?bc"]);
+
+ let expected = "0123456789abcdefghijklmnopqrstuvwxyz\n";
+ eqnice!(expected, cmd.stdout());
+});
+
+rgtest!(f917_trim_max_columns_normal, |dir: Dir, mut cmd: TestCommand| {
+ const HAYSTACK: &str = " 0123456789abcdefghijklmnopqrstuvwxyz";
+ dir.create("haystack", HAYSTACK);
+ cmd.args(&[
+ "--trim",
+ "--max-columns-preview",
+ "-M8",
+ "--no-filename",
+ "abc",
+ ]);
+
+ let expected = "01234567 [... omitted end of long line]\n";
+ eqnice!(expected, cmd.stdout());
+});
+
+rgtest!(f917_trim_max_columns_matches, |dir: Dir, mut cmd: TestCommand| {
+ const HAYSTACK: &str = " 0123456789abcdefghijklmnopqrstuvwxyz";
+ dir.create("haystack", HAYSTACK);
+ cmd.args(&[
+ "--trim",
+ "--max-columns-preview",
+ "-M8",
+ "--color=always",
+ "--colors=path:none",
+ "--no-filename",
+ "abc",
+ ]);
+
+ let expected = "01234567 [... 1 more match]\n";
+ eqnice!(expected, cmd.stdout());
+});
+
+rgtest!(
+ f917_trim_max_columns_multi_standard,
+ |dir: Dir, mut cmd: TestCommand| {
+ const HAYSTACK: &str = " 0123456789abcdefghijklmnopqrstuvwxyz";
+ dir.create("haystack", HAYSTACK);
+ cmd.args(&[
+ "--multiline",
+ "--trim",
+ "--max-columns-preview",
+ "-M8",
+ // Force the "slow" printing path without actually
+ // putting colors in the output.
+ "--color=always",
+ "--colors=path:none",
+ "--no-filename",
+ r"a\n?bc",
+ ]);
+
+ let expected = "01234567 [... 1 more match]\n";
+ eqnice!(expected, cmd.stdout());
+ }
+);
+
+rgtest!(
+ f917_trim_max_columns_multi_only_matching,
+ |dir: Dir, mut cmd: TestCommand| {
+ const HAYSTACK: &str = " 0123456789abcdefghijklmnopqrstuvwxyz";
+ dir.create("haystack", HAYSTACK);
+ cmd.args(&[
+ "--multiline",
+ "--trim",
+ "--max-columns-preview",
+ "-M8",
+ "--only-matching",
+ "--no-filename",
+ r".*a\n?bc.*",
+ ]);
+
+ let expected = "01234567 [... 0 more matches]\n";
+ eqnice!(expected, cmd.stdout());
+ }
+);
+
+rgtest!(
+ f917_trim_max_columns_multi_per_match,
+ |dir: Dir, mut cmd: TestCommand| {
+ const HAYSTACK: &str = " 0123456789abcdefghijklmnopqrstuvwxyz";
+ dir.create("haystack", HAYSTACK);
+ cmd.args(&[
+ "--multiline",
+ "--trim",
+ "--max-columns-preview",
+ "-M8",
+ "--vimgrep",
+ "--no-filename",
+ r".*a\n?bc.*",
+ ]);
+
+ let expected = "1:1:01234567 [... 0 more matches]\n";
+ eqnice!(expected, cmd.stdout());
+ }
+);
+
// See: https://github.com/BurntSushi/ripgrep/issues/993
rgtest!(f993_null_data, |dir: Dir, mut cmd: TestCommand| {
dir.create("test", "foo\x00bar\x00\x00\x00baz\x00");