Compare commits

..

4 Commits

Author SHA1 Message Date
Tom Alexander
d4a2ad4a7f
Merge branch 'node_property_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
2023-10-02 23:47:11 -04:00
Tom Alexander
3d1b2713ed
Compare key and value. 2023-10-02 23:45:31 -04:00
Tom Alexander
60bec4695b
Merge branch 'drawer_properties' 2023-10-02 23:38:34 -04:00
Tom Alexander
d992947ff1
Compare name. 2023-10-02 23:34:06 -04:00
3 changed files with 43 additions and 7 deletions

View File

@ -1241,9 +1241,19 @@ fn compare_drawer<'b, 's>(
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
// TODO: Compare :drawer-name
let mut this_status = DiffStatus::Good;
let mut message = None;
// Compare drawer-name
let name =
get_property_quoted_string(emacs, ":drawer-name")?.ok_or("Drawers should have a name.")?;
if name != rust.name {
this_status = DiffStatus::Bad;
message = Some(format!(
"Name mismatch (emacs != rust) {:?} != {:?}",
name, rust.name
));
}
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())?);
@ -1291,10 +1301,33 @@ fn compare_node_property<'b, 's>(
rust: &'b NodeProperty<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let child_status = Vec::new();
let this_status = DiffStatus::Good;
let message = None;
let mut this_status = DiffStatus::Good;
let mut message = None;
// TODO: Compare :key :value
// Compare key
let key =
get_property_quoted_string(emacs, ":key")?.ok_or("Node properties should have a key.")?;
if key != rust.name {
this_status = DiffStatus::Bad;
message = Some(format!(
"Key mismatch (emacs != rust) {:?} != {:?}",
key, rust.name
));
}
// Compare value
let value = get_property_quoted_string(emacs, ":value")?;
match (value.as_ref(), rust.value) {
(None, None) => {}
(Some(emacs_value), Some(rust_value)) if emacs_value == rust_value => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Value mismatch (emacs != rust) {:?} != {:?}",
value, rust.value
));
}
}
Ok(DiffResult {
status: this_status,

View File

@ -101,7 +101,7 @@ fn node_property<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, NodeProperty<'s>> {
let (remaining, (_start_of_line, _leading_whitespace, _open_colon, _name, _close_colon)) =
let (remaining, (_start_of_line, _leading_whitespace, _open_colon, name, _close_colon)) =
tuple((
start_of_line,
space0,
@ -120,6 +120,7 @@ fn node_property<'b, 'g, 'r, 's>(
remaining,
NodeProperty {
source: source.into(),
name: Into::<&str>::into(name),
value: None,
},
))
@ -132,6 +133,7 @@ fn node_property<'b, 'g, 'r, 's>(
remaining,
NodeProperty {
source: source.into(),
name: Into::<&str>::into(name),
value: Some(value.into()),
},
))

View File

@ -94,6 +94,7 @@ pub struct PropertyDrawer<'s> {
#[derive(Debug)]
pub struct NodeProperty<'s> {
pub source: &'s str,
pub name: &'s str,
pub value: Option<&'s str>,
}