Compare plain list type in diff.rs.
This commit is contained in:
		
							parent
							
								
									a4b1d462c3
								
							
						
					
					
						commit
						f820e27b17
					
				| @ -9,6 +9,7 @@ use super::sexp::unquote; | ||||
| use super::sexp::Token; | ||||
| use super::util::compare_standard_properties; | ||||
| use super::util::get_property; | ||||
| use super::util::get_property_unquoted_atom; | ||||
| use crate::types::AngleLink; | ||||
| use crate::types::BabelCall; | ||||
| use crate::types::Bold; | ||||
| @ -50,6 +51,7 @@ use crate::types::Paragraph; | ||||
| use crate::types::PlainLink; | ||||
| use crate::types::PlainList; | ||||
| use crate::types::PlainListItem; | ||||
| use crate::types::PlainListType; | ||||
| use crate::types::PlainText; | ||||
| use crate::types::Planning; | ||||
| use crate::types::PriorityCookie; | ||||
| @ -748,11 +750,24 @@ fn compare_plain_list<'s>( | ||||
| ) -> Result<DiffEntry<'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 :type
 | ||||
|     //
 | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut message = None; | ||||
| 
 | ||||
|     // :type is an unquoted atom of either descriptive, ordered, or unordered
 | ||||
|     let list_type = get_property_unquoted_atom(emacs, ":type")?; | ||||
|     match (list_type, &rust.list_type) { | ||||
|         (None, _) => panic!("Emacs returned a list with no type."), | ||||
|         (Some("unordered"), PlainListType::Unordered) => {} | ||||
|         (Some("ordered"), PlainListType::Ordered) => {} | ||||
|         (Some("descriptive"), PlainListType::Descriptive) => {} | ||||
|         _ => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(format!( | ||||
|                 "List type mismatch (emacs != rust) {:?} != {:?}", | ||||
|                 list_type, rust.list_type | ||||
|             )); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { | ||||
|         child_status.push(compare_plain_list_item(source, emacs_child, rust_child)?); | ||||
|  | ||||
| @ -190,3 +190,15 @@ pub(crate) fn get_property<'s, 'x>( | ||||
|     }; | ||||
|     Ok(Some(*prop)) | ||||
| } | ||||
| 
 | ||||
| /// Get a named property containing an unquoted atom from the emacs token.
 | ||||
| ///
 | ||||
| /// Returns None if key is not found.
 | ||||
| pub(crate) fn get_property_unquoted_atom<'s, 'x>( | ||||
|     emacs: &'s Token<'s>, | ||||
|     key: &'x str, | ||||
| ) -> Result<Option<&'s str>, Box<dyn std::error::Error>> { | ||||
|     Ok(get_property(emacs, key)? | ||||
|         .map(Token::as_atom) | ||||
|         .map_or(Ok(None), |r| r.map(Some))?) | ||||
| } | ||||
|  | ||||
| @ -148,7 +148,7 @@ pub(crate) fn plain_list<'b, 'g, 'r, 's>( | ||||
|         remaining, | ||||
|         PlainList { | ||||
|             source: source.into(), | ||||
|             list_type: PlainListType::Ordered, | ||||
|             list_type: first_item_list_type.expect("Plain lists require at least one element."), | ||||
|             children: children.into_iter().map(|(_start, item)| item).collect(), | ||||
|         }, | ||||
|     )) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander