Compare heading todo keywords.
This only handles the default case where the only valid TODO keywords are TODO and DONE.
This commit is contained in:
@@ -2,6 +2,7 @@ use std::collections::HashSet;
|
||||
|
||||
use super::util::assert_bounds;
|
||||
use super::util::assert_name;
|
||||
use crate::parser::sexp::unquote;
|
||||
use crate::parser::sexp::Token;
|
||||
use crate::parser::AngleLink;
|
||||
use crate::parser::Bold;
|
||||
@@ -60,7 +61,6 @@ use crate::parser::Timestamp;
|
||||
use crate::parser::Underline;
|
||||
use crate::parser::Verbatim;
|
||||
use crate::parser::VerseBlock;
|
||||
use crate::parser::sexp::unquote;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DiffResult {
|
||||
@@ -336,6 +336,45 @@ fn compare_heading<'s>(
|
||||
this_status = DiffStatus::Bad;
|
||||
}
|
||||
|
||||
// Compare tags
|
||||
let emacs_tags = get_tags_from_heading(emacs)?;
|
||||
let emacs_tags: HashSet<_> = emacs_tags.iter().map(|val| val.as_str()).collect();
|
||||
let rust_tags: HashSet<&str> = rust.tags.iter().map(|val| *val).collect();
|
||||
let difference: Vec<&str> = emacs_tags
|
||||
.symmetric_difference(&rust_tags)
|
||||
.map(|val| *val)
|
||||
.collect();
|
||||
if !difference.is_empty() {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!("Mismatched tags: {}", difference.join(", ")));
|
||||
}
|
||||
|
||||
// Compare todo-keyword
|
||||
let todo_keyword = {
|
||||
let children = emacs.as_list()?;
|
||||
let attributes_child = children
|
||||
.iter()
|
||||
.nth(1)
|
||||
.ok_or("Should have an attributes child.")?;
|
||||
let attributes_map = attributes_child.as_map()?;
|
||||
let todo_keyword = attributes_map
|
||||
.get(":todo-keyword")
|
||||
.ok_or("Missing :todo-keyword attribute.");
|
||||
todo_keyword?.as_atom()?
|
||||
};
|
||||
match (todo_keyword, rust.todo_keyword, unquote(todo_keyword)) {
|
||||
("nil", None, _) => {}
|
||||
(_, Some(rust_todo), Ok(emacs_todo)) if emacs_todo == rust_todo => {}
|
||||
(emacs_todo, rust_todo, _) => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"(emacs != rust) {:?} != {:?}",
|
||||
emacs_todo, rust_todo
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
// Compare title
|
||||
let title = {
|
||||
let children = emacs.as_list()?;
|
||||
let attributes_child = children
|
||||
@@ -351,20 +390,10 @@ fn compare_heading<'s>(
|
||||
for (emacs_child, rust_child) in title.as_list()?.iter().zip(rust.title.iter()) {
|
||||
child_status.push(compare_object(source, emacs_child, rust_child)?);
|
||||
}
|
||||
let emacs_tags = get_tags_from_heading(emacs)?;
|
||||
let emacs_tags: HashSet<_> = emacs_tags.iter().map(|val| val.as_str()).collect();
|
||||
let rust_tags: HashSet<&str> = rust.tags.iter().map(|val| *val).collect();
|
||||
let difference: Vec<&str> = emacs_tags
|
||||
.symmetric_difference(&rust_tags)
|
||||
.map(|val| *val)
|
||||
.collect();
|
||||
if !difference.is_empty() {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!("Mismatched tags: {}", difference.join(", ")));
|
||||
}
|
||||
|
||||
// TODO: Compare todo-keyword, level, priority
|
||||
// TODO: Compare todo-type, level, priority
|
||||
|
||||
// Compare section
|
||||
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
|
||||
match rust_child {
|
||||
DocumentElement::Heading(rust_heading) => {
|
||||
@@ -405,8 +434,14 @@ fn get_tags_from_heading<'s>(
|
||||
};
|
||||
let tags = {
|
||||
let tags = tags.as_list()?;
|
||||
let strings = tags.iter().map(Token::as_atom).collect::<Result<Vec<&str>, _>>()?;
|
||||
strings.into_iter().map(unquote).collect::<Result<HashSet<String>, _>>()?
|
||||
let strings = tags
|
||||
.iter()
|
||||
.map(Token::as_atom)
|
||||
.collect::<Result<Vec<&str>, _>>()?;
|
||||
strings
|
||||
.into_iter()
|
||||
.map(unquote)
|
||||
.collect::<Result<HashSet<String>, _>>()?
|
||||
};
|
||||
Ok(tags)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user