Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xxchan committed May 18, 2023
1 parent 3e499f0 commit 207bbe3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ impl Expect {
}
line_start += line.len();
}
// `literal_start` points to the first character after `expect![`
let (literal_start, line_indent) = target_line.unwrap();

let lit_to_eof = &file[literal_start..];
Expand All @@ -352,6 +353,9 @@ impl Expect {
}
}

/// Returns the byte index of the closing delimiter.
///
/// `arg_start_to_eof` is the part after `expect![`, with leading whitespaces trimmed.
fn locate_end(arg_start_to_eof: &str) -> Option<usize> {
match arg_start_to_eof.chars().next()? {
c if c.is_whitespace() => panic!("skip whitespace before calling `locate_end`"),
Expand Down Expand Up @@ -836,8 +840,9 @@ line1
macro_rules! check_locate {
($( [[$s:literal]] ),* $(,)?) => {$({
let lit = stringify!($s);
let with_trailer = format!("{} \t]]\n", lit);
assert_eq!(locate_end(&with_trailer), Some(lit.len()));
let with_trailer = format!("[{} \t]]\n", lit);
// ^ ^^ ^^ 5 additional chars
assert_eq!(locate_end(&with_trailer), Some(4+lit.len()));
})*};
}

Expand All @@ -850,7 +855,7 @@ line1
);

// Check `expect![[ ]]` as well.
assert_eq!(locate_end("]]"), Some(0));
assert_eq!(locate_end("[]]"), Some(2));
}

#[test]
Expand Down

0 comments on commit 207bbe3

Please sign in to comment.