Add a basic test showing the radio link rematching working on plain text.
Some checks failed
rust-test Build rust-test has failed
Some checks failed
rust-test Build rust-test has failed
This commit is contained in:
parent
66ae70e790
commit
e5c1b68b0e
@ -62,7 +62,6 @@ pub fn rematch_target<'r, 's>(
|
|||||||
let (new_remaining, new_match) = plaintext.rematch_object(context, remaining)?;
|
let (new_remaining, new_match) = plaintext.rematch_object(context, remaining)?;
|
||||||
remaining = new_remaining;
|
remaining = new_remaining;
|
||||||
new_matches.push(new_match);
|
new_matches.push(new_match);
|
||||||
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||||
@ -112,3 +111,44 @@ pub trait RematchObject {
|
|||||||
input: &'s str,
|
input: &'s str,
|
||||||
) -> Res<&'s str, Object<'s>>;
|
) -> Res<&'s str, Object<'s>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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;
|
||||||
|
use crate::parser::PlainText;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn plain_text_radio_target() {
|
||||||
|
let input = "foo bar baz";
|
||||||
|
let initial_context: ContextTree<'_, '_> = ContextTree::new();
|
||||||
|
let document_context = initial_context
|
||||||
|
.with_additional_node(ContextElement::DocumentRoot(input))
|
||||||
|
.with_additional_node(ContextElement::RadioTarget(vec![vec![Object::PlainText(
|
||||||
|
PlainText { source: "bar" },
|
||||||
|
)]]));
|
||||||
|
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(), "foo bar baz");
|
||||||
|
assert_eq!(first_paragraph.children.len(), 3);
|
||||||
|
assert_eq!(
|
||||||
|
first_paragraph
|
||||||
|
.children
|
||||||
|
.get(1)
|
||||||
|
.expect("Len already asserted to be 3"),
|
||||||
|
&Object::RadioLink(RadioLink {
|
||||||
|
source: "bar",
|
||||||
|
children: vec![Object::PlainText(PlainText { source: "bar" })]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user