From f4e0dddd9da3a6e297593fc1b3393013e955ff16 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 30 Dec 2023 22:42:14 -0500 Subject: [PATCH] Fix clippy. --- .lighthouse/pipeline-rustfmt.yaml | 2 +- docker/organic_clippy/Makefile | 2 +- src/compare/mod.rs | 4 - src/wasm/additional_property.rs | 7 -- src/wasm/document.rs | 4 +- src/wasm/example_block.rs | 4 +- src/wasm/headline.rs | 8 +- src/wasm/macros.rs | 7 +- src/wasm/plain_list_item.rs | 4 +- src/wasm/plain_text.rs | 2 +- src/wasm/planning.rs | 8 +- src/wasm/src_block.rs | 6 +- src/wasm/table.rs | 4 +- src/wasm/verse_block.rs | 2 +- src/wasm_test/compare.rs | 98 ++++++++++---------- src/wasm_test/diff.rs | 5 +- src/wasm_test/macros.rs | 143 ------------------------------ src/wasm_test/mod.rs | 1 - 18 files changed, 80 insertions(+), 231 deletions(-) delete mode 100644 src/wasm_test/macros.rs diff --git a/.lighthouse/pipeline-rustfmt.yaml b/.lighthouse/pipeline-rustfmt.yaml index 9e6d656..aa290fb 100644 --- a/.lighthouse/pipeline-rustfmt.yaml +++ b/.lighthouse/pipeline-rustfmt.yaml @@ -127,7 +127,7 @@ spec: - name: command value: ["cargo", "fix"] - name: args - value: ["--allow-dirty"] + value: ["--all-targets", "--all-features", "--allow-dirty"] - name: docker-image value: "$(params.image-name):$(tasks.fetch-repository.results.commit)" - name: commit-changes diff --git a/docker/organic_clippy/Makefile b/docker/organic_clippy/Makefile index 6e9fb21..8553fb2 100644 --- a/docker/organic_clippy/Makefile +++ b/docker/organic_clippy/Makefile @@ -30,7 +30,7 @@ endif # NOTE: This target will write to folders underneath the git-root .PHONY: run run: build - docker run --rm --init --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME) + docker run --rm --init -t --read-only --mount type=tmpfs,destination=/tmp -v "$$(readlink -f ../../):/source:ro" --workdir=/source --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target $(IMAGE_NAME) .PHONY: shell shell: build diff --git a/src/compare/mod.rs b/src/compare/mod.rs index 6df7f61..136f02b 100644 --- a/src/compare/mod.rs +++ b/src/compare/mod.rs @@ -11,13 +11,9 @@ pub use compare::run_compare_on_file; pub use compare::run_compare_on_file_with_settings; pub use compare::silent_anonymous_compare; pub use compare::silent_compare_on_file; - pub use sexp::sexp; pub(crate) use sexp::unquote; pub(crate) use sexp::TextWithProperties; pub use sexp::Token; - - - pub(crate) use util::maybe_token_to_usize; pub(crate) use util::EmacsStandardProperties; diff --git a/src/wasm/additional_property.rs b/src/wasm/additional_property.rs index b7ce476..051d716 100644 --- a/src/wasm/additional_property.rs +++ b/src/wasm/additional_property.rs @@ -1,4 +1,3 @@ - use std::collections::HashMap; use serde::Deserialize; @@ -31,12 +30,6 @@ pub struct AdditionalProperties { pub(crate) properties: HashMap, } -impl AdditionalProperties { - pub(crate) fn get_elisp_names<'c>(&'c self) -> impl Iterator + 'c { - self.properties.keys().map(move |key| format!(":{}", key)) - } -} - to_wasm!( AdditionalProperties, AffiliatedKeywords<'s>, diff --git a/src/wasm/document.rs b/src/wasm/document.rs index 0b2bbc0..6286406 100644 --- a/src/wasm/document.rs +++ b/src/wasm/document.rs @@ -8,8 +8,8 @@ use super::additional_property::AdditionalPropertyValue; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; -use crate::util::elisp_fact::ElispFact; use crate::types::Document; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] @@ -29,7 +29,7 @@ to_wasm!( { WasmAstNode::Document(original) }, { "org-data".into() }, { - let category = original.category.as_ref().map(String::as_str); + let category = original.category.as_deref(); let path = original.path.clone(); let mut additional_properties = AdditionalProperties::default(); diff --git a/src/wasm/example_block.rs b/src/wasm/example_block.rs index a50fb5d..e7945ff 100644 --- a/src/wasm/example_block.rs +++ b/src/wasm/example_block.rs @@ -8,12 +8,12 @@ use super::src_block::WasmNumberLinesWrapper; use super::src_block::WasmRetainLabels; use super::to_wasm::ToWasm; use super::AdditionalProperties; -use crate::util::elisp_fact::ElispFact; use crate::types::CharOffsetInLine; use crate::types::ExampleBlock; use crate::types::GetAffiliatedKeywords; use crate::types::RetainLabels; use crate::types::SwitchNumberLines; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] @@ -58,7 +58,7 @@ to_wasm!( inner: WasmNumberLines::New(n), }), Some(SwitchNumberLines::Continued(n)) => Some(WasmNumberLinesWrapper { - inner: WasmNumberLines::continued(n), + inner: WasmNumberLines::Continued(n), }), }, preserve_indent: original.preserve_indent, diff --git a/src/wasm/headline.rs b/src/wasm/headline.rs index 5413a1d..137ab34 100644 --- a/src/wasm/headline.rs +++ b/src/wasm/headline.rs @@ -6,11 +6,11 @@ use super::macros::to_wasm; use super::to_wasm::ToWasm; use super::AdditionalProperties; use super::AdditionalPropertyValue; -use crate::util::elisp_fact::ElispFact; use crate::types::Heading; use crate::types::HeadlineLevel; use crate::types::PriorityCookie; use crate::types::TodoKeywordType; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] @@ -112,7 +112,7 @@ to_wasm!( .map(Into::::into) }) .map_or(Ok(None), |r| r.map(Some))? - .map(|child| Box::new(child)), + .map(Box::new), deadline: original .deadline .as_ref() @@ -122,7 +122,7 @@ to_wasm!( .map(Into::::into) }) .map_or(Ok(None), |r| r.map(Some))? - .map(|child| Box::new(child)), + .map(Box::new), closed: original .closed .as_ref() @@ -132,7 +132,7 @@ to_wasm!( .map(Into::::into) }) .map_or(Ok(None), |r| r.map(Some))? - .map(|child| Box::new(child)), + .map(Box::new), pre_blank: Noop {}, }, )) diff --git a/src/wasm/macros.rs b/src/wasm/macros.rs index 81ef247..590d4d3 100644 --- a/src/wasm/macros.rs +++ b/src/wasm/macros.rs @@ -23,6 +23,7 @@ macro_rules! to_wasm { &self, $wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>, ) -> Result { + #[allow(unused_variables)] let $original = self; let standard_properties = self.to_wasm_standard_properties($wasm_context.clone())?; @@ -38,9 +39,8 @@ macro_rules! to_wasm { } } - impl Into for crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct> { - fn into(self) -> WasmAstNode { - let $original = self; + impl From> for WasmAstNode { + fn from($original: crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct>) -> Self { let ret = $toastnodebody; ret } @@ -48,7 +48,6 @@ macro_rules! to_wasm { impl<'s> crate::util::elisp_fact::ElispFact<'s> for $ostruct { fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> { - let $original = self; let ret = $elispnamebody; ret } diff --git a/src/wasm/plain_list_item.rs b/src/wasm/plain_list_item.rs index 0e845ef..8081b6e 100644 --- a/src/wasm/plain_list_item.rs +++ b/src/wasm/plain_list_item.rs @@ -4,11 +4,11 @@ use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; -use crate::util::elisp_fact::ElispFact; use crate::types::CheckboxType; use crate::types::PlainListItem; use crate::types::PlainListItemCounter; use crate::types::PlainListItemPreBlank; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] @@ -52,7 +52,7 @@ to_wasm!( }) .collect::, _>>()?, bullet: original.bullet.to_owned(), - counter: original.counter.clone(), + counter: original.counter, checkbox: original.checkbox.as_ref().map(|(checkbox_type, _)| { match checkbox_type { CheckboxType::On => "on", diff --git a/src/wasm/plain_text.rs b/src/wasm/plain_text.rs index 339b283..e339c71 100644 --- a/src/wasm/plain_text.rs +++ b/src/wasm/plain_text.rs @@ -4,8 +4,8 @@ use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; -use crate::util::elisp_fact::ElispFact; use crate::types::PlainText; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] diff --git a/src/wasm/planning.rs b/src/wasm/planning.rs index b98f6db..1091f6e 100644 --- a/src/wasm/planning.rs +++ b/src/wasm/planning.rs @@ -4,8 +4,8 @@ use serde::Serialize; use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; -use crate::util::elisp_fact::ElispFact; use crate::types::Planning; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] @@ -35,7 +35,7 @@ to_wasm!( .map(Into::::into) }) .map_or(Ok(None), |r| r.map(Some))? - .map(|child| Box::new(child)), + .map(Box::new), deadline: original .deadline .as_ref() @@ -45,7 +45,7 @@ to_wasm!( .map(Into::::into) }) .map_or(Ok(None), |r| r.map(Some))? - .map(|child| Box::new(child)), + .map(Box::new), closed: original .closed .as_ref() @@ -55,7 +55,7 @@ to_wasm!( .map(Into::::into) }) .map_or(Ok(None), |r| r.map(Some))? - .map(|child| Box::new(child)), + .map(Box::new), }, )) } diff --git a/src/wasm/src_block.rs b/src/wasm/src_block.rs index fc8563f..7633c54 100644 --- a/src/wasm/src_block.rs +++ b/src/wasm/src_block.rs @@ -5,13 +5,13 @@ use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; use super::AdditionalProperties; -use crate::util::elisp_fact::ElispFact; use crate::types::CharOffsetInLine; use crate::types::GetAffiliatedKeywords; use crate::types::LineNumber; use crate::types::RetainLabels; use crate::types::SrcBlock; use crate::types::SwitchNumberLines; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] @@ -46,7 +46,7 @@ pub(crate) enum WasmNumberLines { #[serde(rename = "new")] New(LineNumber), #[serde(rename = "continued")] - continued(LineNumber), + Continued(LineNumber), } #[derive(Debug, Serialize, Deserialize)] @@ -83,7 +83,7 @@ to_wasm!( inner: WasmNumberLines::New(n), }), Some(SwitchNumberLines::Continued(n)) => Some(WasmNumberLinesWrapper { - inner: WasmNumberLines::continued(n), + inner: WasmNumberLines::Continued(n), }), }, preserve_indent: original.preserve_indent, diff --git a/src/wasm/table.rs b/src/wasm/table.rs index 3c1ef32..e034069 100644 --- a/src/wasm/table.rs +++ b/src/wasm/table.rs @@ -7,9 +7,9 @@ use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; use super::AdditionalProperties; -use crate::util::elisp_fact::ElispFact; use crate::types::GetAffiliatedKeywords; use crate::types::Table; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] @@ -26,7 +26,7 @@ pub struct WasmTable { #[derive(Debug, Serialize, Deserialize)] #[serde(tag = "string-set")] #[serde(rename = "string-set")] -struct WasmStringSet { +pub(crate) struct WasmStringSet { value: BTreeSet, } diff --git a/src/wasm/verse_block.rs b/src/wasm/verse_block.rs index 585df0e..5028223 100644 --- a/src/wasm/verse_block.rs +++ b/src/wasm/verse_block.rs @@ -5,9 +5,9 @@ use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::to_wasm::ToWasm; use super::AdditionalProperties; -use crate::util::elisp_fact::ElispFact; use crate::types::GetAffiliatedKeywords; use crate::types::VerseBlock; +use crate::util::elisp_fact::ElispFact; use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize, Deserialize)] diff --git a/src/wasm_test/compare.rs b/src/wasm_test/compare.rs index f73181f..7fda10d 100644 --- a/src/wasm_test/compare.rs +++ b/src/wasm_test/compare.rs @@ -13,19 +13,19 @@ use crate::compare::Token; use crate::wasm::WasmAstNodeWrapper; use crate::wasm::WasmDocument; -pub fn wasm_compare_document<'e, 's, 'w>( +pub fn wasm_compare_document<'s>( source: &'s str, - emacs: &'e Token<'s>, - wasm: &'w WasmAstNodeWrapper, + emacs: &Token<'s>, + wasm: &WasmAstNodeWrapper, ) -> Result, Box> { let wasm_json = serde_json::to_string(&wasm)?; let wasm_json_parsed = serde_json::from_str(&wasm_json)?; compare_json_value(source, emacs, &wasm_json_parsed) } -fn compare_json_value<'b, 's>( +fn compare_json_value<'s>( source: &'s str, - emacs: &'b Token<'s>, + emacs: &Token<'s>, wasm: &serde_json::Value, ) -> Result, Box> { // println!("XXXXXXXXXXXXXX compare_json_value XXXXXXXXXXXXXX"); @@ -147,9 +147,9 @@ fn compare_json_value<'b, 's>( } } -fn compare_optional_json_value<'b, 's>( +fn compare_optional_json_value<'s>( source: &'s str, - emacs: Option<&'b Token<'s>>, + emacs: Option<&Token<'s>>, wasm: Option<&serde_json::Value>, ) -> Result, Box> { match (emacs, wasm) { @@ -175,10 +175,10 @@ fn compare_optional_json_value<'b, 's>( } } -fn compare_ast_node<'e, 's, 'w>( +fn compare_ast_node<'s>( source: &'s str, - emacs: &'e Vec>, - wasm: &'w serde_json::Map, + emacs: &[Token<'s>], + wasm: &serde_json::Map, ) -> Result, Box> { let mut result = WasmDiffResult::default(); let mut emacs_list_iter = emacs.iter(); @@ -277,11 +277,13 @@ fn compare_ast_node<'e, 's, 'w>( { // Compare attributes. for attribute_name in wasm_attributes_map.keys() { - let mut layer = WasmDiffResult::default(); - layer.name = Cow::Owned(attribute_name.clone()); + let mut layer = WasmDiffResult::<'_> { + name: Cow::Owned(attribute_name.clone()), + ..Default::default() + }; let wasm_attribute_value = wasm_attributes_map.get(attribute_name); let emacs_key = wasm_key_to_emacs_key(attribute_name); - let emacs_attribute_value = emacs_attributes_map.get(emacs_key.as_str()).map(|e| *e); + let emacs_attribute_value = emacs_attributes_map.get(emacs_key.as_str()).copied(); let inner_layer = compare_optional_json_value(source, emacs_attribute_value, wasm_attribute_value)?; if !inner_layer.name.is_empty() { @@ -295,8 +297,10 @@ fn compare_ast_node<'e, 's, 'w>( { // Compare standard-properties. - let mut layer = WasmDiffResult::default(); - layer.name = "standard-properties".into(); + let mut layer = WasmDiffResult::<'_> { + name: "standard-properties".into(), + ..Default::default() + }; let emacs_standard_properties = wasm_get_emacs_standard_properties(&emacs_attributes_map)?; let wasm_standard_properties = wasm .get("standard-properties") @@ -349,12 +353,13 @@ fn compare_ast_node<'e, 's, 'w>( { // Compare children. - let mut layer = WasmDiffResult::default(); - layer.name = "children".into(); + let mut layer = WasmDiffResult::<'_> { + name: "children".into(), + ..Default::default() + }; if let Some(wasm_iter) = wasm .get("children") - .map(|children| children.as_array()) - .flatten() + .and_then(|children| children.as_array()) .map(|children| children.iter()) { layer.extend(wasm_compare_list(source, emacs_list_iter, wasm_iter)?)?; @@ -375,10 +380,10 @@ fn wasm_key_to_emacs_key(wasm_key: WK) -> String { format!(":{key}", key = wasm_key) } -fn compare_quoted_string<'e, 's, 'w>( +fn compare_quoted_string<'s>( _source: &'s str, - emacs: &'e str, - wasm: &'w String, + emacs: &str, + wasm: &String, ) -> Result, Box> { let mut result = WasmDiffResult::default(); let emacs_text = unquote(emacs)?; @@ -448,10 +453,8 @@ where { let emacs_length = emacs.len(); let wasm_length = wasm.len(); - if emacs_length == 1 && wasm_length == 0 { - if emacs.all(|t| matches!(t.as_atom(), Ok(r#""""#))) { - return Ok(WasmDiffResult::default()); - } + if emacs_length == 1 && wasm_length == 0 && emacs.all(|t| matches!(t.as_atom(), Ok(r#""""#))) { + return Ok(WasmDiffResult::default()); } if emacs_length != wasm_length { return Ok(WasmDiffResult { @@ -479,10 +482,10 @@ where }) } -fn compare_optional_pair<'e, 's, 'w>( +fn compare_optional_pair<'s>( source: &'s str, - emacs: &'e Vec>, - wasm: &'w serde_json::Map, + emacs: &Vec>, + wasm: &serde_json::Map, ) -> Result, Box> { let mut result = WasmDiffResult::default(); let wasm_optval = wasm @@ -540,10 +543,10 @@ fn compare_optional_pair<'e, 's, 'w>( Ok(result) } -fn compare_object_tree<'e, 's, 'w>( +fn compare_object_tree<'s>( source: &'s str, - emacs: &'e Vec>, - wasm: &'w serde_json::Map, + emacs: &[Token<'s>], + wasm: &serde_json::Map, ) -> Result, Box> { let mut result = WasmDiffResult::default(); let wasm_attributes = wasm @@ -657,10 +660,10 @@ fn compare_object_tree<'e, 's, 'w>( Ok(result) } -fn compare_number_lines<'e, 's, 'w>( +fn compare_number_lines<'s>( _source: &'s str, - emacs: &'e Vec>, - wasm: &'w serde_json::Map, + emacs: &[Token<'s>], + wasm: &serde_json::Map, ) -> Result, Box> { let mut result = WasmDiffResult::default(); let mut emacs_iter = emacs.iter(); @@ -669,8 +672,7 @@ fn compare_number_lines<'e, 's, 'w>( .ok_or("Emacs number lines should have 3 children.")? .as_atom()?; let emacs_number: i64 = emacs_iter - .skip(1) - .next() + .nth(1) .ok_or("Emacs number lines should have 3 children.")? .as_atom()? .parse()?; @@ -744,10 +746,10 @@ fn compare_number_lines<'e, 's, 'w>( Ok(result) } -fn compare_string_set<'e, 's, 'w>( +fn compare_string_set<'s>( _source: &'s str, - emacs: &'e Vec>, - wasm: &'w serde_json::Map, + emacs: &[Token<'s>], + wasm: &serde_json::Map, ) -> Result, Box> { let mut result = WasmDiffResult::default(); let wasm_list = wasm @@ -764,7 +766,7 @@ fn compare_string_set<'e, 's, 'w>( .map(|v| v.as_atom()) .collect::, Box>>()? .into_iter() - .map(|s| unquote(s)) + .map(unquote) .collect::, Box>>()?; let emacs_strings = emacs_strings .iter() @@ -788,7 +790,7 @@ fn compare_string_set<'e, 's, 'w>( Ok(result) } -fn is_plain_text<'e, 's, 'w>(wasm: &'w serde_json::Map) -> bool { +fn is_plain_text(wasm: &serde_json::Map) -> bool { if let Some(serde_json::Value::String(node_type)) = wasm.get("ast-node") { node_type == "plain-text" } else { @@ -796,13 +798,15 @@ fn is_plain_text<'e, 's, 'w>(wasm: &'w serde_json::Map( +fn compare_plain_text<'s>( source: &'s str, - emacs: &'e TextWithProperties<'s>, - wasm: &'w serde_json::Map, + emacs: &TextWithProperties<'s>, + wasm: &serde_json::Map, ) -> Result, Box> { - let mut result = WasmDiffResult::default(); - result.name = "plain-text".into(); + let mut result = WasmDiffResult::<'_> { + name: "plain-text".into(), + ..Default::default() + }; if !is_plain_text(wasm) { result.status.push(WasmDiffStatus::Bad( format!( diff --git a/src/wasm_test/diff.rs b/src/wasm_test/diff.rs index f6b1dfa..815e115 100644 --- a/src/wasm_test/diff.rs +++ b/src/wasm_test/diff.rs @@ -12,6 +12,7 @@ pub struct WasmDiffResult<'s> { #[derive(Debug)] pub(crate) enum WasmDiffStatus { + #[allow(dead_code)] Good, Bad(Cow<'static, str>), } @@ -50,7 +51,7 @@ impl<'s> WasmDiffResult<'s> { fn print_indented( &self, indentation: usize, - original_document: &str, + _original_document: &str, ) -> Result<(), Box> { let status_text = { if self.is_self_bad() { @@ -90,7 +91,7 @@ impl<'s> WasmDiffResult<'s> { ); for child in self.children.iter() { - child.print_indented(indentation + 1, original_document)?; + child.print_indented(indentation + 1, _original_document)?; } Ok(()) diff --git a/src/wasm_test/macros.rs b/src/wasm_test/macros.rs deleted file mode 100644 index 5490911..0000000 --- a/src/wasm_test/macros.rs +++ /dev/null @@ -1,143 +0,0 @@ -macro_rules! wasm_compare { - ($source:expr, $emacs:expr, $wasm:expr, $(($emacs_field:expr, $wasm_value_getter:expr, $compare_fn: expr)),*) => {{ - let mut result = WasmDiffResult::default(); - let emacs_list = $emacs.as_list()?; - let mut emacs_list_iter = emacs_list.iter(); - let emacs_name = emacs_list_iter - .next() - .ok_or("Should have an attributes child.")? - .as_atom()?; - result.name = emacs_name.into(); - let emacs_attributes_map = emacs_list_iter - .next() - .ok_or("Should have an attributes child.")? - .as_map()?; - let mut emacs_keys: std::collections::BTreeSet<&str> = - emacs_attributes_map.keys().map(|s| *s).collect(); - - // Mark :standard-properties as seen because it will be handled separately. - if emacs_keys.contains(":standard-properties") { - emacs_keys.remove(":standard-properties"); - } else { - result.status.push(WasmDiffStatus::Bad( - "Emacs node lacked :standard-properties field.".into(), - )); - } - - { - // Compare name. - let wasm_name = $wasm.get_elisp_name(); - - if emacs_name != wasm_name { - result.status.push(WasmDiffStatus::Bad( - format!( - "AST node name mismatch. Emacs=({emacs}) Wasm=({wasm}).", - emacs = emacs_name, - wasm = wasm_name, - ) - .into(), - )); - } - } - - { - // Compare standard properties. - result.extend(wasm_compare_standard_properties($source, $emacs, &$wasm.standard_properties)?)?; - } - - { - // Compare additional properties. - let additional_property_names: Vec = $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) => {} - - } - } - - result.extend(wasm_compare_additional_properties($source, $emacs, &$wasm.additional_properties)?)?; - } - - { - // Compare children. - result.extend(wasm_compare_list( - $source, - emacs_list_iter, - $wasm.children.iter(), - )?)?; - } - - { - // Check for properties that are missing from the elisp node. - $( - match $emacs_field { - 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) => {} - } - )* - } - - { - // Check for elisp properties that were not compared. - if !emacs_keys.is_empty() { - let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect(); - let unexpected_keys = unexpected_keys.join(", "); - result.status.push(WasmDiffStatus::Bad( - format!( - "Emacs node had extra field(s): ({field_names}).", - field_names = unexpected_keys, - ) - .into(), - )); - } - - } - - { - // Compare properties. - $( - let emacs_name = match $emacs_field { - EmacsField::Required(name) => { - name - }, - EmacsField::Optional(name) => { - name - }, - }; - result.extend($compare_fn($source, $emacs, $wasm, emacs_name, $wasm_value_getter)?)?; - )* - } - - result - }}; -} - diff --git a/src/wasm_test/mod.rs b/src/wasm_test/mod.rs index 038b592..f243278 100644 --- a/src/wasm_test/mod.rs +++ b/src/wasm_test/mod.rs @@ -1,6 +1,5 @@ mod compare; mod diff; -mod macros; mod runner; pub use runner::wasm_run_anonymous_compare;