Implement compare for list of quoted strings.
This commit is contained in:
		
							parent
							
								
									9520e5814b
								
							
						
					
					
						commit
						f227d8405e
					
				| @ -15,7 +15,9 @@ pub use compare::silent_compare_on_file; | ||||
| pub(crate) use compare_field::EmacsField; | ||||
| pub(crate) use elisp_fact::ElispFact; | ||||
| pub use sexp::sexp; | ||||
| pub(crate) use sexp::unquote; | ||||
| pub use sexp::Token; | ||||
| pub(crate) use util::get_emacs_standard_properties; | ||||
| pub(crate) use util::get_property; | ||||
| pub(crate) use util::get_property_quoted_string; | ||||
| pub(crate) use util::EmacsStandardProperties; | ||||
|  | ||||
| @ -2,7 +2,9 @@ use super::diff::WasmDiffResult; | ||||
| use super::diff::WasmDiffStatus; | ||||
| use super::elisp_compare::WasmElispCompare; | ||||
| use crate::compare::get_emacs_standard_properties; | ||||
| use crate::compare::get_property; | ||||
| use crate::compare::get_property_quoted_string; | ||||
| use crate::compare::unquote; | ||||
| use crate::compare::Token; | ||||
| use crate::wasm::AdditionalProperties; | ||||
| use crate::wasm::AdditionalPropertyValue; | ||||
| @ -76,6 +78,79 @@ pub(crate) fn wasm_compare_property_quoted_string< | ||||
|     Ok(result) | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn wasm_compare_property_list_of_quoted_string< | ||||
|     'b, | ||||
|     's, | ||||
|     WI: Iterator<Item = WV> + ExactSizeIterator, | ||||
|     W, | ||||
|     WV: AsRef<str> + std::fmt::Debug, | ||||
|     WG: Fn(W) -> Option<WI>, | ||||
| >( | ||||
|     _source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
|     wasm_node: W, | ||||
|     emacs_field: &str, | ||||
|     wasm_value_getter: WG, | ||||
| ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { | ||||
|     let mut result = WasmDiffResult::default(); | ||||
|     let emacs_value = get_property(emacs, emacs_field)? | ||||
|         .map(Token::as_list) | ||||
|         .map_or(Ok(None), |r| r.map(Some))?; | ||||
|     let wasm_value = wasm_value_getter(wasm_node); | ||||
|     match (emacs_value, wasm_value) { | ||||
|         (None, None) => {} | ||||
|         (None, Some(_)) | (Some(_), None) => { | ||||
|             return Ok(WasmDiffResult { | ||||
|             status: vec![WasmDiffStatus::Bad( | ||||
|                 format!( | ||||
|                     "Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", | ||||
|                     property = emacs_field, | ||||
|                     emacs = if emacs_value.is_some() {"Some"} else {"None"}, | ||||
|                     wasm = if !emacs_value.is_some() {"Some"} else {"None"} | ||||
|                 ) | ||||
|                 .into(), | ||||
|             )], | ||||
|             children: Vec::new(), | ||||
|             name: "".into(), | ||||
|         }); | ||||
|         } | ||||
|         (Some(el), Some(wl)) if el.len() != wl.len() => { | ||||
|             return Ok(WasmDiffResult { | ||||
|             status: vec![WasmDiffStatus::Bad( | ||||
|                 format!( | ||||
|                     "Property list length mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", | ||||
|                     property = emacs_field, | ||||
|                     emacs = el.len(), | ||||
|                     wasm = wl.len() | ||||
|                 ) | ||||
|                 .into(), | ||||
|             )], | ||||
|             children: Vec::new(), | ||||
|             name: "".into(), | ||||
|         }); | ||||
|         } | ||||
|         (Some(el), Some(wl)) => { | ||||
|             for (e, w) in el.iter().zip(wl) { | ||||
|                 let e = unquote(e.as_atom()?)?; | ||||
|                 let w = w.as_ref(); | ||||
|                 if e != w { | ||||
|                     result.status.push(WasmDiffStatus::Bad( | ||||
|                         format!( | ||||
|                             "Property list value mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).", | ||||
|                             property = emacs_field, | ||||
|                             emacs = e, | ||||
|                             wasm = w | ||||
|                         ) | ||||
|                             .into(), | ||||
|                     )); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     Ok(result) | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn wasm_compare_standard_properties<'b, 's>( | ||||
|     _source: &'s str, | ||||
|     emacs: &'b Token<'s>, | ||||
| @ -168,8 +243,16 @@ pub(crate) fn wasm_compare_additional_properties<'b, 's>( | ||||
|                     |_| Some(wasm_value), | ||||
|                 )?)?; | ||||
|             } | ||||
|             AdditionalPropertyValue::ListOfStrings(wasm_value) => { | ||||
|                 layer.extend(wasm_compare_property_list_of_quoted_string( | ||||
|                     source, | ||||
|                     emacs, | ||||
|                     wasm, | ||||
|                     &emacs_property_name, | ||||
|                     |_| Some(wasm_value.iter()), | ||||
|                 )?)?; | ||||
|             } | ||||
|             // TODO: similar to compare_affiliated_keywords
 | ||||
|             AdditionalPropertyValue::ListOfStrings(_) => todo!(), | ||||
|             AdditionalPropertyValue::OptionalPair { optval, val } => todo!(), | ||||
|             AdditionalPropertyValue::ObjectTree(_) => todo!(), | ||||
|         } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander