Skip to content

Commit

Permalink
Account for whitespace between expect![[ and the literal
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Dec 24, 2021
1 parent a13fe99 commit 9d4ab00
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,22 @@ impl Expect {
}
let (literal_start, line_indent) = target_line.unwrap();

let literal_len = locate_end(&file[literal_start..])
let lit_to_eof = &file[literal_start..];
let lit_to_eof_trimmed = lit_to_eof.trim_start();

let literal_start = literal_start + (lit_to_eof.len() - lit_to_eof_trimmed.len());

let literal_len = locate_end(lit_to_eof_trimmed)
.expect("Couldn't find matching `]]` for `expect![[`.");
let literal_range = literal_start..literal_start + literal_len;
Location { line_indent, literal_range }
}
}

fn locate_end(lit_to_eof: &str) -> Option<usize> {
if lit_to_eof.chars().skip_while(|c| c.is_whitespace()).take(2).eq([']', ']'].iter().cloned()) {
assert!(lit_to_eof.chars().next().map_or(true, |c| !c.is_whitespace()));

if lit_to_eof.starts_with("]]") {
// expect![[ ]]
Some(0)
} else {
Expand Down

0 comments on commit 9d4ab00

Please sign in to comment.