Comparing single string values.

This commit is contained in:
Tom Alexander 2023-10-11 13:00:21 -04:00
parent e767892dd5
commit 441a240c33
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 33 additions and 24 deletions

View File

@ -757,11 +757,9 @@ fn compare_plain_list<'b, 's>(
&mut message, &mut message,
)?; )?;
compare_affiliated_keywords(emacs, rust)?.apply( for diff in compare_affiliated_keywords(source, emacs, rust)? {
&mut child_status, diff.apply(&mut child_status, &mut this_status, &mut message);
&mut this_status, }
&mut message,
);
let affiliated_keywords_names: Vec<String> = affiliated_keywords_names(rust).collect(); let affiliated_keywords_names: Vec<String> = affiliated_keywords_names(rust).collect();
for diff in compare_properties!( for diff in compare_properties!(

View File

@ -1,5 +1,6 @@
use std::str::FromStr; use std::str::FromStr;
use super::compare_field::compare_property_quoted_string;
use super::compare_field::ComparePropertiesResult; use super::compare_field::ComparePropertiesResult;
use super::diff::DiffEntry; use super::diff::DiffEntry;
use super::diff::DiffStatus; use super::diff::DiffStatus;
@ -7,6 +8,7 @@ use super::elisp_fact::GetElispFact;
use super::sexp::Token; use super::sexp::Token;
use crate::compare::diff::compare_ast_node; use crate::compare::diff::compare_ast_node;
use crate::compare::sexp::unquote; use crate::compare::sexp::unquote;
use crate::types::AffiliatedKeywordValue;
use crate::types::AstNode; use crate::types::AstNode;
use crate::types::GetAffiliatedKeywords; use crate::types::GetAffiliatedKeywords;
use crate::types::GetStandardProperties; use crate::types::GetStandardProperties;
@ -340,28 +342,37 @@ where
} }
pub(crate) fn compare_affiliated_keywords<'b, 's, GAK>( pub(crate) fn compare_affiliated_keywords<'b, 's, GAK>(
source: &'s str,
emacs: &'b Token<'s>, emacs: &'b Token<'s>,
rust: &'b GAK, rust: &'b GAK,
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> ) -> Result<Vec<ComparePropertiesResult<'b, 's>>, Box<dyn std::error::Error>>
where where
GAK: GetAffiliatedKeywords<'s>, GAK: GetAffiliatedKeywords<'s>,
{ {
let mut ret = Vec::new();
let affiliated_keywords = rust.get_affiliated_keywords(); let affiliated_keywords = rust.get_affiliated_keywords();
for (rust_name, rust_value) in affiliated_keywords.keywords.iter() { for (rust_name, rust_value) in affiliated_keywords.keywords.iter() {
let emacs_property_name = format!(":{}", rust_name); let emacs_property_name = format!(":{}", rust_name);
let emacs_property = get_property(emacs, emacs_property_name.as_str())?; match rust_value {
if let Some(emacs_property) = emacs_property { AffiliatedKeywordValue::SingleString(rust_value) => {
let diff = compare_property_quoted_string(
source,
emacs,
rust,
emacs_property_name.as_str(),
|_| Some(*rust_value),
)?;
ret.push(diff);
}
AffiliatedKeywordValue::ListOfStrings(rust_value) => {
// foo // foo
} else {
let this_status = DiffStatus::Bad;
let message = Some(format!(
"{} mismatch (emacs != rust) {:?} != {:?}",
rust_name, emacs_property, rust_value
));
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
} }
AffiliatedKeywordValue::ListOfListsOfObjects(rust_value) => {
// foo
} }
Ok(ComparePropertiesResult::NoChange) };
}
Ok(ret)
} }
pub(crate) fn affiliated_keywords_names<'s, GAK>(rust: &'s GAK) -> impl Iterator<Item = String> + 's pub(crate) fn affiliated_keywords_names<'s, GAK>(rust: &'s GAK) -> impl Iterator<Item = String> + 's

View File

@ -20,12 +20,12 @@ pub(crate) fn parse_affiliated_keywords<'g, 's>(
let mut ret = BTreeMap::new(); let mut ret = BTreeMap::new();
for kw in input.into_iter() { for kw in input.into_iter() {
let translated_name = translate_name(global_settings, kw.key); let translated_name = translate_name(global_settings, kw.key);
if is_single_string_keyword(global_settings, translated_name) { if is_single_string_keyword(global_settings, translated_name.as_str()) {
ret.insert( ret.insert(
translated_name, translated_name,
AffiliatedKeywordValue::SingleString(kw.value), AffiliatedKeywordValue::SingleString(kw.value),
); );
} else if is_list_of_objects_keyword(global_settings, translated_name) { } else if is_list_of_objects_keyword(global_settings, translated_name.as_str()) {
let initial_context = ContextElement::document_context(); let initial_context = ContextElement::document_context();
let initial_context = Context::new(global_settings, List::new(&initial_context)); let initial_context = Context::new(global_settings, List::new(&initial_context));
@ -58,13 +58,13 @@ pub(crate) fn parse_affiliated_keywords<'g, 's>(
AffiliatedKeywords { keywords: ret } AffiliatedKeywords { keywords: ret }
} }
fn translate_name<'g, 's>(global_settings: &'g GlobalSettings<'g, 's>, name: &'s str) -> &'s str { fn translate_name<'g, 's>(global_settings: &'g GlobalSettings<'g, 's>, name: &'s str) -> String {
for (src, dst) in global_settings.element_keyword_translation_alist { for (src, dst) in global_settings.element_keyword_translation_alist {
if name.eq_ignore_ascii_case(src) { if name.eq_ignore_ascii_case(src) {
return *dst; return dst.to_lowercase();
} }
} }
name name.to_lowercase()
} }
fn is_single_string_keyword<'g, 's>( fn is_single_string_keyword<'g, 's>(

View File

@ -17,7 +17,7 @@ pub struct AffiliatedKeyword<'s> {
#[derive(Debug)] #[derive(Debug)]
pub struct AffiliatedKeywords<'s> { pub struct AffiliatedKeywords<'s> {
pub(crate) keywords: BTreeMap<&'s str, AffiliatedKeywordValue<'s>>, pub(crate) keywords: BTreeMap<String, AffiliatedKeywordValue<'s>>,
} }
pub trait GetAffiliatedKeywords<'s> { pub trait GetAffiliatedKeywords<'s> {