Starting a compare properties document function.
This commit is contained in:
		
							parent
							
								
									360b2d963d
								
							
						
					
					
						commit
						a873794068
					
				| @ -23,6 +23,7 @@ use super::sexp::unquote; | ||||
| use super::sexp::Token; | ||||
| use super::util::assert_no_children; | ||||
| use super::util::compare_children; | ||||
| use super::util::compare_children_iter; | ||||
| use super::util::compare_standard_properties; | ||||
| use super::util::get_property; | ||||
| use super::util::get_property_boolean; | ||||
| @ -438,6 +439,63 @@ pub fn compare_document<'b, 's>( | ||||
| } | ||||
| 
 | ||||
| fn _compare_document<'b, 's>( | ||||
|     source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
|     rust: &'b Document<'s>, | ||||
| ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut child_status = Vec::new(); | ||||
|     let mut message = None; | ||||
| 
 | ||||
|     // compare_children_iter(
 | ||||
|     //     source,
 | ||||
|     //     emacs,
 | ||||
|     //     rust.zeroth_section
 | ||||
|     //         .iter()
 | ||||
|     //         .map(Into::<AstNode>::into)
 | ||||
|     //         .chain(rust.children.iter().map(Into::<AstNode>::into)),
 | ||||
|     //     &mut child_status,
 | ||||
|     //     &mut this_status,
 | ||||
|     //     &mut message,
 | ||||
|     // )?;
 | ||||
| 
 | ||||
|     for diff in compare_properties!( | ||||
|         source, | ||||
|         emacs, | ||||
|         rust, | ||||
|         // (
 | ||||
|         //     EmacsField::Optional(":name"),
 | ||||
|         //     |r| r.name,
 | ||||
|         //     compare_property_quoted_string
 | ||||
|         // ),
 | ||||
|         ( | ||||
|             EmacsField::Optional(":caption"), | ||||
|             compare_identity, | ||||
|             compare_noop | ||||
|         ) | ||||
|     ) { | ||||
|         match diff { | ||||
|             ComparePropertiesResult::NoChange => {} | ||||
|             ComparePropertiesResult::SelfChange(new_status, new_message) => { | ||||
|                 this_status = new_status; | ||||
|                 message = new_message | ||||
|             } | ||||
|             ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
|         status: this_status, | ||||
|         name: rust.get_elisp_name(), | ||||
|         message, | ||||
|         children: child_status, | ||||
|         rust_source: rust.get_source(), | ||||
|         emacs_token: emacs, | ||||
|     } | ||||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| fn _old_compare_document<'b, 's>( | ||||
|     _source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
|     rust: &'b Document<'s>, | ||||
|  | ||||
| @ -284,6 +284,39 @@ where | ||||
|     Ok(()) | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn compare_children_iter< | ||||
|     'b, | ||||
|     's, | ||||
|     'x, | ||||
|     RC: 'x, | ||||
|     RI: Iterator<Item = &'x RC> + ExactSizeIterator, | ||||
| >( | ||||
|     source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
|     rust_children: RI, | ||||
|     child_status: &mut Vec<DiffEntry<'b, 's>>, | ||||
|     this_status: &mut DiffStatus, | ||||
|     message: &mut Option<String>, | ||||
| ) -> Result<(), Box<dyn std::error::Error>> | ||||
| where | ||||
|     AstNode<'b, 's>: From<&'x RC>, | ||||
| { | ||||
|     let emacs_children = emacs.as_list()?; | ||||
|     let emacs_children_length = emacs_children.len() - 2; | ||||
|     if emacs_children_length != rust_children.len() { | ||||
|         *this_status = DiffStatus::Bad; | ||||
|         *message = Some(format!( | ||||
|             "Child length mismatch (emacs != rust) {:?} != {:?}", | ||||
|             emacs_children_length, | ||||
|             rust_children.len() | ||||
|         )); | ||||
|     } | ||||
|     for (emacs_child, rust_child) in emacs_children.iter().skip(2).zip(rust_children) { | ||||
|         child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); | ||||
|     } | ||||
|     Ok(()) | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn assert_no_children<'b, 's>( | ||||
|     emacs: &'b Token<'s>, | ||||
|     this_status: &mut DiffStatus, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander