diff --git a/org_mode_samples/comment/require_whitespace_after_hash.org b/org_mode_samples/comment/require_whitespace_after_hash.org new file mode 100644 index 0000000..d06c06e --- /dev/null +++ b/org_mode_samples/comment/require_whitespace_after_hash.org @@ -0,0 +1,3 @@ +# Comment line +#not a comment +# Comment again diff --git a/src/parser/comment.rs b/src/parser/comment.rs index cb7d093..f304ac8 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -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 +" + ); + } +}