Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reiteration of the first found match with --only-mathing flag #454

Merged
merged 1 commit into from
Apr 21, 2017

Conversation

kpp
Copy link
Contributor

@kpp kpp commented Apr 20, 2017

Fixes #451

~/ripgrep$ cat tests/digits.txt 
1 2 3
123
~/ripgrep$ cargo run -- "\d" tests/digits.txt -o --column
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/rg '\d' tests/digits.txt -o --column`
1:1:1
1:3:2
1:5:3
2:1:1
2:2:2
2:3:3
~/ripgrep$ cargo run -- "\d+" tests/digits.txt -o --column
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/rg '\d+' tests/digits.txt -o --column`
1:1:1
1:3:2
1:5:3
2:1:123

Copy link
Owner

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix! I think this mostly looks good, but I left some nits on the test. I also think we should include a regression test that roughly matches what the reporter initially presented.

tests/tests.rs Outdated
wd.create(path, "1 2 3\n123\n");

let mut cmd = wd.command();
cmd.arg("\\d").arg(path)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a raw string literal for this? e.g., r"\d".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

tests/tests.rs Outdated
let mut cmd = wd.command();
cmd.arg("\\d").arg(path)
.arg("--only-matching")
.arg("--color=never")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right

tests/tests.rs Outdated
@@ -1607,6 +1607,32 @@ fn regression_391() {
assert_eq!(lines, "bar.py\n");
}

// See: https://github.com/BurntSushi/ripgrep/issues/451
#[test]
fn regression_451_only_matching() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks good. Could you add another test that approximately mimics the bug report in #451? e.g., Test that the actual results printed are correct instead of just column numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I see. Yep

@kpp kpp force-pushed the bug_451_only_mathing_digits branch 2 times, most recently from 8e83224 to 8539784 Compare April 20, 2017 15:32
@kpp kpp force-pushed the bug_451_only_mathing_digits branch from 8539784 to 5854b69 Compare April 20, 2017 15:34
@kpp
Copy link
Contributor Author

kpp commented Apr 21, 2017

@BurntSushi ?

@BurntSushi BurntSushi merged commit 362abed into BurntSushi:master Apr 21, 2017
@BurntSushi
Copy link
Owner

Looks good, thank you!

@kpp kpp deleted the bug_451_only_mathing_digits branch April 23, 2017 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants