From e7567f1991950461a11a6386129fa3ef0a070e31 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sun, 26 Dec 2021 13:35:51 -0800 Subject: [PATCH] Support single delimiters in `expect!` Now that we parse string literals, multiple delimiters aren't necessary. --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4f77ae0..ae43b3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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!(), @@ -187,6 +188,7 @@ macro_rules! expect { data: $data, indent: true, }}; + [] => { $crate::expect![[""]] }; [[]] => { $crate::expect![[""]] }; } @@ -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 } } @@ -314,7 +316,8 @@ impl Expect { fn locate_end(lit_to_eof: &str) -> Option { 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 {