Skip to content

Commit

Permalink
Report the text line where pattern failed to match from.
Browse files Browse the repository at this point in the history
Previously when `...` failed, it told you how-far-it-got before
realising it had failed, rather than the more useful where-it-started.
This commit fixes that.
  • Loading branch information
ltratt committed Jun 3, 2024
1 parent 9794e4e commit 6542ea4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,29 @@ impl<'a> FMatcher<'a> {
match (ptnl, textl) {
(Some(x), Some(y)) => {
if x.trim() == LINE_ANCHOR_WILDCARD {
let text_lines_off_orig = text_lines_off;
ptnl = ptn_lines.next();
ptn_lines_off += 1;
match ptnl {
Some(x) => {
let mut succ = false;
while let Some(y) = textl {
text_lines_off += 1;
if self.match_line(&mut names, x, y) {
succ = true;
break;
}
text_lines_off += 1;
textl = text_lines.next();
}
text_lines_off -= 1;
if !succ {
return Err(FMatchError {
output_formatter: self.options.output_formatter,
ptn: self.ptn.to_owned(),
text: text.to_owned(),
ptn_line_off: ptn_lines_off,
text_line_off: text_lines_off_orig,
});
}
}
None => return Ok(()),
}
Expand Down Expand Up @@ -1011,7 +1022,7 @@ mod tests {

assert_eq!(helper("...\nb\nc\nd\n", "a\nb\nc\n0\ne"), (4, 4));
assert_eq!(helper("...\nc\nd\n", "a\nb\nc\n0\ne"), (3, 4));
assert_eq!(helper("...\nd\n", "a\nb\nc\n0\ne"), (2, 5));
assert_eq!(helper("...\nd\n", "a\nb\nc\n0\ne"), (2, 1));

assert_eq!(helper("a\n..~\nc\nd\ne", "a\nb\nc\nd"), (3, 2));
assert_eq!(helper("a\n..~\nc\nd", "a\nb\nc\ne"), (3, 2));
Expand Down

0 comments on commit 6542ea4

Please sign in to comment.