Add test demonstrating problem.

This commit is contained in:
Tom Alexander 2023-04-15 17:04:47 -04:00
parent 4e460e4a8c
commit 6e4aa38fce
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# Comment line
#not a comment
# Comment again

View File

@ -43,3 +43,33 @@ fn comment_line<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str
let source = get_consumed(input, remaining);
Ok((remaining, source))
}
#[cfg(test)]
mod tests {
use crate::parser::parser_context::ContextElement;
use crate::parser::parser_context::ContextTree;
use crate::parser::parser_with_context::parser_with_context;
use super::*;
#[test]
fn require_space_after_hash() {
let input = "# Comment line
#not a comment
# Comment again";
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let comment_matcher =
parser_with_context!(comment)(&document_context);
let (remaining, first_comment) =
comment_matcher(input).expect("Parse first comment");
assert_eq!(remaining, r#"#not a comment
# Comment again"#);
assert_eq!(
first_comment.source,
"# Comment line
"
);
}
}