Add SourceInfo to Comment

This commit is contained in:
robozati 2023-10-23 11:04:09 -03:00 committed by hurl-bot
parent 717857950d
commit 21235c655e
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
5 changed files with 21 additions and 6 deletions

View File

@ -359,7 +359,8 @@ mod tests {
line_terminators: vec![LineTerminator {
space0: whitespace(),
comment: Some(Comment {
value: "@cookie_storage_clear".to_string()
value: "@cookie_storage_clear".to_string(),
source_info: SourceInfo::new(0, 0, 0, 0),
}),
newline: whitespace(),
}],
@ -399,7 +400,8 @@ mod tests {
comment: Some(Comment {
value:
"@cookie_storage_set: localhost\tFALSE\t/\tFALSE\t0\tcookie1\tvalueA"
.to_string()
.to_string(),
source_info: SourceInfo::new(0, 0, 0, 0),
}),
newline: whitespace(),
}],

View File

@ -575,6 +575,7 @@ pub enum TemplateElement {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Comment {
pub value: String,
pub source_info: SourceInfo,
}
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -354,6 +354,7 @@ mod tests {
},
comment: Some(Comment {
value: " comment".to_string(),
source_info: SourceInfo::new(1, 24, 1, 32),
}),
newline: Whitespace {
value: String::new(),

View File

@ -133,6 +133,7 @@ pub fn optional_line_terminators(reader: &mut Reader) -> ParseResult<Vec<LineTer
pub fn comment(reader: &mut Reader) -> ParseResult<Comment> {
try_literal("#", reader)?;
let start = reader.state.clone();
let mut value = String::new();
loop {
if reader.is_eof() {
@ -152,7 +153,13 @@ pub fn comment(reader: &mut Reader) -> ParseResult<Comment> {
}
}
}
Ok(Comment { value })
Ok(Comment {
value,
source_info: SourceInfo {
start: start.pos,
end: reader.state.clone().pos,
},
})
}
pub fn literal(s: &str, reader: &mut Reader) -> ParseResult<()> {
@ -677,7 +684,8 @@ mod tests {
assert_eq!(
comment(&mut reader),
Ok(Comment {
value: String::new()
value: String::new(),
source_info: SourceInfo::new(1, 2, 1, 2),
})
);
@ -685,7 +693,8 @@ mod tests {
assert_eq!(
comment(&mut reader),
Ok(Comment {
value: " comment".to_string()
value: " comment".to_string(),
source_info: SourceInfo::new(1, 2, 1, 10),
})
);
assert_eq!(reader.state.cursor, 9);
@ -809,7 +818,8 @@ mod tests {
source_info: SourceInfo::new(1, 25, 1, 26),
},
comment: Some(Comment {
value: " comment".to_string()
value: " comment".to_string(),
source_info: SourceInfo::new(1, 27, 1, 35),
}),
newline: Whitespace {
value: String::new(),

View File

@ -615,6 +615,7 @@ fn lint_comment(comment: &Comment) -> Comment {
} else {
format!(" {}", comment.value)
},
source_info: SourceInfo::new(0, 0, 0, 0),
}
}