From 6578ddc10096d987d05d158a7e687dbc7b902883 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 10 Apr 2023 11:54:05 -0400 Subject: [PATCH] Add a test for footnote definition. --- src/parser/footnote_definition.rs | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 4e3403b0..661b5d20 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -84,3 +84,43 @@ fn footnote_definition_end<'r, 's>( ))), ))(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 = "[fn:1] A footnote. + +[fn:2] A multi- + +line footnote."; + let initial_context: ContextTree<'_, '_> = ContextTree::new(); + let document_context = + initial_context.with_additional_node(ContextElement::DocumentRoot(input)); + let footnote_definition_matcher = + parser_with_context!(footnote_definition)(&document_context); + let (remaining, first_footnote_definition) = + footnote_definition_matcher(input).expect("Parse first footnote_definition"); + let (remaining, second_footnote_definition) = + footnote_definition_matcher(remaining).expect("Parse second footnote_definition."); + assert_eq!(remaining, ""); + assert_eq!( + first_footnote_definition.source, + "[fn:1] A footnote. + +" + ); + assert_eq!( + second_footnote_definition.source, + "[fn:2] A multi- + +line footnote." + ); + } +}