Skip to content

Commit

Permalink
Support single delimiters in expect!
Browse files Browse the repository at this point in the history
Now that we parse string literals, multiple delimiters aren't necessary.
  • Loading branch information
ecstatic-morse committed Dec 26, 2021
1 parent c3db211 commit e7567f1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ fn update_expect() -> bool {
/// Leading indentation is stripped.
#[macro_export]
macro_rules! expect {
[$data:literal] => { $crate::expect![[$data]] };
[[$data:literal]] => {$crate::Expect {
position: $crate::Position {
file: file!(),
Expand All @@ -187,6 +188,7 @@ macro_rules! expect {
data: $data,
indent: true,
}};
[] => { $crate::expect![[""]] };
[[]] => { $crate::expect![[""]] };
}

Expand Down Expand Up @@ -305,7 +307,7 @@ impl Expect {
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![[`.");
locate_end(lit_to_eof_trimmed).expect("Couldn't find closing delimiter for `expect!`.");
let literal_range = literal_start..literal_start + literal_len;
Location { line_indent, literal_range }
}
Expand All @@ -314,7 +316,8 @@ impl Expect {
fn locate_end(lit_to_eof: &str) -> Option<usize> {
assert!(lit_to_eof.chars().next().map_or(true, |c| !c.is_whitespace()));

if lit_to_eof.starts_with("]]") {
let first = lit_to_eof.chars().next()?;
if matches!(first, ']' | '}' | ')') {
// expect![[ ]]
Some(0)
} else {
Expand Down

0 comments on commit e7567f1

Please sign in to comment.