mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-31 20:21:59 -07:00
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
This commit is contained in:
104
tests/feature.rs
104
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");
|
||||
|
Reference in New Issue
Block a user