Merge branch 'radio_link_properties'
All checks were successful
rustfmt Build rustfmt has succeeded
rust-build Build rust-build has succeeded
rust-test Build rust-test has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded

This commit is contained in:
Tom Alexander 2023-10-07 01:14:12 -04:00
commit 8d9ff77799
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 68 additions and 8 deletions

View File

@ -2758,11 +2758,13 @@ fn compare_strike_through<'b, 's>(
}
fn compare_regular_link<'b, 's>(
_source: &'s str,
source: &'s str,
emacs: &'b Token<'s>,
rust: &'b RegularLink<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut this_status = DiffStatus::Good;
let mut child_status = Vec::new();
let mut message = None;
if let Some((new_status, new_message)) = compare_properties!(
@ -2812,6 +2814,10 @@ fn compare_regular_link<'b, 's>(
message = new_message;
}
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?);
}
Ok(DiffResult {
status: this_status,
name: rust.get_elisp_name(),
@ -2824,14 +2830,56 @@ fn compare_regular_link<'b, 's>(
}
fn compare_radio_link<'b, 's>(
_source: &'s str,
source: &'s str,
emacs: &'b Token<'s>,
rust: &'b RadioLink<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let this_status = DiffStatus::Good;
let message = None;
let children = emacs.as_list()?;
let mut this_status = DiffStatus::Good;
let mut child_status = Vec::new();
let mut message = None;
// TODO: Compare :type :path :format :raw-link :application :search-option
if let Some((new_status, new_message)) = compare_properties!(
emacs,
rust,
(
EmacsField::Required(":type"),
|_| { Some("radio") },
compare_property_quoted_string
),
(
EmacsField::Required(":path"),
|r| Some(&r.path),
compare_property_quoted_string
),
(
EmacsField::Required(":format"),
|_| Some("plain"),
compare_property_unquoted_atom
),
(
EmacsField::Required(":raw-link"),
|r| Some(&r.raw_link),
compare_property_quoted_string
),
(
EmacsField::Required(":application"),
compare_identity,
compare_property_always_nil
),
(
EmacsField::Required(":search-option"),
compare_identity,
compare_property_always_nil
)
)? {
this_status = new_status;
message = new_message;
}
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?);
}
Ok(DiffResult {
status: this_status,

View File

@ -30,6 +30,7 @@ pub(crate) fn radio_link<'b, 'g, 'r, 's>(
for radio_target in &context.get_global_settings().radio_targets {
let rematched_target = rematch_target(context, radio_target, input);
if let Ok((remaining, rematched_target)) = rematched_target {
let path = get_consumed(input, remaining);
let (remaining, _) = space0(remaining)?;
let source = get_consumed(input, remaining);
return Ok((
@ -37,6 +38,8 @@ pub(crate) fn radio_link<'b, 'g, 'r, 's>(
RadioLink {
source: source.into(),
children: rematched_target,
path: path.into(),
raw_link: path.into(),
},
));
}
@ -184,7 +187,9 @@ mod tests {
.expect("Len already asserted to be 3"),
&Object::RadioLink(RadioLink {
source: "bar ",
children: vec![Object::PlainText(PlainText { source: "bar" })]
children: vec![Object::PlainText(PlainText { source: "bar" })],
path: "bar".into(),
raw_link: "bar".into()
})
);
}
@ -226,7 +231,9 @@ mod tests {
children: vec![Object::Bold(Bold {
source: "*bar* ",
children: vec![Object::PlainText(PlainText { source: "bar" })]
})]
})],
path: "*bar* ".into(),
raw_link: "*bar* ".into()
})
);
}

View File

@ -68,6 +68,7 @@ fn regular_link_without_description<'b, 'g, 'r, 's>(
path: path.path,
raw_link: path.raw_link,
search_option: path.search_option,
children: Vec::new(),
},
))
}
@ -80,7 +81,7 @@ fn regular_link_with_description<'b, 'g, 'r, 's>(
let (remaining, _opening_bracket) = tag("[[")(input)?;
let (remaining, path) = pathreg(context, remaining)?;
let (remaining, _closing_bracket) = tag("][")(remaining)?;
let (remaining, _description) = description(context, remaining)?;
let (remaining, description) = description(context, remaining)?;
let (remaining, _closing_bracket) = tag("]]")(remaining)?;
let (remaining, _trailing_whitespace) =
maybe_consume_object_trailing_whitespace_if_not_exiting(context, remaining)?;
@ -93,6 +94,7 @@ fn regular_link_with_description<'b, 'g, 'r, 's>(
path: path.path,
raw_link: path.raw_link,
search_option: path.search_option,
children: description,
},
))
}

View File

@ -84,6 +84,7 @@ pub struct RegularLink<'s> {
pub path: Cow<'s, str>,
pub raw_link: Cow<'s, str>,
pub search_option: Option<Cow<'s, str>>,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
@ -95,6 +96,8 @@ pub struct RadioTarget<'s> {
#[derive(Debug, PartialEq)]
pub struct RadioLink<'s> {
pub source: &'s str,
pub path: Cow<'s, str>,
pub raw_link: Cow<'s, str>,
pub children: Vec<Object<'s>>,
}