Compare commits

..

No commits in common. "7f3f5fb889abc848e1674d945b16fc29999c1e4f" and "c46a935cfcb7df7ad62635fc8f1d72d82478003b" have entirely different histories.

5 changed files with 21 additions and 115 deletions

View File

@ -7,20 +7,12 @@ use super::to_wasm::ToWasm;
use super::AdditionalProperties;
use crate::compare::ElispFact;
use crate::types::BabelCall;
use crate::types::GetAffiliatedKeywords;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
pub struct WasmBabelCall {
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
pub(crate) call: Option<String>,
#[serde(rename = "inside-header")]
pub(crate) inside_header: Option<String>,
pub(crate) arguments: Option<String>,
#[serde(rename = "end-header")]
pub(crate) end_header: Option<String>,
pub(crate) value: String,
}
to_wasm!(
@ -29,21 +21,12 @@ to_wasm!(
original,
wasm_context,
{ WasmAstNode::BabelCall(original) },
{ "babel-call".into() },
{ "TODO".into() },
{
let additional_properties = original
.get_affiliated_keywords()
.to_wasm(wasm_context.clone())?;
Ok((
Vec::new(),
WasmBabelCall {
additional_properties,
call: original.call.map(|s| s.to_owned()),
inside_header: original.inside_header.map(|s| s.to_owned()),
arguments: original.arguments.map(|s| s.to_owned()),
end_header: original.end_header.map(|s| s.to_owned()),
value: original.value.to_owned(),
additional_properties: AdditionalProperties::default(),
},
))
}

View File

@ -1,5 +1,3 @@
use std::collections::BTreeSet;
use serde::Deserialize;
use serde::Serialize;
@ -8,7 +6,6 @@ use super::macros::to_wasm;
use super::to_wasm::ToWasm;
use super::AdditionalProperties;
use crate::compare::ElispFact;
use crate::types::GetAffiliatedKeywords;
use crate::types::Table;
use crate::wasm::to_wasm::ToWasmStandardProperties;
@ -16,18 +13,6 @@ use crate::wasm::to_wasm::ToWasmStandardProperties;
pub struct WasmTable {
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
#[serde(rename = "tblfm")]
pub(crate) formulas: Option<WasmStringSet>,
#[serde(rename = "type")]
pub(crate) table_type: String,
pub(crate) value: Option<String>, // Always None
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "string-set")]
#[serde(rename = "string-set")]
struct WasmStringSet {
value: BTreeSet<String>,
}
to_wasm!(
@ -36,12 +21,8 @@ to_wasm!(
original,
wasm_context,
{ WasmAstNode::Table(original) },
{ "table".into() },
{ "TODO".into() },
{
let additional_properties = original
.get_affiliated_keywords()
.to_wasm(wasm_context.clone())?;
let children = original
.children
.iter()
@ -55,20 +36,7 @@ to_wasm!(
Ok((
children,
WasmTable {
additional_properties,
formulas: if original.formulas.is_empty() {
None
} else {
Some(WasmStringSet {
value: original
.formulas
.iter()
.map(|kw| kw.value.to_owned())
.collect(),
})
},
table_type: "org".to_owned(),
value: None,
additional_properties: AdditionalProperties::default(),
},
))
}

View File

@ -4,12 +4,16 @@ use serde::Serialize;
use super::ast_node::WasmAstNode;
use super::macros::to_wasm;
use super::to_wasm::ToWasm;
use super::AdditionalProperties;
use crate::compare::ElispFact;
use crate::types::TableCell;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
pub struct WasmTableCell {}
pub struct WasmTableCell {
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
}
to_wasm!(
WasmTableCell,
@ -17,7 +21,7 @@ to_wasm!(
original,
wasm_context,
{ WasmAstNode::TableCell(original) },
{ "table-cell".into() },
{ "TODO".into() },
{
let children = original
.children
@ -29,6 +33,11 @@ to_wasm!(
})
.collect::<Result<Vec<_>, _>>()?;
Ok((children, WasmTableCell {}))
Ok((
children,
WasmTableCell {
additional_properties: AdditionalProperties::default(),
},
))
}
);

View File

@ -4,15 +4,15 @@ use serde::Serialize;
use super::ast_node::WasmAstNode;
use super::macros::to_wasm;
use super::to_wasm::ToWasm;
use super::AdditionalProperties;
use crate::compare::ElispFact;
use crate::types::TableRow;
use crate::types::TableRowType;
use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)]
pub struct WasmTableRow {
#[serde(rename = "type")]
pub(crate) row_type: String,
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
}
to_wasm!(
@ -21,7 +21,7 @@ to_wasm!(
original,
wasm_context,
{ WasmAstNode::TableRow(original) },
{ "table-row".into() },
{ "TODO".into() },
{
let children = original
.children
@ -36,11 +36,7 @@ to_wasm!(
Ok((
children,
WasmTableRow {
row_type: match original.get_type() {
TableRowType::Standard => "standard",
TableRowType::Rule => "rule",
}
.to_owned(),
additional_properties: AdditionalProperties::default(),
},
))
}

View File

@ -1,6 +1,4 @@
use std::borrow::Borrow;
use std::borrow::Cow;
use std::collections::BTreeSet;
use std::collections::HashMap;
use super::diff::WasmDiffResult;
@ -60,10 +58,6 @@ fn compare_json_value<'b, 's>(
// We hit an object tree additional property.
compare_number_lines(source, el, wasm)
}
(serde_json::Value::Object(wasm), Token::List(el)) if wasm.contains_key("string-set") => {
// We hit an object tree additional property.
compare_string_set(source, el, wasm)
}
(serde_json::Value::Object(w), Token::TextWithProperties(e)) if is_plain_text(w) => {
compare_plain_text(source, e, w)
}
@ -725,50 +719,6 @@ fn compare_number_lines<'e, 's, 'w>(
Ok(result)
}
fn compare_string_set<'e, 's, 'w>(
source: &'s str,
emacs: &'e Vec<Token<'s>>,
wasm: &'w serde_json::Map<String, serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default();
let wasm_list = wasm
.get("value")
.ok_or(r#"Wasm string set should have a "value" attribute."#)?
.as_array()
.ok_or(r#"Wasm string set "value" attribute should be a list."#)?;
let wasm_strings = wasm_list
.iter()
.map(|v| v.as_str().ok_or("Non-string in wasm string set."))
.collect::<Result<BTreeSet<_>, &'static str>>()?;
let emacs_strings = emacs
.iter()
.map(|v| v.as_atom())
.collect::<Result<Vec<_>, Box<dyn std::error::Error>>>()?
.into_iter()
.map(|s| unquote(s))
.collect::<Result<Vec<_>, Box<dyn std::error::Error>>>()?;
let emacs_strings = emacs_strings
.iter()
.map(|s| s.borrow())
.collect::<BTreeSet<&str>>();
let mismatched: Vec<_> = emacs_strings
.symmetric_difference(&wasm_strings)
.copied()
.collect();
if !mismatched.is_empty() {
result.status.push(WasmDiffStatus::Bad(
format!(
"String set mismatch. MismatchedValues=({values:?}).",
values = mismatched.join(", ")
)
.into(),
));
}
Ok(result)
}
fn is_plain_text<'e, 's, 'w>(wasm: &'w serde_json::Map<String, serde_json::Value>) -> bool {
if let Some(serde_json::Value::String(node_type)) = wasm.get("ast-node") {
node_type == "plain-text"