Skip to content

Commit f43c673

Browse files
Handle expect![[]] (no literal) in locate_end
1 parent 0174343 commit f43c673

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ impl Expect {
288288
fn locate_end(expect_invocation_to_eof: &str) -> Option<usize> {
289289
static TRAILER: Lazy<Regex> = Lazy::new(|| Regex::new(r##""#*(\s*]])"##).unwrap());
290290

291+
// First, check for `expect![[]]` (no literal).
292+
let mut chars = expect_invocation_to_eof.chars().skip_while(|c| c.is_whitespace());
293+
if (']', ']') == (chars.next()?, chars.next()?) {
294+
return Some(0);
295+
}
296+
291297
let trailer = TRAILER.captures(expect_invocation_to_eof)?;
292298
let literal_end = trailer.get(0).unwrap().end() - trailer[1].len();
293299
Some(literal_end)
@@ -693,5 +699,8 @@ line1
693699
// [["\"]]"]],
694700
// [[r#""]]"#]],
695701
);
702+
703+
// Check `expect![[ ]]` as well.
704+
assert_eq!(locate_end(" ]]"), Some(0));
696705
}
697706
}

0 commit comments

Comments
 (0)