Compare commits

..

4 Commits

Author SHA1 Message Date
Tom Alexander
ef2c351696
Expect fail the last radio link test.
All checks were successful
rust-test Build rust-test has succeeded
2023-07-14 18:36:25 -04:00
Tom Alexander
cdd3517655
Include the trailing space for the bolds. 2023-07-14 18:32:16 -04:00
Tom Alexander
7ca8beac5a
Allow matching bolds in radio link targets. 2023-07-14 18:27:09 -04:00
Tom Alexander
4ba1e63dde
Add a test for bold inside a radio target. 2023-07-14 18:12:04 -04:00
3 changed files with 44 additions and 1 deletions

View File

@ -81,6 +81,7 @@ fn is_expect_fail(name: &str) -> Option<&str> {
"paragraphs_paragraph_with_backslash_line_breaks" => Some("The text we're getting out of the parse tree is already processed to remove line breaks, so our comparison needs to take that into account."),
"radio_link_before_and_after" => Some("Matching the contents of radio targets not yet implemented."),
"radio_link_simple" => Some("Matching the contents of radio targets not yet implemented."),
"radio_link_identical_or_semantically_identical" => Some("Would require having the 2-pass parsing implemented."),
_ => None,
}
}

View File

@ -58,6 +58,11 @@ pub fn rematch_target<'x, 'r, 's>(
for original_object in target {
match original_object {
// TODO: The rest of the minimal set of objects.
Object::Bold(bold) => {
let (new_remaining, new_match) = bold.rematch_object(context, remaining)?;
remaining = new_remaining;
new_matches.push(new_match);
}
Object::PlainText(plaintext) => {
let (new_remaining, new_match) = plaintext.rematch_object(context, remaining)?;
remaining = new_remaining;
@ -120,6 +125,7 @@ mod tests {
use crate::parser::parser_context::ContextTree;
use crate::parser::parser_with_context::parser_with_context;
use crate::parser::source::Source;
use crate::parser::Bold;
use crate::parser::PlainText;
#[test]
@ -151,4 +157,40 @@ mod tests {
})
);
}
#[test]
fn bold_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::Bold(
Bold {
source: "*bar*",
children: 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::Bold(Bold {
source: "*bar* ",
children: vec![Object::PlainText(PlainText { source: "bar" })]
})]
})
);
}
}

View File

@ -291,5 +291,5 @@ fn _rematch_text_markup_object<'r, 's, 'x>(
let (remaining, _close) = text_markup_end_specialized(context, remaining)?;
let (remaining, _trailing_whitespace) = space0(remaining)?;
Ok((remaining, Vec::new()))
Ok((remaining, children))
}