Compare commits

...

8 Commits

Author SHA1 Message Date
Tom Alexander
a4a83d047d
Fix node name getting chopped off.
Some checks failed
clippy Build clippy has failed
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-build Build rust-build has failed
rust-test Build rust-test has failed
2023-12-29 21:33:17 -05:00
Tom Alexander
a4414369ce
Remove unnecessary additional properties in the already-implemented types. 2023-12-29 21:04:31 -05:00
Tom Alexander
83e4b72307
Implement timestamp. 2023-12-29 20:55:01 -05:00
Tom Alexander
34b3e4fa7b
Implement statistics cookie. 2023-12-29 20:26:12 -05:00
Tom Alexander
c0e879dc1e
Implement headline. 2023-12-29 20:26:11 -05:00
Tom Alexander
fa31b001f4
Implement fixed width area. 2023-12-29 19:21:35 -05:00
Tom Alexander
0897061ff6
Add wasm tests to the CI. 2023-12-29 19:07:07 -05:00
Tom Alexander
28a3e1bc7b
Implement bold. 2023-12-29 18:56:29 -05:00
14 changed files with 374 additions and 78 deletions

View File

@ -115,7 +115,7 @@ spec:
[ [
--no-default-features, --no-default-features,
--features, --features,
compare, "compare,wasm_test",
--no-fail-fast, --no-fail-fast,
--lib, --lib,
--test, --test,

View File

@ -63,6 +63,11 @@ dockertest:
> $(MAKE) -C docker/organic_test > $(MAKE) -C docker/organic_test
> docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test --no-default-features --features compare --no-fail-fast --lib --test test_loader -- --test-threads $(TESTJOBS) > docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test --no-default-features --features compare --no-fail-fast --lib --test test_loader -- --test-threads $(TESTJOBS)
.PHONY: dockerwasmtest
dockerwasmtest:
> $(MAKE) -C docker/organic_test
> docker run --init --rm -i -t --read-only -v "$$(readlink -f ./):/source:ro" --mount type=tmpfs,destination=/tmp --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test --no-default-features --features compare,wasm_test --no-fail-fast --lib --test test_loader autogen_wasm_ -- --test-threads $(TESTJOBS)
.PHONY: buildtest .PHONY: buildtest
buildtest: buildtest:
> cargo build --no-default-features > cargo build --no-default-features

View File

@ -332,19 +332,19 @@ pub type HourInner = u8;
pub type MinuteInner = u8; pub type MinuteInner = u8;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Year(YearInner); pub struct Year(pub YearInner);
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Month(MonthInner); pub struct Month(pub MonthInner);
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct DayOfMonth(DayOfMonthInner); pub struct DayOfMonth(pub DayOfMonthInner);
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Hour(HourInner); pub struct Hour(pub HourInner);
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Minute(MinuteInner); pub struct Minute(pub MinuteInner);
impl Year { impl Year {
// TODO: Make a real error type instead of a boxed any error. // TODO: Make a real error type instead of a boxed any error.

View File

@ -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::Bold; use crate::types::Bold;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct WasmBold { pub struct WasmBold {}
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
}
to_wasm!( to_wasm!(
WasmBold, WasmBold,
@ -21,7 +17,7 @@ to_wasm!(
original, original,
wasm_context, wasm_context,
{ WasmAstNode::Bold(original) }, { WasmAstNode::Bold(original) },
{ "TODO".into() }, { "bold".into() },
{ {
let children = original let children = original
.children .children
@ -33,11 +29,6 @@ to_wasm!(
}) })
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
Ok(( Ok((children, WasmBold {}))
children,
WasmBold {
additional_properties: AdditionalProperties::default(),
},
))
} }
); );

View File

@ -7,12 +7,14 @@ use super::to_wasm::ToWasm;
use super::AdditionalProperties; use super::AdditionalProperties;
use crate::compare::ElispFact; use crate::compare::ElispFact;
use crate::types::FixedWidthArea; use crate::types::FixedWidthArea;
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 WasmFixedWidthArea { pub struct WasmFixedWidthArea {
#[serde(flatten)] #[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties, pub(crate) additional_properties: AdditionalProperties,
pub(crate) value: String,
} }
to_wasm!( to_wasm!(
@ -21,12 +23,19 @@ to_wasm!(
original, original,
wasm_context, wasm_context,
{ WasmAstNode::FixedWidthArea(original) }, { WasmAstNode::FixedWidthArea(original) },
{ "TODO".into() }, { "fixed-width".into() },
{ {
let additional_properties = original
.get_affiliated_keywords()
.to_wasm(wasm_context.clone())?;
let value = original.get_value();
Ok(( Ok((
Vec::new(), Vec::new(),
WasmFixedWidthArea { WasmFixedWidthArea {
additional_properties: AdditionalProperties::default(), additional_properties,
value,
}, },
)) ))
} }

View File

@ -5,14 +5,39 @@ 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 super::AdditionalPropertyValue;
use crate::compare::ElispFact; use crate::compare::ElispFact;
use crate::types::Heading; use crate::types::Heading;
use crate::types::HeadlineLevel;
use crate::types::PriorityCookie;
use crate::types::TodoKeywordType;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct WasmHeadline { pub struct WasmHeadline {
#[serde(flatten)] #[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties, pub(crate) additional_properties: AdditionalProperties,
pub(crate) level: HeadlineLevel,
pub(crate) tags: Vec<String>,
#[serde(rename = "todo-keyword")]
pub(crate) todo_keyword: Option<String>,
#[serde(rename = "todo-type")]
pub(crate) todo_type: Option<String>,
pub(crate) title: Vec<WasmAstNode>,
pub(crate) priority: Option<PriorityCookie>,
#[serde(rename = "archivedp")]
pub(crate) is_archived: bool,
#[serde(rename = "commentedp")]
pub(crate) is_comment: bool,
#[serde(rename = "raw-value")]
pub(crate) raw_value: String,
#[serde(rename = "footnote-section-p")]
pub(crate) is_footnote_section: bool,
pub(crate) scheduled: Option<Box<WasmAstNode>>,
pub(crate) deadline: Option<Box<WasmAstNode>>,
pub(crate) closed: Option<Box<WasmAstNode>>,
#[serde(rename = "pre-blank")]
pub(crate) pre_blank: usize,
} }
to_wasm!( to_wasm!(
@ -21,8 +46,18 @@ to_wasm!(
original, original,
wasm_context, wasm_context,
{ WasmAstNode::Headline(original) }, { WasmAstNode::Headline(original) },
{ "TODO".into() }, { "headline".into() },
{ {
let mut additional_properties = AdditionalProperties::default();
for (name, val) in original.get_additional_properties().map(|node_property| {
(
node_property.property_name.to_uppercase(),
AdditionalPropertyValue::SingleString(node_property.value.unwrap_or("").to_owned()),
)
}) {
additional_properties.properties.insert(name, val);
}
let children = original let children = original
.children .children
.iter() .iter()
@ -36,7 +71,65 @@ to_wasm!(
Ok(( Ok((
children, children,
WasmHeadline { WasmHeadline {
additional_properties: AdditionalProperties::default(), additional_properties,
level: original.level,
tags: original.tags.iter().map(|tag| (*tag).to_owned()).collect(),
todo_keyword: original
.todo_keyword
.as_ref()
.map(|(_, keyword)| (*keyword).to_owned()),
todo_type: original
.todo_keyword
.as_ref()
.map(|(keyword, _)| match keyword {
TodoKeywordType::Done => "done".to_owned(),
TodoKeywordType::Todo => "todo".to_owned(),
}),
title: original
.title
.iter()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.collect::<Result<Vec<_>, _>>()?,
priority: original.priority_cookie,
is_archived: original.is_archived,
is_comment: original.is_comment,
raw_value: original.get_raw_value(),
is_footnote_section: original.is_footnote_section,
scheduled: original
.scheduled
.as_ref()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)),
deadline: original
.deadline
.as_ref()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)),
closed: original
.closed
.as_ref()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)),
pre_blank: 0, // TODO: Should this be a no-op?
}, },
)) ))
} }

View File

@ -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::PlainText; use crate::types::PlainText;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct WasmPlainText { pub struct WasmPlainText {}
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
}
to_wasm!( to_wasm!(
WasmPlainText, WasmPlainText,
@ -22,12 +18,5 @@ to_wasm!(
wasm_context, wasm_context,
{ WasmAstNode::PlainText(original) }, { WasmAstNode::PlainText(original) },
{ "plain-text".into() }, { "plain-text".into() },
{ { Ok((Vec::new(), WasmPlainText {},)) }
Ok((
Vec::new(),
WasmPlainText {
additional_properties: AdditionalProperties::default(),
},
))
}
); );

View File

@ -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::Planning; use crate::types::Planning;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct WasmPlanning { pub struct WasmPlanning {
#[serde(flatten)] pub(crate) scheduled: Option<Box<WasmAstNode>>,
pub(crate) additional_properties: AdditionalProperties, pub(crate) deadline: Option<Box<WasmAstNode>>,
pub(crate) closed: Option<Box<WasmAstNode>>,
} }
to_wasm!( to_wasm!(
@ -21,12 +21,41 @@ to_wasm!(
original, original,
wasm_context, wasm_context,
{ WasmAstNode::Planning(original) }, { WasmAstNode::Planning(original) },
{ "TODO".into() }, { "planning".into() },
{ {
Ok(( Ok((
Vec::new(), Vec::new(),
WasmPlanning { WasmPlanning {
additional_properties: AdditionalProperties::default(), scheduled: original
.scheduled
.as_ref()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)),
deadline: original
.deadline
.as_ref()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)),
closed: original
.closed
.as_ref()
.map(|child| {
child
.to_wasm(wasm_context.clone())
.map(Into::<WasmAstNode>::into)
})
.map_or(Ok(None), |r| r.map(Some))?
.map(|child| Box::new(child)),
}, },
)) ))
} }

View File

@ -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::Section; use crate::types::Section;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct WasmSection { pub struct WasmSection {}
#[serde(flatten)]
pub(crate) additional_properties: AdditionalProperties,
}
to_wasm!( to_wasm!(
WasmSection, WasmSection,
@ -33,11 +29,6 @@ to_wasm!(
}) })
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
Ok(( Ok((children, WasmSection {}))
children,
WasmSection {
additional_properties: AdditionalProperties::default(),
},
))
} }
); );

