Fix clippy.
All checks were successful
clippy Build clippy has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-build Build rust-build has succeeded
rust-test Build rust-test has succeeded

This commit is contained in:
Tom Alexander 2023-12-30 22:42:14 -05:00
parent 6b62176fd0
commit f4e0dddd9d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
18 changed files with 80 additions and 231 deletions

View File

@ -127,7 +127,7 @@ spec:
- name: command - name: command
value: ["cargo", "fix"] value: ["cargo", "fix"]
- name: args - name: args
value: ["--allow-dirty"] value: ["--all-targets", "--all-features", "--allow-dirty"]
- name: docker-image - name: docker-image
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)" value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
- name: commit-changes - name: commit-changes

View File

@ -30,7 +30,7 @@ endif
# NOTE: This target will write to folders underneath the git-root # NOTE: This target will write to folders underneath the git-root
.PHONY: run .PHONY: run
run: build 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 .PHONY: shell
shell: build shell: build

View File

@ -11,13 +11,9 @@ pub use compare::run_compare_on_file;
pub use compare::run_compare_on_file_with_settings; pub use compare::run_compare_on_file_with_settings;
pub use compare::silent_anonymous_compare; pub use compare::silent_anonymous_compare;
pub use compare::silent_compare_on_file; pub use compare::silent_compare_on_file;
pub use sexp::sexp; pub use sexp::sexp;
pub(crate) use sexp::unquote; pub(crate) use sexp::unquote;
pub(crate) use sexp::TextWithProperties; pub(crate) use sexp::TextWithProperties;
pub use sexp::Token; pub use sexp::Token;
pub(crate) use util::maybe_token_to_usize; pub(crate) use util::maybe_token_to_usize;
pub(crate) use util::EmacsStandardProperties; pub(crate) use util::EmacsStandardProperties;

View File

@ -1,4 +1,3 @@
use std::collections::HashMap; use std::collections::HashMap;
use serde::Deserialize; use serde::Deserialize;
@ -31,12 +30,6 @@ pub struct AdditionalProperties {
pub(crate) properties: HashMap<String, AdditionalPropertyValue>, pub(crate) properties: HashMap<String, AdditionalPropertyValue>,
} }
impl AdditionalProperties {
pub(crate) fn get_elisp_names<'c>(&'c self) -> impl Iterator<Item = String> + 'c {
self.properties.keys().map(move |key| format!(":{}", key))
}
}
to_wasm!( to_wasm!(
AdditionalProperties, AdditionalProperties,
AffiliatedKeywords<'s>, AffiliatedKeywords<'s>,

View File

@ -8,8 +8,8 @@ use super::additional_property::AdditionalPropertyValue;
use super::ast_node::WasmAstNode; use super::ast_node::WasmAstNode;
use super::macros::to_wasm; use super::macros::to_wasm;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use crate::util::elisp_fact::ElispFact;
use crate::types::Document; use crate::types::Document;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -29,7 +29,7 @@ to_wasm!(
{ WasmAstNode::Document(original) }, { WasmAstNode::Document(original) },
{ "org-data".into() }, { "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 path = original.path.clone();
let mut additional_properties = AdditionalProperties::default(); let mut additional_properties = AdditionalProperties::default();

View File

@ -8,12 +8,12 @@ use super::src_block::WasmNumberLinesWrapper;
use super::src_block::WasmRetainLabels; use super::src_block::WasmRetainLabels;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use super::AdditionalProperties; use super::AdditionalProperties;
use crate::util::elisp_fact::ElispFact;
use crate::types::CharOffsetInLine; use crate::types::CharOffsetInLine;
use crate::types::ExampleBlock; use crate::types::ExampleBlock;
use crate::types::GetAffiliatedKeywords; use crate::types::GetAffiliatedKeywords;
use crate::types::RetainLabels; use crate::types::RetainLabels;
use crate::types::SwitchNumberLines; use crate::types::SwitchNumberLines;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -58,7 +58,7 @@ to_wasm!(
inner: WasmNumberLines::New(n), inner: WasmNumberLines::New(n),
}), }),
Some(SwitchNumberLines::Continued(n)) => Some(WasmNumberLinesWrapper { Some(SwitchNumberLines::Continued(n)) => Some(WasmNumberLinesWrapper {
inner: WasmNumberLines::continued(n), inner: WasmNumberLines::Continued(n),
}), }),
}, },
preserve_indent: original.preserve_indent, preserve_indent: original.preserve_indent,

View File

@ -6,11 +6,11 @@ use super::macros::to_wasm;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use super::AdditionalProperties; use super::AdditionalProperties;
use super::AdditionalPropertyValue; use super::AdditionalPropertyValue;
use crate::util::elisp_fact::ElispFact;
use crate::types::Heading; use crate::types::Heading;
use crate::types::HeadlineLevel; use crate::types::HeadlineLevel;
use crate::types::PriorityCookie; use crate::types::PriorityCookie;
use crate::types::TodoKeywordType; use crate::types::TodoKeywordType;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -112,7 +112,7 @@ to_wasm!(
.map(Into::<WasmAstNode>::into) .map(Into::<WasmAstNode>::into)
}) })
.map_or(Ok(None), |r| r.map(Some))? .map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)), .map(Box::new),
deadline: original deadline: original
.deadline .deadline
.as_ref() .as_ref()
@ -122,7 +122,7 @@ to_wasm!(
.map(Into::<WasmAstNode>::into) .map(Into::<WasmAstNode>::into)
}) })
.map_or(Ok(None), |r| r.map(Some))? .map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)), .map(Box::new),
closed: original closed: original
.closed .closed
.as_ref() .as_ref()
@ -132,7 +132,7 @@ to_wasm!(
.map(Into::<WasmAstNode>::into) .map(Into::<WasmAstNode>::into)
}) })
.map_or(Ok(None), |r| r.map(Some))? .map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)), .map(Box::new),
pre_blank: Noop {}, pre_blank: Noop {},
}, },
)) ))

View File

@ -23,6 +23,7 @@ macro_rules! to_wasm {
&self, &self,
$wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>, $wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>,
) -> Result<Self::Output, crate::error::CustomError> { ) -> Result<Self::Output, crate::error::CustomError> {
#[allow(unused_variables)]
let $original = self; let $original = self;
let standard_properties = let standard_properties =
self.to_wasm_standard_properties($wasm_context.clone())?; self.to_wasm_standard_properties($wasm_context.clone())?;
@ -38,9 +39,8 @@ macro_rules! to_wasm {
} }
} }
impl Into<WasmAstNode> for crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct> { impl From<crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct>> for WasmAstNode {
fn into(self) -> WasmAstNode { fn from($original: crate::wasm::ast_node::WasmAstNodeWrapper<$ostruct>) -> Self {
let $original = self;
let ret = $toastnodebody; let ret = $toastnodebody;
ret ret
} }
@ -48,7 +48,6 @@ macro_rules! to_wasm {
impl<'s> crate::util::elisp_fact::ElispFact<'s> for $ostruct { impl<'s> crate::util::elisp_fact::ElispFact<'s> for $ostruct {
fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> { fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> {
let $original = self;
let ret = $elispnamebody; let ret = $elispnamebody;
ret ret
} }

View File

@ -4,11 +4,11 @@ use serde::Serialize;
use super::ast_node::WasmAstNode; use super::ast_node::WasmAstNode;
use super::macros::to_wasm; use super::macros::to_wasm;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use crate::util::elisp_fact::ElispFact;
use crate::types::CheckboxType; use crate::types::CheckboxType;
use crate::types::PlainListItem; use crate::types::PlainListItem;
use crate::types::PlainListItemCounter; use crate::types::PlainListItemCounter;
use crate::types::PlainListItemPreBlank; use crate::types::PlainListItemPreBlank;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -52,7 +52,7 @@ to_wasm!(
}) })
.collect::<Result<Vec<_>, _>>()?, .collect::<Result<Vec<_>, _>>()?,
bullet: original.bullet.to_owned(), bullet: original.bullet.to_owned(),
counter: original.counter.clone(), counter: original.counter,
checkbox: original.checkbox.as_ref().map(|(checkbox_type, _)| { checkbox: original.checkbox.as_ref().map(|(checkbox_type, _)| {
match checkbox_type { match checkbox_type {
CheckboxType::On => "on", CheckboxType::On => "on",

View File

@ -4,8 +4,8 @@ use serde::Serialize;
use super::ast_node::WasmAstNode; use super::ast_node::WasmAstNode;
use super::macros::to_wasm; use super::macros::to_wasm;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use crate::util::elisp_fact::ElispFact;
use crate::types::PlainText; use crate::types::PlainText;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

View File

@ -4,8 +4,8 @@ use serde::Serialize;
use super::ast_node::WasmAstNode; use super::ast_node::WasmAstNode;
use super::macros::to_wasm; use super::macros::to_wasm;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use crate::util::elisp_fact::ElispFact;
use crate::types::Planning; use crate::types::Planning;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -35,7 +35,7 @@ to_wasm!(
.map(Into::<WasmAstNode>::into) .map(Into::<WasmAstNode>::into)
}) })
.map_or(Ok(None), |r| r.map(Some))? .map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)), .map(Box::new),
deadline: original deadline: original
.deadline .deadline
.as_ref() .as_ref()
@ -45,7 +45,7 @@ to_wasm!(
.map(Into::<WasmAstNode>::into) .map(Into::<WasmAstNode>::into)
}) })
.map_or(Ok(None), |r| r.map(Some))? .map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)), .map(Box::new),
closed: original closed: original
.closed .closed
.as_ref() .as_ref()
@ -55,7 +55,7 @@ to_wasm!(
.map(Into::<WasmAstNode>::into) .map(Into::<WasmAstNode>::into)
}) })
.map_or(Ok(None), |r| r.map(Some))? .map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)), .map(Box::new),
}, },
)) ))
} }

View File

@ -5,13 +5,13 @@ use super::ast_node::WasmAstNode;
use super::macros::to_wasm; use super::macros::to_wasm;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use super::AdditionalProperties; use super::AdditionalProperties;
use crate::util::elisp_fact::ElispFact;
use crate::types::CharOffsetInLine; use crate::types::CharOffsetInLine;
use crate::types::GetAffiliatedKeywords; use crate::types::GetAffiliatedKeywords;
use crate::types::LineNumber; use crate::types::LineNumber;
use crate::types::RetainLabels; use crate::types::RetainLabels;
use crate::types::SrcBlock; use crate::types::SrcBlock;
use crate::types::SwitchNumberLines; use crate::types::SwitchNumberLines;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -46,7 +46,7 @@ pub(crate) enum WasmNumberLines {
#[serde(rename = "new")] #[serde(rename = "new")]
New(LineNumber), New(LineNumber),
#[serde(rename = "continued")] #[serde(rename = "continued")]
continued(LineNumber), Continued(LineNumber),
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -83,7 +83,7 @@ to_wasm!(
inner: WasmNumberLines::New(n), inner: WasmNumberLines::New(n),
}), }),
Some(SwitchNumberLines::Continued(n)) => Some(WasmNumberLinesWrapper { Some(SwitchNumberLines::Continued(n)) => Some(WasmNumberLinesWrapper {
inner: WasmNumberLines::continued(n), inner: WasmNumberLines::Continued(n),
}), }),
}, },
preserve_indent: original.preserve_indent, preserve_indent: original.preserve_indent,

View File

@ -7,9 +7,9 @@ use super::ast_node::WasmAstNode;
use super::macros::to_wasm; use super::macros::to_wasm;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use super::AdditionalProperties; use super::AdditionalProperties;
use crate::util::elisp_fact::ElispFact;
use crate::types::GetAffiliatedKeywords; use crate::types::GetAffiliatedKeywords;
use crate::types::Table; use crate::types::Table;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -26,7 +26,7 @@ pub struct WasmTable {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "string-set")] #[serde(tag = "string-set")]
#[serde(rename = "string-set")] #[serde(rename = "string-set")]
struct WasmStringSet { pub(crate) struct WasmStringSet {
value: BTreeSet<String>, value: BTreeSet<String>,
} }

View File

@ -5,9 +5,9 @@ use super::ast_node::WasmAstNode;
use super::macros::to_wasm; use super::macros::to_wasm;
use super::to_wasm::ToWasm; use super::to_wasm::ToWasm;
use super::AdditionalProperties; use super::AdditionalProperties;
use crate::util::elisp_fact::ElispFact;
use crate::types::GetAffiliatedKeywords; use crate::types::GetAffiliatedKeywords;
use crate::types::VerseBlock; use crate::types::VerseBlock;
use crate::util::elisp_fact::ElispFact;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

View File

@ -13,19 +13,19 @@ use crate::compare::Token;
use crate::wasm::WasmAstNodeWrapper; use crate::wasm::WasmAstNodeWrapper;
use crate::wasm::WasmDocument; use crate::wasm::WasmDocument;
pub fn wasm_compare_document<'e, 's, 'w>( pub fn wasm_compare_document<'s>(
source: &'s str, source: &'s str,
emacs: &'e Token<'s>, emacs: &Token<'s>,
wasm: &'w WasmAstNodeWrapper<WasmDocument>, wasm: &WasmAstNodeWrapper<WasmDocument>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let wasm_json = serde_json::to_string(&wasm)?; let wasm_json = serde_json::to_string(&wasm)?;
let wasm_json_parsed = serde_json::from_str(&wasm_json)?; let wasm_json_parsed = serde_json::from_str(&wasm_json)?;
compare_json_value(source, emacs, &wasm_json_parsed) compare_json_value(source, emacs, &wasm_json_parsed)
} }
fn compare_json_value<'b, 's>( fn compare_json_value<'s>(
source: &'s str, source: &'s str,
emacs: &'b Token<'s>, emacs: &Token<'s>,
wasm: &serde_json::Value, wasm: &serde_json::Value,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
// println!("XXXXXXXXXXXXXX compare_json_value XXXXXXXXXXXXXX"); // 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, source: &'s str,
emacs: Option<&'b Token<'s>>, emacs: Option<&Token<'s>>,
wasm: Option<&serde_json::Value>, wasm: Option<&serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
match (emacs, wasm) { 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, source: &'s str,
emacs: &'e Vec<Token<'s>>, emacs: &[Token<'s>],
wasm: &'w serde_json::Map<String, serde_json::Value>, wasm: &serde_json::Map<String, serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default(); let mut result = WasmDiffResult::default();
let mut emacs_list_iter = emacs.iter(); let mut emacs_list_iter = emacs.iter();
@ -277,11 +277,13 @@ fn compare_ast_node<'e, 's, 'w>(
{ {
// Compare attributes. // Compare attributes.
for attribute_name in wasm_attributes_map.keys() { for attribute_name in wasm_attributes_map.keys() {
let mut layer = WasmDiffResult::default(); let mut layer = WasmDiffResult::<'_> {
layer.name = Cow::Owned(attribute_name.clone()); name: Cow::Owned(attribute_name.clone()),
..Default::default()
};
let wasm_attribute_value = wasm_attributes_map.get(attribute_name); let wasm_attribute_value = wasm_attributes_map.get(attribute_name);
let emacs_key = wasm_key_to_emacs_key(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 = let inner_layer =
compare_optional_json_value(source, emacs_attribute_value, wasm_attribute_value)?; compare_optional_json_value(source, emacs_attribute_value, wasm_attribute_value)?;
if !inner_layer.name.is_empty() { if !inner_layer.name.is_empty() {
@ -295,8 +297,10 @@ fn compare_ast_node<'e, 's, 'w>(
{ {
// Compare standard-properties. // Compare standard-properties.
let mut layer = WasmDiffResult::default(); let mut layer = WasmDiffResult::<'_> {
layer.name = "standard-properties".into(); name: "standard-properties".into(),
..Default::default()
};
let emacs_standard_properties = wasm_get_emacs_standard_properties(&emacs_attributes_map)?; let emacs_standard_properties = wasm_get_emacs_standard_properties(&emacs_attributes_map)?;
let wasm_standard_properties = wasm let wasm_standard_properties = wasm
.get("standard-properties") .get("standard-properties")
@ -349,12 +353,13 @@ fn compare_ast_node<'e, 's, 'w>(
{ {
// Compare children. // Compare children.
let mut layer = WasmDiffResult::default(); let mut layer = WasmDiffResult::<'_> {
layer.name = "children".into(); name: "children".into(),
..Default::default()
};
if let Some(wasm_iter) = wasm if let Some(wasm_iter) = wasm
.get("children") .get("children")
.map(|children| children.as_array()) .and_then(|children| children.as_array())
.flatten()
.map(|children| children.iter()) .map(|children| children.iter())
{ {
layer.extend(wasm_compare_list(source, emacs_list_iter, wasm_iter)?)?; layer.extend(wasm_compare_list(source, emacs_list_iter, wasm_iter)?)?;
@ -375,10 +380,10 @@ fn wasm_key_to_emacs_key<WK: std::fmt::Display>(wasm_key: WK) -> String {
format!(":{key}", key = wasm_key) format!(":{key}", key = wasm_key)
} }
fn compare_quoted_string<'e, 's, 'w>( fn compare_quoted_string<'s>(
_source: &'s str, _source: &'s str,
emacs: &'e str, emacs: &str,
wasm: &'w String, wasm: &String,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default(); let mut result = WasmDiffResult::default();
let emacs_text = unquote(emacs)?; let emacs_text = unquote(emacs)?;
@ -448,10 +453,8 @@ where
{ {
let emacs_length = emacs.len(); let emacs_length = emacs.len();
let wasm_length = wasm.len(); let wasm_length = wasm.len();
if emacs_length == 1 && wasm_length == 0 { if emacs_length == 1 && wasm_length == 0 && emacs.all(|t| matches!(t.as_atom(), Ok(r#""""#))) {
if emacs.all(|t| matches!(t.as_atom(), Ok(r#""""#))) { return Ok(WasmDiffResult::default());
return Ok(WasmDiffResult::default());
}
} }
if emacs_length != wasm_length { if emacs_length != wasm_length {
return Ok(WasmDiffResult { return Ok(WasmDiffResult {
@ -479,10 +482,10 @@ where
}) })
} }
fn compare_optional_pair<'e, 's, 'w>( fn compare_optional_pair<'s>(
source: &'s str, source: &'s str,
emacs: &'e Vec<Token<'s>>, emacs: &Vec<Token<'s>>,
wasm: &'w serde_json::Map<String, serde_json::Value>, wasm: &serde_json::Map<String, serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default(); let mut result = WasmDiffResult::default();
let wasm_optval = wasm let wasm_optval = wasm
@ -540,10 +543,10 @@ fn compare_optional_pair<'e, 's, 'w>(
Ok(result) Ok(result)
} }
fn compare_object_tree<'e, 's, 'w>( fn compare_object_tree<'s>(
source: &'s str, source: &'s str,
emacs: &'e Vec<Token<'s>>, emacs: &[Token<'s>],
wasm: &'w serde_json::Map<String, serde_json::Value>, wasm: &serde_json::Map<String, serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default(); let mut result = WasmDiffResult::default();
let wasm_attributes = wasm let wasm_attributes = wasm
@ -657,10 +660,10 @@ fn compare_object_tree<'e, 's, 'w>(
Ok(result) Ok(result)
} }
fn compare_number_lines<'e, 's, 'w>( fn compare_number_lines<'s>(
_source: &'s str, _source: &'s str,
emacs: &'e Vec<Token<'s>>, emacs: &[Token<'s>],
wasm: &'w serde_json::Map<String, serde_json::Value>, wasm: &serde_json::Map<String, serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default(); let mut result = WasmDiffResult::default();
let mut emacs_iter = emacs.iter(); 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.")? .ok_or("Emacs number lines should have 3 children.")?
.as_atom()?; .as_atom()?;
let emacs_number: i64 = emacs_iter let emacs_number: i64 = emacs_iter
.skip(1) .nth(1)
.next()
.ok_or("Emacs number lines should have 3 children.")? .ok_or("Emacs number lines should have 3 children.")?
.as_atom()? .as_atom()?
.parse()?; .parse()?;
@ -744,10 +746,10 @@ fn compare_number_lines<'e, 's, 'w>(
Ok(result) Ok(result)
} }
fn compare_string_set<'e, 's, 'w>( fn compare_string_set<'s>(
_source: &'s str, _source: &'s str,
emacs: &'e Vec<Token<'s>>, emacs: &[Token<'s>],
wasm: &'w serde_json::Map<String, serde_json::Value>, wasm: &serde_json::Map<String, serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default(); let mut result = WasmDiffResult::default();
let wasm_list = wasm let wasm_list = wasm
@ -764,7 +766,7 @@ fn compare_string_set<'e, 's, 'w>(
.map(|v| v.as_atom()) .map(|v| v.as_atom())
.collect::<Result<Vec<_>, Box<dyn std::error::Error>>>()? .collect::<Result<Vec<_>, Box<dyn std::error::Error>>>()?
.into_iter() .into_iter()
.map(|s| unquote(s)) .map(unquote)
.collect::<Result<Vec<_>, Box<dyn std::error::Error>>>()?; .collect::<Result<Vec<_>, Box<dyn std::error::Error>>>()?;
let emacs_strings = emacs_strings let emacs_strings = emacs_strings
.iter() .iter()
@ -788,7 +790,7 @@ fn compare_string_set<'e, 's, 'w>(
Ok(result) Ok(result)
} }
fn is_plain_text<'e, 's, 'w>(wasm: &'w serde_json::Map<String, serde_json::Value>) -> bool { fn is_plain_text(wasm: &serde_json::Map<String, serde_json::Value>) -> bool {
if let Some(serde_json::Value::String(node_type)) = wasm.get("ast-node") { if let Some(serde_json::Value::String(node_type)) = wasm.get("ast-node") {
node_type == "plain-text" node_type == "plain-text"
} else { } else {
@ -796,13 +798,15 @@ fn is_plain_text<'e, 's, 'w>(wasm: &'w serde_json::Map<String, serde_json::Value
} }
} }
fn compare_plain_text<'e, 's, 'w>( fn compare_plain_text<'s>(
source: &'s str, source: &'s str,
emacs: &'e TextWithProperties<'s>, emacs: &TextWithProperties<'s>,
wasm: &'w serde_json::Map<String, serde_json::Value>, wasm: &serde_json::Map<String, serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> { ) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default(); let mut result = WasmDiffResult::<'_> {
result.name = "plain-text".into(); name: "plain-text".into(),
..Default::default()
};
if !is_plain_text(wasm) { if !is_plain_text(wasm) {
result.status.push(WasmDiffStatus::Bad( result.status.push(WasmDiffStatus::Bad(
format!( format!(

View File

@ -12,6 +12,7 @@ pub struct WasmDiffResult<'s> {
#[derive(Debug)] #[derive(Debug)]
pub(crate) enum WasmDiffStatus { pub(crate) enum WasmDiffStatus {
#[allow(dead_code)]
Good, Good,
Bad(Cow<'static, str>), Bad(Cow<'static, str>),
} }
@ -50,7 +51,7 @@ impl<'s> WasmDiffResult<'s> {
fn print_indented( fn print_indented(
&self, &self,
indentation: usize, indentation: usize,
original_document: &str, _original_document: &str,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
let status_text = { let status_text = {
if self.is_self_bad() { if self.is_self_bad() {
@ -90,7 +91,7 @@ impl<'s> WasmDiffResult<'s> {
); );
for child in self.children.iter() { for child in self.children.iter() {
child.print_indented(indentation + 1, original_document)?; child.print_indented(indentation + 1, _original_document)?;
} }
Ok(()) Ok(())

View File

@ -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<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) => {}
}
}
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
}};
}

View File

@ -1,6 +1,5 @@
mod compare; mod compare;
mod diff; mod diff;
mod macros;
mod runner; mod runner;
pub use runner::wasm_run_anonymous_compare; pub use runner::wasm_run_anonymous_compare;