Add test demonstrating problem.
This commit is contained in:
parent
4e460e4a8c
commit
6e4aa38fce
@ -0,0 +1,3 @@
|
|||||||
|
# Comment line
|
||||||
|
#not a comment
|
||||||
|
# Comment again
|
@ -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);
|
let source = get_consumed(input, remaining);
|
||||||
Ok((remaining, source))
|
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
|
||||||
|
"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user