Add a simple test for paragraphs.

This commit is contained in:
Tom Alexander 2023-04-10 11:24:04 -04:00
parent 204f319a92
commit e417e86bd4
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -50,3 +50,26 @@ fn paragraph_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s st
eof,
))(input)
}
#[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 two_paragraphs() {
let input = "foo bar baz\n\nlorem ipsum";
let initial_context: ContextTree<'_, '_> = ContextTree::new();
let document_context =
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
let paragraph_matcher = parser_with_context!(paragraph)(&document_context);
let (remaining, first_paragraph) = paragraph_matcher(input).unwrap();
let (remaining, second_paragraph) = paragraph_matcher(remaining).unwrap();
assert_eq!(remaining, "");
assert_eq!(first_paragraph.source, "foo bar baz\n\n");
assert_eq!(second_paragraph.source, "lorem ipsum");
}
}