Taking into account additional property names but not comparing their values.
This commit is contained in:
		
							parent
							
								
									a5e108bc37
								
							
						
					
					
						commit
						f050e9b6a8
					
				
							
								
								
									
										27
									
								
								src/wasm/additional_property.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/wasm/additional_property.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| use std::collections::HashMap; | ||||
| 
 | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use super::WasmAstNode; | ||||
| 
 | ||||
| #[derive(Debug, Serialize)] | ||||
| pub enum AdditionalPropertyValue<'s, 'p> { | ||||
|     SingleString(&'s str), | ||||
|     ListOfStrings(Vec<&'s str>), | ||||
|     OptionalPair { | ||||
|         optval: Option<&'s str>, | ||||
|         val: &'s str, | ||||
|     }, | ||||
|     ObjectTree(Vec<(Option<Vec<WasmAstNode<'s, 'p>>>, Vec<WasmAstNode<'s, 'p>>)>), | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, Serialize, Default)] | ||||
| pub struct AdditionalProperties<'s, 'p> { | ||||
|     pub(crate) properties: HashMap<String, AdditionalPropertyValue<'s, 'p>>, | ||||
| } | ||||
| 
 | ||||
| impl<'s, 'p> AdditionalProperties<'s, 'p> { | ||||
|     pub(crate) fn get_elisp_names<'c>(&'c self) -> impl Iterator<Item = String> + 'c { | ||||
|         self.properties.keys().map(move |key| format!(":{}", key)) | ||||
|     } | ||||
| } | ||||
| @ -2,6 +2,8 @@ use std::path::PathBuf; | ||||
| 
 | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use super::additional_property::AdditionalProperties; | ||||
| use super::additional_property::AdditionalPropertyValue; | ||||
| use super::ast_node::WasmAstNode; | ||||
| use super::macros::to_wasm; | ||||
| use super::standard_properties::WasmStandardProperties; | ||||
| @ -16,7 +18,7 @@ use crate::wasm::to_wasm::ToWasmStandardProperties; | ||||
| #[serde(rename = "org-data")] | ||||
| pub struct WasmDocument<'s, 'p> { | ||||
|     pub(crate) standard_properties: WasmStandardProperties, | ||||
|     additional_properties: Vec<(String, &'s str)>, | ||||
|     pub(crate) additional_properties: AdditionalProperties<'s, 'p>, | ||||
|     pub(crate) children: Vec<WasmAstNode<'s, 'p>>, | ||||
|     pub(crate) category: Option<&'p str>, | ||||
|     pub(crate) path: Option<PathBuf>, | ||||
| @ -32,15 +34,15 @@ to_wasm!( | ||||
|         let category = original.category.as_ref().map(String::as_str); | ||||
|         let path = original.path.clone(); | ||||
| 
 | ||||
|         let additional_properties: Vec<(String, &str)> = original | ||||
|             .get_additional_properties() | ||||
|             .map(|node_property| { | ||||
|                 ( | ||||
|                     format!(":{}", node_property.property_name.to_uppercase()), | ||||
|                     node_property.value.unwrap_or(""), | ||||
|                 ) | ||||
|             }) | ||||
|             .collect(); | ||||
|         let mut additional_properties = AdditionalProperties::default(); | ||||
|         for (name, val) in original.get_additional_properties().map(|node_property| { | ||||
|             ( | ||||
|                 node_property.property_name.to_uppercase(), | ||||
|                 AdditionalPropertyValue::SingleString(node_property.value.unwrap_or("")), | ||||
|             ) | ||||
|         }) { | ||||
|             additional_properties.properties.insert(name, val); | ||||
|         } | ||||
| 
 | ||||
|         let children = original | ||||
|             .zeroth_section | ||||
|  | ||||
| @ -1,3 +1,4 @@ | ||||
| mod additional_property; | ||||
| mod angle_link; | ||||
| mod ast_node; | ||||
| mod babel_call; | ||||
|  | ||||
| @ -40,10 +40,36 @@ macro_rules! wasm_compare { | ||||
|         } | ||||
| 
 | ||||
|         { | ||||
|             // Compare standard properties
 | ||||
|             // Compare standard properties.
 | ||||
|             result.extend(wasm_compare_standard_properties($source, $emacs, &$wasm.standard_properties)?)?; | ||||
|         } | ||||
| 
 | ||||
|         { | ||||
|             // Compare additional properties.
 | ||||
|             let additional_property_names: Vec<String> = $wasm.additional_properties.get_elisp_names().collect(); | ||||
|             for additional_property in additional_property_names.iter().map(String::as_str).map(EmacsField::Required) { | ||||
|                 match additional_property { | ||||
|                     EmacsField::Required(name) if emacs_keys.contains(name) => { | ||||
|                         emacs_keys.remove(name); | ||||
|                     } | ||||
|                     EmacsField::Optional(name) if emacs_keys.contains(name) => { | ||||
|                         emacs_keys.remove(name); | ||||
|                     } | ||||
|                     EmacsField::Required(name) => { | ||||
|                         result.status.push(WasmDiffStatus::Bad( | ||||
|                             format!( | ||||
|                                 "Emacs node lacked required field ({name}).", | ||||
|                                 name = name, | ||||
|                             ) | ||||
|                             .into(), | ||||
|                         )); | ||||
|                     } | ||||
|                     EmacsField::Optional(_name) => {} | ||||
| 
 | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         { | ||||
|             // Compare children.
 | ||||
|             result.extend(wasm_compare_list( | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander