compare_properties for document.
This commit is contained in:
		
							parent
							
								
									c578bb45af
								
							
						
					
					
						commit
						585b1d2b74
					
				| @ -460,15 +460,15 @@ fn _compare_document<'b, 's>( | ||||
|         source, | ||||
|         emacs, | ||||
|         rust, | ||||
|         // (
 | ||||
|         //     EmacsField::Optional(":name"),
 | ||||
|         //     |r| r.name,
 | ||||
|         //     compare_property_quoted_string
 | ||||
|         // ),
 | ||||
|         ( | ||||
|             EmacsField::Optional(":caption"), | ||||
|             compare_identity, | ||||
|             compare_noop | ||||
|             EmacsField::Required(":path"), | ||||
|             |r| r.path.as_ref().map(|p| p.to_str()).flatten(), | ||||
|             compare_property_quoted_string | ||||
|         ), | ||||
|         ( | ||||
|             EmacsField::Required(":CATEGORY"), | ||||
|             |r| r.category.as_ref(), | ||||
|             compare_property_quoted_string | ||||
|         ) | ||||
|     ) { | ||||
|         match diff { | ||||
| @ -492,114 +492,6 @@ fn _compare_document<'b, 's>( | ||||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| fn _old_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 children = emacs.as_list()?; | ||||
|     let mut child_status = Vec::new(); | ||||
|     let mut this_status = DiffStatus::Good; | ||||
|     let mut message = None; | ||||
| 
 | ||||
|     // Compare :path
 | ||||
|     // :path is a quoted string to the absolute path of the document.
 | ||||
|     let document_path = get_property_quoted_string(emacs, ":path")?; | ||||
|     let rust_document_path = rust.path.as_ref().map(|p| p.to_str()).flatten(); | ||||
|     match ( | ||||
|         document_path.as_ref().map(|s| s.as_str()), | ||||
|         rust_document_path, | ||||
|     ) { | ||||
|         (None, None) => {} | ||||
|         (None, Some(_)) | (Some(_), None) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(format!( | ||||
|                 "Path mismatch (emacs != rust) {:?} != {:?}", | ||||
|                 document_path, rust_document_path | ||||
|             )); | ||||
|         } | ||||
|         (Some(e), Some(r)) if e != r => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(format!( | ||||
|                 "Path mismatch (emacs != rust) {:?} != {:?}", | ||||
|                 document_path, rust_document_path | ||||
|             )); | ||||
|         } | ||||
|         (Some(_), Some(_)) => {} | ||||
|     }; | ||||
| 
 | ||||
|     // Compare category
 | ||||
|     // :CATEGORY is specified either from "#+CATEGORY:" or it is the file name without the ".org" extension.
 | ||||
|     let category = get_property_quoted_string(emacs, ":CATEGORY")?; | ||||
|     match (category.as_ref(), rust.category.as_ref()) { | ||||
|         (None, None) => {} | ||||
|         (None, Some(_)) | (Some(_), None) => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(format!( | ||||
|                 "Category mismatch (emacs != rust) {:?} != {:?}", | ||||
|                 category, rust.category | ||||
|             )); | ||||
|         } | ||||
|         (Some(e), Some(r)) if e != r => { | ||||
|             this_status = DiffStatus::Bad; | ||||
|             message = Some(format!( | ||||
|                 "Category mismatch (emacs != rust) {:?} != {:?}", | ||||
|                 category, rust.category | ||||
|             )); | ||||
|         } | ||||
|         (Some(_), Some(_)) => {} | ||||
|     }; | ||||
| 
 | ||||
|     // Skipping "org-data" and its properties
 | ||||
|     for (i, token) in children.iter().skip(2).enumerate() { | ||||
|         let section_or_headline = token.as_list()?; | ||||
|         let first_cell = section_or_headline | ||||
|             .first() | ||||
|             .ok_or("Should have at least one child.")? | ||||
|             .as_atom()?; | ||||
|         if first_cell == "section" { | ||||
|             if i != 0 { | ||||
|                 return Err("Section cannot be after the first child of document.".into()); | ||||
|             } | ||||
|             child_status.push(compare_ast_node( | ||||
|                 rust.source, | ||||
|                 token, | ||||
|                 rust.zeroth_section | ||||
|                     .as_ref() | ||||
|                     .ok_or("No corresponding zeroth-section")? | ||||
|                     .into(), | ||||
|             )?); | ||||
|         } else if first_cell == "headline" { | ||||
|             let corresponding_heading = rust | ||||
|                 .children | ||||
|                 .iter() | ||||
|                 .nth(i - rust.zeroth_section.as_ref().map(|_| 1).unwrap_or(0)) | ||||
|                 .ok_or("Should have a corresponding heading.")?; | ||||
|             child_status.push(compare_ast_node( | ||||
|                 rust.source, | ||||
|                 token, | ||||
|                 corresponding_heading.into(), | ||||
|             )?); | ||||
|         } else { | ||||
|             return Err(format!( | ||||
|                 "Document should only contain sections and headlines, found: {}", | ||||
|                 first_cell | ||||
|             ) | ||||
|             .into()); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     Ok(DiffResult { | ||||
|         status: this_status, | ||||
|         name: rust.get_elisp_name(), | ||||
|         message, | ||||
|         children: child_status, | ||||
|         rust_source: rust.get_source(), | ||||
|         emacs_token: emacs, | ||||
|     } | ||||
|     .into()) | ||||
| } | ||||
| 
 | ||||
| fn compare_section<'b, 's>( | ||||
|     source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander