Add a test for a simple citation.
This commit is contained in:
parent
6b47a6c6c3
commit
4ad297f58a
@ -176,3 +176,39 @@ fn global_suffix_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'
|
|||||||
recognize(parser_with_context!(citation_reference_key)(context)),
|
recognize(parser_with_context!(citation_reference_key)(context)),
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::parser::element_parser::element;
|
||||||
|
use crate::parser::parser_context::ContextElement;
|
||||||
|
use crate::parser::parser_context::ContextTree;
|
||||||
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
|
use crate::parser::source::Source;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn citation_simple() {
|
||||||
|
let input = "[cite:@foo]";
|
||||||
|
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||||
|
let document_context =
|
||||||
|
initial_context.with_additional_node(ContextElement::DocumentRoot(input));
|
||||||
|
let paragraph_matcher = parser_with_context!(element(true))(&document_context);
|
||||||
|
let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph");
|
||||||
|
let first_paragraph = match first_paragraph {
|
||||||
|
crate::parser::Element::Paragraph(paragraph) => paragraph,
|
||||||
|
_ => panic!("Should be a paragraph!"),
|
||||||
|
};
|
||||||
|
assert_eq!(remaining, "");
|
||||||
|
assert_eq!(first_paragraph.get_source(), "[cite:@foo]");
|
||||||
|
assert_eq!(first_paragraph.children.len(), 1);
|
||||||
|
assert_eq!(
|
||||||
|
first_paragraph
|
||||||
|
.children
|
||||||
|
.get(0)
|
||||||
|
.expect("Len already asserted to be 1"),
|
||||||
|
&Object::Citation(Citation {
|
||||||
|
source: "[cite:@foo]"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
[fn:2:This is a footnote reference since it has the definition inside the brackets. This style is referred to as an "inline footnote".]
|
[cite:@foo]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user