Compare node properties.
This commit is contained in:
parent
49afcf0db6
commit
6fc607cfe0
@ -36,6 +36,7 @@ use crate::types::Keyword;
|
||||
use crate::types::LatexEnvironment;
|
||||
use crate::types::LatexFragment;
|
||||
use crate::types::LineBreak;
|
||||
use crate::types::NodeProperty;
|
||||
use crate::types::Object;
|
||||
use crate::types::OrgMacro;
|
||||
use crate::types::Paragraph;
|
||||
@ -934,7 +935,7 @@ fn compare_property_drawer<'s>(
|
||||
rust: &'s PropertyDrawer<'s>,
|
||||
) -> Result<DiffEntry<'s>, Box<dyn std::error::Error>> {
|
||||
let children = emacs.as_list()?;
|
||||
let child_status = Vec::new();
|
||||
let mut child_status = Vec::new();
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let mut message = None;
|
||||
let emacs_name = "property-drawer";
|
||||
@ -950,9 +951,8 @@ fn compare_property_drawer<'s>(
|
||||
Ok(_) => {}
|
||||
};
|
||||
|
||||
for (_emacs_child, _rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
||||
// TODO: What are node properties and are they the only legal child of property drawers?
|
||||
// child_status.push(compare_element(source, emacs_child, rust_child)?);
|
||||
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
||||
child_status.push(compare_node_property(source, emacs_child, rust_child)?);
|
||||
}
|
||||
|
||||
Ok(DiffResult {
|
||||
@ -966,6 +966,40 @@ fn compare_property_drawer<'s>(
|
||||
.into())
|
||||
}
|
||||
|
||||
fn compare_node_property<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
rust: &'s NodeProperty<'s>,
|
||||
) -> Result<DiffEntry<'s>, Box<dyn std::error::Error>> {
|
||||
let child_status = Vec::new();
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let mut message = None;
|
||||
let emacs_name = "node-property";
|
||||
if assert_name(emacs, emacs_name).is_err() {
|
||||
this_status = DiffStatus::Bad;
|
||||
}
|
||||
|
||||
match assert_bounds(source, emacs, rust) {
|
||||
Err(err) => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(err.to_string())
|
||||
}
|
||||
Ok(_) => {}
|
||||
};
|
||||
|
||||
// TODO: Compare :key :value
|
||||
|
||||
Ok(DiffResult {
|
||||
status: this_status,
|
||||
name: emacs_name.to_owned(),
|
||||
message,
|
||||
children: child_status,
|
||||
rust_source: rust.get_source(),
|
||||
emacs_token: emacs,
|
||||
}
|
||||
.into())
|
||||
}
|
||||
|
||||
fn compare_table<'s>(
|
||||
source: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
|
@ -4,6 +4,7 @@ use crate::types::Document;
|
||||
use crate::types::DocumentElement;
|
||||
use crate::types::Element;
|
||||
use crate::types::Heading;
|
||||
use crate::types::NodeProperty;
|
||||
use crate::types::Object;
|
||||
use crate::types::PlainListItem;
|
||||
use crate::types::Section;
|
||||
@ -19,6 +20,7 @@ pub enum Token<'r, 's> {
|
||||
PlainListItem(&'r PlainListItem<'s>),
|
||||
TableRow(&'r TableRow<'s>),
|
||||
TableCell(&'r TableCell<'s>),
|
||||
NodeProperty(&'r NodeProperty<'s>),
|
||||
}
|
||||
|
||||
impl<'r, 's> Token<'r, 's> {
|
||||
@ -81,7 +83,9 @@ impl<'r, 's> Token<'r, 's> {
|
||||
}
|
||||
Element::Comment(_) => Box::new(std::iter::empty()),
|
||||
Element::Drawer(inner) => Box::new(inner.children.iter().map(Token::Element)),
|
||||
Element::PropertyDrawer(_) => Box::new(std::iter::empty()),
|
||||
Element::PropertyDrawer(inner) => {
|
||||
Box::new(inner.children.iter().map(Token::NodeProperty))
|
||||
}
|
||||
Element::Table(inner) => Box::new(inner.children.iter().map(Token::TableRow)),
|
||||
Element::VerseBlock(inner) => Box::new(inner.children.iter().map(Token::Object)),
|
||||
Element::CommentBlock(_) => Box::new(std::iter::empty()),
|
||||
@ -100,6 +104,7 @@ impl<'r, 's> Token<'r, 's> {
|
||||
Token::PlainListItem(elem) => Box::new(elem.children.iter().map(Token::Element)),
|
||||
Token::TableRow(elem) => Box::new(elem.children.iter().map(Token::TableCell)),
|
||||
Token::TableCell(elem) => Box::new(elem.children.iter().map(Token::Object)),
|
||||
Token::NodeProperty(_) => Box::new(std::iter::empty()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +114,12 @@ impl<'s> Source<'s> for PropertyDrawer<'s> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for NodeProperty<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Source<'s> for Table<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
|
Loading…
Reference in New Issue
Block a user