Compare commits
4 Commits
c46a935cfc
...
7f3f5fb889
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7f3f5fb889 | ||
![]() |
e0fbf17226 | ||
![]() |
4e18cbafba | ||
![]() |
46c36d7f3e |
@ -7,12 +7,20 @@ use super::to_wasm::ToWasm;
|
|||||||
use super::AdditionalProperties;
|
use super::AdditionalProperties;
|
||||||
use crate::compare::ElispFact;
|
use crate::compare::ElispFact;
|
||||||
use crate::types::BabelCall;
|
use crate::types::BabelCall;
|
||||||
|
use crate::types::GetAffiliatedKeywords;
|
||||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct WasmBabelCall {
|
pub struct WasmBabelCall {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub(crate) additional_properties: AdditionalProperties,
|
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!(
|
to_wasm!(
|
||||||
@ -21,12 +29,21 @@ to_wasm!(
|
|||||||
original,
|
original,
|
||||||
wasm_context,
|
wasm_context,
|
||||||
{ WasmAstNode::BabelCall(original) },
|
{ WasmAstNode::BabelCall(original) },
|
||||||
{ "TODO".into() },
|
{ "babel-call".into() },
|
||||||
{
|
{
|
||||||
|
let additional_properties = original
|
||||||
|
.get_affiliated_keywords()
|
||||||
|
.to_wasm(wasm_context.clone())?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
WasmBabelCall {
|
WasmBabelCall {
|
||||||
additional_properties: AdditionalProperties::default(),
|
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(),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
@ -6,6 +8,7 @@ use super::macros::to_wasm;
|
|||||||
use super::to_wasm::ToWasm;
|
use super::to_wasm::ToWasm;
|
||||||
use super::AdditionalProperties;
|
use super::AdditionalProperties;
|
||||||
use crate::compare::ElispFact;
|
use crate::compare::ElispFact;
|
||||||
|
use crate::types::GetAffiliatedKeywords;
|
||||||
use crate::types::Table;
|
use crate::types::Table;
|
||||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
|
||||||
@ -13,6 +16,18 @@ use crate::wasm::to_wasm::ToWasmStandardProperties;
|
|||||||
pub struct WasmTable {
|
pub struct WasmTable {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub(crate) additional_properties: AdditionalProperties,
|
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!(
|
to_wasm!(
|
||||||
@ -21,8 +36,12 @@ to_wasm!(
|
|||||||
original,
|
original,
|
||||||
wasm_context,
|
wasm_context,
|
||||||
{ WasmAstNode::Table(original) },
|
{ WasmAstNode::Table(original) },
|
||||||
{ "TODO".into() },
|
{ "table".into() },
|
||||||
{
|
{
|
||||||
|
let additional_properties = original
|
||||||
|
.get_affiliated_keywords()
|
||||||
|
.to_wasm(wasm_context.clone())?;
|
||||||
|
|
||||||
let children = original
|
let children = original
|
||||||
.children
|
.children
|
||||||
.iter()
|
.iter()
|
||||||
@ -36,7 +55,20 @@ to_wasm!(
|
|||||||
Ok((
|
Ok((
|
||||||
children,
|
children,
|
||||||
WasmTable {
|
WasmTable {
|
||||||
additional_properties: AdditionalProperties::default(),
|
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,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -4,16 +4,12 @@ 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 super::AdditionalProperties;
|
|
||||||
use crate::compare::ElispFact;
|
use crate::compare::ElispFact;
|
||||||
use crate::types::TableCell;
|
use crate::types::TableCell;
|
||||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct WasmTableCell {
|
pub struct WasmTableCell {}
|
||||||
#[serde(flatten)]
|
|
||||||
pub(crate) additional_properties: AdditionalProperties,
|
|
||||||
}
|
|
||||||
|
|
||||||
to_wasm!(
|
to_wasm!(
|
||||||
WasmTableCell,
|
WasmTableCell,
|
||||||
@ -21,7 +17,7 @@ to_wasm!(
|
|||||||
original,
|
original,
|
||||||
wasm_context,
|
wasm_context,
|
||||||
{ WasmAstNode::TableCell(original) },
|
{ WasmAstNode::TableCell(original) },
|
||||||
{ "TODO".into() },
|
{ "table-cell".into() },
|
||||||
{
|
{
|
||||||
let children = original
|
let children = original
|
||||||
.children
|
.children
|
||||||
@ -33,11 +29,6 @@ to_wasm!(
|
|||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
Ok((
|
Ok((children, WasmTableCell {}))
|
||||||
children,
|
|
||||||
WasmTableCell {
|
|
||||||
additional_properties: AdditionalProperties::default(),
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -4,15 +4,15 @@ 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 super::AdditionalProperties;
|
|
||||||
use crate::compare::ElispFact;
|
use crate::compare::ElispFact;
|
||||||
use crate::types::TableRow;
|
use crate::types::TableRow;
|
||||||
|
use crate::types::TableRowType;
|
||||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct WasmTableRow {
|
pub struct WasmTableRow {
|
||||||
#[serde(flatten)]
|
#[serde(rename = "type")]
|
||||||
pub(crate) additional_properties: AdditionalProperties,
|
pub(crate) row_type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
to_wasm!(
|
to_wasm!(
|
||||||
@ -21,7 +21,7 @@ to_wasm!(
|
|||||||
original,
|
original,
|
||||||
wasm_context,
|
wasm_context,
|
||||||
{ WasmAstNode::TableRow(original) },
|
{ WasmAstNode::TableRow(original) },
|
||||||
{ "TODO".into() },
|
{ "table-row".into() },
|
||||||
{
|
{
|
||||||
let children = original
|
let children = original
|
||||||
.children
|
.children
|
||||||
@ -36,7 +36,11 @@ to_wasm!(
|
|||||||
Ok((
|
Ok((
|
||||||
children,
|
children,
|
||||||
WasmTableRow {
|
WasmTableRow {
|
||||||
additional_properties: AdditionalProperties::default(),
|
row_type: match original.get_type() {
|
||||||
|
TableRowType::Standard => "standard",
|
||||||
|
TableRowType::Rule => "rule",
|
||||||
|
}
|
||||||
|
.to_owned(),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
use std::borrow::Borrow;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::collections::BTreeSet;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::diff::WasmDiffResult;
|
use super::diff::WasmDiffResult;
|
||||||
@ -58,6 +60,10 @@ fn compare_json_value<'b, 's>(
|
|||||||
// We hit an object tree additional property.
|
// We hit an object tree additional property.
|
||||||
compare_number_lines(source, el, wasm)
|
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) => {
|
(serde_json::Value::Object(w), Token::TextWithProperties(e)) if is_plain_text(w) => {
|
||||||
compare_plain_text(source, e, w)
|
compare_plain_text(source, e, w)
|
||||||
}
|
}
|
||||||
@ -719,6 +725,50 @@ fn compare_number_lines<'e, 's, 'w>(
|
|||||||
Ok(result)
|
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 {
|
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") {
|
if let Some(serde_json::Value::String(node_type)) = wasm.get("ast-node") {
|
||||||
node_type == "plain-text"
|
node_type == "plain-text"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user