View File

@ -4,15 +4,13 @@ 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::StatisticsCookie; use crate::types::StatisticsCookie;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct WasmStatisticsCookie { pub struct WasmStatisticsCookie {
#[serde(flatten)] pub(crate) value: String,
pub(crate) additional_properties: AdditionalProperties,
} }
to_wasm!( to_wasm!(
@ -21,12 +19,12 @@ to_wasm!(
original, original,
wasm_context, wasm_context,
{ WasmAstNode::StatisticsCookie(original) }, { WasmAstNode::StatisticsCookie(original) },
{ "TODO".into() }, { "statistics-cookie".into() },
{ {
Ok(( Ok((
Vec::new(), Vec::new(),
WasmStatisticsCookie { WasmStatisticsCookie {
additional_properties: AdditionalProperties::default(), value: original.value.to_owned(),
}, },
)) ))
} }

View File

@ -4,15 +4,61 @@ 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::DayOfMonthInner;
use crate::types::HourInner;
use crate::types::MinuteInner;
use crate::types::MonthInner;
use crate::types::RepeaterType;
use crate::types::RepeaterWarningDelayValueType;
use crate::types::TimeUnit;
use crate::types::Timestamp; use crate::types::Timestamp;
use crate::types::TimestampRangeType;
use crate::types::TimestampType;
use crate::types::WarningDelayType;
use crate::types::YearInner;
use crate::wasm::to_wasm::ToWasmStandardProperties; use crate::wasm::to_wasm::ToWasmStandardProperties;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct WasmTimestamp { pub struct WasmTimestamp {
#[serde(flatten)] #[serde(rename = "type")]
pub(crate) additional_properties: AdditionalProperties, pub(crate) timestamp_type: String,
#[serde(rename = "range-type")]
pub(crate) range_type: Option<String>,
#[serde(rename = "raw-value")]
pub(crate) raw_value: String,
#[serde(rename = "year-start")]
pub(crate) year_start: Option<YearInner>,
#[serde(rename = "month-start")]
pub(crate) month_start: Option<MonthInner>,
#[serde(rename = "day-start")]
pub(crate) day_of_month_start: Option<DayOfMonthInner>,
#[serde(rename = "hour-start")]
pub(crate) hour_start: Option<HourInner>,
#[serde(rename = "minute-start")]
pub(crate) minute_start: Option<MinuteInner>,
#[serde(rename = "year-end")]
pub(crate) year_end: Option<YearInner>,
#[serde(rename = "month-end")]
pub(crate) month_end: Option<MonthInner>,
#[serde(rename = "day-end")]
pub(crate) day_of_month_end: Option<DayOfMonthInner>,
#[serde(rename = "hour-end")]
pub(crate) hour_end: Option<HourInner>,
#[serde(rename = "minute-end")]
pub(crate) minute_end: Option<MinuteInner>,
#[serde(rename = "repeater-type")]
pub(crate) repeater_type: Option<String>,
#[serde(rename = "repeater-unit")]
pub(crate) repeater_unit: Option<String>,
#[serde(rename = "repeater-value")]
pub(crate) repeater_value: Option<RepeaterWarningDelayValueType>,
#[serde(rename = "warning-type")]
pub(crate) warning_type: Option<String>,
#[serde(rename = "warning-unit")]
pub(crate) warning_unit: Option<String>,
#[serde(rename = "warning-value")]
pub(crate) warning_value: Option<RepeaterWarningDelayValueType>,
} }
to_wasm!( to_wasm!(
@ -21,12 +67,79 @@ to_wasm!(
original, original,
wasm_context, wasm_context,
{ WasmAstNode::Timestamp(original) }, { WasmAstNode::Timestamp(original) },
{ "TODO".into() }, { "timestamp".into() },
{ {
Ok(( Ok((
Vec::new(), Vec::new(),
WasmTimestamp { WasmTimestamp {
additional_properties: AdditionalProperties::default(), timestamp_type: match original.timestamp_type {
TimestampType::Diary => "diary",
TimestampType::Active => "active",
TimestampType::Inactive => "inactive",
TimestampType::ActiveRange => "active-range",
TimestampType::InactiveRange => "inactive-range",
}
.to_owned(),
range_type: match original.range_type {
TimestampRangeType::DateRange => Some("daterange".to_owned()),
TimestampRangeType::TimeRange => Some("timerange".to_owned()),
TimestampRangeType::None => None,
},
raw_value: original.get_raw_value().to_owned(),
year_start: original.start.as_ref().map(|date| date.get_year().0),
month_start: original.start.as_ref().map(|date| date.get_month().0),
day_of_month_start: original
.start
.as_ref()
.map(|date| date.get_day_of_month().0),
hour_start: original.start_time.as_ref().map(|time| time.get_hour().0),
minute_start: original.start_time.as_ref().map(|time| time.get_minute().0),
year_end: original.end.as_ref().map(|date| date.get_year().0),
month_end: original.end.as_ref().map(|date| date.get_month().0),
day_of_month_end: original.end.as_ref().map(|date| date.get_day_of_month().0),
hour_end: original.end_time.as_ref().map(|time| time.get_hour().0),
minute_end: original.end_time.as_ref().map(|time| time.get_minute().0),
repeater_type: original
.repeater
.as_ref()
.map(|repeater| match repeater.repeater_type {
RepeaterType::Cumulative => "cumulate",
RepeaterType::CatchUp => "catch-up",
RepeaterType::Restart => "restart",
})
.map(|text| text.to_owned()),
repeater_unit: original
.repeater
.as_ref()
.map(|repeater| match repeater.unit {
TimeUnit::Hour => "hour",
TimeUnit::Day => "day",
TimeUnit::Week => "week",
TimeUnit::Month => "month",
TimeUnit::Year => "year",
})
.map(|text| text.to_owned()),
repeater_value: original.repeater.as_ref().map(|repeater| repeater.value),
warning_type: original
.warning_delay
.as_ref()
.map(|warning| match warning.warning_delay_type {
WarningDelayType::All => "all",
WarningDelayType::First => "first",
})
.map(|text| text.to_owned()),
warning_unit: original
.warning_delay
.as_ref()
.map(|warning| match warning.unit {
TimeUnit::Hour => "hour",
TimeUnit::Day => "day",
TimeUnit::Week => "week",
TimeUnit::Month => "month",
TimeUnit::Year => "year",
})
.map(|text| text.to_owned()),
warning_value: original.warning_delay.as_ref().map(|warning| warning.value),
}, },
)) ))
} }

View File

@ -57,11 +57,37 @@ fn compare_json_value<'b, 's>(
(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)
} }
(serde_json::Value::Null, Token::Atom("nil")) => Ok(WasmDiffResult::default()),
(serde_json::Value::Bool(false), Token::Atom("nil")) => Ok(WasmDiffResult::default()),
(serde_json::Value::Bool(true), Token::Atom(e)) if (*e) != "nil" => {
Ok(WasmDiffResult::default())
}
(serde_json::Value::Bool(w), Token::Atom(e)) => {
let mut result = WasmDiffResult::default();
result.status.push(WasmDiffStatus::Bad(
format!(
"Value mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
emacs = e,
wasm = w,
)
.into(),
));
Ok(result)
}
(serde_json::Value::Number(w), Token::Atom(e)) if w.to_string().as_str() == (*e) => {
Ok(WasmDiffResult::default())
}
(serde_json::Value::Array(w), Token::Atom("nil")) if w.is_empty() => {
Ok(WasmDiffResult::default())
}
(serde_json::Value::String(w), Token::Atom(e)) if w.as_str() == *e => {
Ok(WasmDiffResult::default())
}
(serde_json::Value::Null, Token::Atom(_)) => todo!(), (serde_json::Value::Null, Token::Atom(_)) => todo!(),
(serde_json::Value::Null, Token::List(_)) => todo!(), (serde_json::Value::Null, Token::List(_)) => todo!(),
(serde_json::Value::Null, Token::TextWithProperties(_)) => todo!(), (serde_json::Value::Null, Token::TextWithProperties(_)) => todo!(),
(serde_json::Value::Null, Token::Vector(_)) => todo!(), (serde_json::Value::Null, Token::Vector(_)) => todo!(),
(serde_json::Value::Bool(_), Token::Atom(_)) => todo!(), // (serde_json::Value::Bool(_), Token::Atom(_)) => todo!(),
(serde_json::Value::Bool(_), Token::List(_)) => todo!(), (serde_json::Value::Bool(_), Token::List(_)) => todo!(),
(serde_json::Value::Bool(_), Token::TextWithProperties(_)) => todo!(), (serde_json::Value::Bool(_), Token::TextWithProperties(_)) => todo!(),
(serde_json::Value::Bool(_), Token::Vector(_)) => todo!(), (serde_json::Value::Bool(_), Token::Vector(_)) => todo!(),
@ -69,7 +95,19 @@ fn compare_json_value<'b, 's>(
(serde_json::Value::Number(_), Token::List(_)) => todo!(), (serde_json::Value::Number(_), Token::List(_)) => todo!(),
(serde_json::Value::Number(_), Token::TextWithProperties(_)) => todo!(), (serde_json::Value::Number(_), Token::TextWithProperties(_)) => todo!(),
(serde_json::Value::Number(_), Token::Vector(_)) => todo!(), (serde_json::Value::Number(_), Token::Vector(_)) => todo!(),
(serde_json::Value::String(_), Token::Atom(_)) => todo!(), // (serde_json::Value::String(_), Token::Atom(_)) => todo!(),
(serde_json::Value::String(w), Token::Atom(e)) => {
let mut result = WasmDiffResult::default();
result.status.push(WasmDiffStatus::Bad(
format!(
"Value mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
emacs = e,
wasm = w,
)
.into(),
));
Ok(result)
}
(serde_json::Value::String(_), Token::List(_)) => todo!(), (serde_json::Value::String(_), Token::List(_)) => todo!(),
(serde_json::Value::String(_), Token::TextWithProperties(_)) => todo!(), (serde_json::Value::String(_), Token::TextWithProperties(_)) => todo!(),
(serde_json::Value::String(_), Token::Vector(_)) => todo!(), (serde_json::Value::String(_), Token::Vector(_)) => todo!(),
@ -84,6 +122,31 @@ fn compare_json_value<'b, 's>(
} }
} }
fn compare_optional_json_value<'b, 's>(
source: &'s str,
emacs: Option<&'b Token<'s>>,
wasm: Option<&serde_json::Value>,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
match (emacs, wasm) {
(None, None) | (None, Some(serde_json::Value::Null)) | (Some(Token::Atom("nil")), None) => {
Ok(WasmDiffResult::default())
}
(Some(e), Some(w)) => compare_json_value(source, e, w),
_ => Ok(WasmDiffResult {
status: vec![WasmDiffStatus::Bad(
format!(
"Nullness mismatch. Emacs=({emacs:?}) Wasm=({wasm:?}).",
emacs = emacs,
wasm = wasm
)
.into(),
)],
children: Vec::new(),
name: "".into(),
}),
}
}
fn compare_ast_node<'e, 's, 'w>( fn compare_ast_node<'e, 's, 'w>(
source: &'s str, source: &'s str,
emacs: &'e Vec<Token<'s>>, emacs: &'e Vec<Token<'s>>,
@ -136,12 +199,21 @@ fn compare_ast_node<'e, 's, 'w>(
.keys() .keys()
.map(|s| (*s).to_owned()) .map(|s| (*s).to_owned())
.collect(); .collect();
// wasm_attributes_map.iter().filter_map(|(k,v)| if matches!(v, serde_json::Value::Null) {None} else {Some(k)}).map(wasm_key_to_emacs_key)
let wasm_keys: std::collections::BTreeSet<String> = let wasm_keys: std::collections::BTreeSet<String> =
std::iter::once(":standard-properties".to_owned()) std::iter::once(":standard-properties".to_owned())
.chain(wasm_attributes_map.keys().map(wasm_key_to_emacs_key)) .chain(wasm_attributes_map.keys().map(wasm_key_to_emacs_key))
.collect(); .collect();
let emacs_only_attributes: Vec<&String> = emacs_keys.difference(&wasm_keys).collect(); let emacs_only_attributes: Vec<&String> = emacs_keys.difference(&wasm_keys).collect();
let wasm_only_attributes: Vec<&String> = wasm_keys.difference(&emacs_keys).collect(); let wasm_only_attributes: Vec<&String> = wasm_keys
.difference(&emacs_keys)
.filter(|attribute| {
emacs_attributes_map
.get(attribute.as_str())
.map(|token| !matches!(token, Token::Atom("nil")))
.unwrap_or(false)
})
.collect();
if !emacs_only_attributes.is_empty() { if !emacs_only_attributes.is_empty() {
result.status.push(WasmDiffStatus::Bad( result.status.push(WasmDiffStatus::Bad(
format!( format!(
@ -179,18 +251,16 @@ fn compare_ast_node<'e, 's, 'w>(
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::default();
layer.name = Cow::Owned(attribute_name.clone()); layer.name = Cow::Owned(attribute_name.clone());
let wasm_attribute_value = wasm_attributes_map let wasm_attribute_value = wasm_attributes_map.get(attribute_name);
.get(attribute_name)
.ok_or("Key should exist in both wasm and elisp at this point.")?;
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 let emacs_attribute_value = emacs_attributes_map.get(emacs_key.as_str()).map(|e| *e);
.get(emacs_key.as_str()) let inner_layer =
.ok_or("Key should exist in both wasm and elisp at this point.")?; compare_optional_json_value(source, emacs_attribute_value, wasm_attribute_value)?;
layer.extend(compare_json_value( if !inner_layer.name.is_empty() {
source, layer.children.push(inner_layer);
emacs_attribute_value, } else {
wasm_attribute_value, layer.extend(inner_layer)?;
)?)?; }
result.children.push(layer); result.children.push(layer);
} }
} }
@ -213,7 +283,7 @@ fn compare_ast_node<'e, 's, 'w>(
(emacs_standard_properties.post_blank, "post-blank"), (emacs_standard_properties.post_blank, "post-blank"),
] { ] {
match (emacs_value, wasm_standard_properties.get(wasm_name)) { match (emacs_value, wasm_standard_properties.get(wasm_name)) {
(None, None) => {} (None, None) | (None, Some(serde_json::Value::Null)) => {}
(None, Some(_)) => { (None, Some(_)) => {
layer.status.push(WasmDiffStatus::Bad( layer.status.push(WasmDiffStatus::Bad(
format!( format!(

View File

@ -45,8 +45,6 @@ impl<'s> WasmDiffResult<'s> {
pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> { pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> {
self.print_indented(0, original_document) self.print_indented(0, original_document)
// println!("{:#?}", self);
// todo!()
} }
fn print_indented( fn print_indented(

View File

@ -60,3 +60,13 @@ async fn autogen_odd_{name}() -> Result<(), Box<dyn std::error::Error>> {{
assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?); assert!(organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings, false).await?);
Ok(()) Ok(())
}} }}
#[cfg(feature = "wasm_test")]
{expect_fail}
#[tokio::test]
async fn autogen_wasm_{name}() -> Result<(), Box<dyn std::error::Error>> {{
let org_path = "{path}";
let org_contents = std::fs::read_to_string(org_path).expect("Read org file.");
assert!(organic::wasm_test::wasm_run_anonymous_compare(org_contents.as_str()).await?);
Ok(())
}}