Compare commits
4 Commits
e4c6ca2880
...
ef2c351696
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ef2c351696 | ||
![]() |
cdd3517655 | ||
![]() |
7ca8beac5a | ||
![]() |
4ba1e63dde |
1
build.rs
1
build.rs
@ -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."),
|
"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_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_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,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,11 @@ pub fn rematch_target<'x, 'r, 's>(
|
|||||||
for original_object in target {
|
for original_object in target {
|
||||||
match original_object {
|
match original_object {
|
||||||
// TODO: The rest of the minimal set of objects.
|
// 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) => {
|
Object::PlainText(plaintext) => {
|
||||||
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;
|
||||||
@ -120,6 +125,7 @@ mod tests {
|
|||||||
use crate::parser::parser_context::ContextTree;
|
use crate::parser::parser_context::ContextTree;
|
||||||
use crate::parser::parser_with_context::parser_with_context;
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
use crate::parser::source::Source;
|
use crate::parser::source::Source;
|
||||||
|
use crate::parser::Bold;
|
||||||
use crate::parser::PlainText;
|
use crate::parser::PlainText;
|
||||||
|
|
||||||
#[test]
|
#[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" })]
|
||||||
|
})]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,5 +291,5 @@ fn _rematch_text_markup_object<'r, 's, 'x>(
|
|||||||
|
|
||||||
let (remaining, _close) = text_markup_end_specialized(context, remaining)?;
|
let (remaining, _close) = text_markup_end_specialized(context, remaining)?;
|
||||||
let (remaining, _trailing_whitespace) = space0(remaining)?;
|
let (remaining, _trailing_whitespace) = space0(remaining)?;
|
||||||
Ok((remaining, Vec::new()))
|
Ok((remaining, children))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user