Add some comments for magic numbers + Add tests

This commit is contained in:
Vadim Petrochenkov 2020-08-05 00:26:23 +03:00
parent d642c3b6f8
commit a285b58368
2 changed files with 3 additions and 1 deletions

View file

@ -264,6 +264,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span:
let mut doc = doc.to_owned();
doc.push('\n');
let len = doc.len();
// +3 skips the opening delimiter
return (doc, vec![(len, span.with_lo(span.lo() + BytePos(3)))]);
}
@ -273,7 +274,7 @@ pub fn strip_doc_comment_decoration(doc: &str, comment_kind: CommentKind, span:
let offset = line.as_ptr() as usize - doc.as_ptr() as usize;
debug_assert_eq!(offset as u32 as usize, offset);
contains_initial_stars |= line.trim_start().starts_with('*');
// +1 for the newline
// +1 adds the newline, +3 skips the opening delimiter
sizes.push((line.len() + 1, span.with_lo(span.lo() + BytePos(3 + offset as u32))));
}
if !contains_initial_stars {

View file

@ -64,6 +64,7 @@ impl TabsInDocComments {
let comment = comment.as_str();
for (lo, hi) in get_chunks_of_tabs(&comment) {
// +3 skips the opening delimiter
let new_span = Span::new(
attr.span.lo() + BytePos(3 + lo),
attr.span.lo() + BytePos(3 + hi),