Compare commits
8 Commits
3fd3d20722
...
a4a83d047d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a4a83d047d | ||
![]() |
a4414369ce | ||
![]() |
83e4b72307 | ||
![]() |
34b3e4fa7b | ||
![]() |
c0e879dc1e | ||
![]() |
fa31b001f4 | ||
![]() |
0897061ff6 | ||
![]() |
28a3e1bc7b |
@ -115,7 +115,7 @@ spec:
|
||||
[
|
||||
--no-default-features,
|
||||
--features,
|
||||
compare,
|
||||
"compare,wasm_test",
|
||||
--no-fail-fast,
|
||||
--lib,
|
||||
--test,
|
||||
|
5
Makefile
5
Makefile
@ -63,6 +63,11 @@ dockertest:
|
||||
> $(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)
|
||||
|
||||
.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
|
||||
buildtest:
|
||||
> cargo build --no-default-features
|
||||
|
@ -332,19 +332,19 @@ pub type HourInner = u8;
|
||||
pub type MinuteInner = u8;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Year(YearInner);
|
||||
pub struct Year(pub YearInner);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Month(MonthInner);
|
||||
pub struct Month(pub MonthInner);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DayOfMonth(DayOfMonthInner);
|
||||
pub struct DayOfMonth(pub DayOfMonthInner);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Hour(HourInner);
|
||||
pub struct Hour(pub HourInner);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Minute(MinuteInner);
|
||||
pub struct Minute(pub MinuteInner);
|
||||
|
||||
impl Year {
|
||||
// TODO: Make a real error type instead of a boxed any error.
|
||||
|
@ -4,16 +4,12 @@ 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::Bold;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmBold {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
pub struct WasmBold {}
|
||||
|
||||
to_wasm!(
|
||||
WasmBold,
|
||||
@ -21,7 +17,7 @@ to_wasm!(
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Bold(original) },
|
||||
{ "TODO".into() },
|
||||
{ "bold".into() },
|
||||
{
|
||||
let children = original
|
||||
.children
|
||||
@ -33,11 +29,6 @@ to_wasm!(
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmBold {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
Ok((children, WasmBold {}))
|
||||
}
|
||||
);
|
||||
|
@ -7,12 +7,14 @@ use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::FixedWidthArea;
|
||||
use crate::types::GetAffiliatedKeywords;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmFixedWidthArea {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
pub(crate) value: String,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
@ -21,12 +23,19 @@ to_wasm!(
|
||||
original,
|
||||
wasm_context,
|
||||
{ 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((
|
||||
Vec::new(),
|
||||
WasmFixedWidthArea {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
additional_properties,
|
||||
value,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -5,14 +5,39 @@ use super::ast_node::WasmAstNode;
|
||||
use super::macros::to_wasm;
|
||||
use super::to_wasm::ToWasm;
|
||||
use super::AdditionalProperties;
|
||||
use super::AdditionalPropertyValue;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::types::Heading;
|
||||
use crate::types::HeadlineLevel;
|
||||
use crate::types::PriorityCookie;
|
||||
use crate::types::TodoKeywordType;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmHeadline {
|
||||
#[serde(flatten)]
|
||||
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!(
|
||||
@ -21,8 +46,18 @@ to_wasm!(
|
||||
original,
|
||||
wasm_context,
|
||||
{ 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
|
||||
.children
|
||||
.iter()
|
||||
@ -36,7 +71,65 @@ to_wasm!(
|
||||
Ok((
|
||||
children,
|
||||
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?
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -4,16 +4,12 @@ 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::PlainText;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmPlainText {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
pub struct WasmPlainText {}
|
||||
|
||||
to_wasm!(
|
||||
WasmPlainText,
|
||||
@ -22,12 +18,5 @@ to_wasm!(
|
||||
wasm_context,
|
||||
{ WasmAstNode::PlainText(original) },
|
||||
{ "plain-text".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmPlainText {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
}
|
||||
{ Ok((Vec::new(), WasmPlainText {},)) }
|
||||
);
|
||||
|
@ -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::Planning;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmPlanning {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
pub(crate) scheduled: Option<Box<WasmAstNode>>,
|
||||
pub(crate) deadline: Option<Box<WasmAstNode>>,
|
||||
pub(crate) closed: Option<Box<WasmAstNode>>,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
@ -21,12 +21,41 @@ to_wasm!(
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Planning(original) },
|
||||
{ "TODO".into() },
|
||||
{ "planning".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
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)),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -4,16 +4,12 @@ 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::Section;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmSection {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
}
|
||||
pub struct WasmSection {}
|
||||
|
||||
to_wasm!(
|
||||
WasmSection,
|
||||
@ -33,11 +29,6 @@ to_wasm!(
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok((
|
||||
children,
|
||||
WasmSection {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
},
|
||||
))
|
||||
Ok((children, WasmSection {}))
|
||||
}
|
||||
);
|
||||
|
@ -4,15 +4,13 @@ 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::StatisticsCookie;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmStatisticsCookie {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
pub(crate) value: String,
|
||||
}
|
||||
|
||||
to_wasm!(
|
||||
@ -21,12 +19,12 @@ to_wasm!(
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::StatisticsCookie(original) },
|
||||
{ "TODO".into() },
|
||||
{ "statistics-cookie".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
WasmStatisticsCookie {
|
||||
additional_properties: AdditionalProperties::default(),
|
||||
value: original.value.to_owned(),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -4,15 +4,61 @@ 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::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::TimestampRangeType;
|
||||
use crate::types::TimestampType;
|
||||
use crate::types::WarningDelayType;
|
||||
use crate::types::YearInner;
|
||||
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct WasmTimestamp {
|
||||
#[serde(flatten)]
|
||||
pub(crate) additional_properties: AdditionalProperties,
|
||||
#[serde(rename = "type")]
|
||||
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!(
|
||||
@ -21,12 +67,79 @@ to_wasm!(
|
||||
original,
|
||||
wasm_context,
|
||||
{ WasmAstNode::Timestamp(original) },
|
||||
{ "TODO".into() },
|
||||
{ "timestamp".into() },
|
||||
{
|
||||
Ok((
|
||||
Vec::new(),
|
||||
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),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -57,11 +57,37 @@ fn compare_json_value<'b, 's>(
|
||||
(serde_json::Value::Object(w), Token::TextWithProperties(e)) if is_plain_text(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::List(_)) => todo!(),
|
||||
(serde_json::Value::Null, Token::TextWithProperties(_)) => 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::TextWithProperties(_)) => 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::TextWithProperties(_)) => 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::TextWithProperties(_)) => 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>(
|
||||
source: &'s str,
|
||||
emacs: &'e Vec<Token<'s>>,
|
||||
@ -136,12 +199,21 @@ fn compare_ast_node<'e, 's, 'w>(
|
||||
.keys()
|
||||
.map(|s| (*s).to_owned())
|
||||
.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> =
|
||||
std::iter::once(":standard-properties".to_owned())
|
||||
.chain(wasm_attributes_map.keys().map(wasm_key_to_emacs_key))
|
||||
.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() {
|
||||
result.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
@ -179,18 +251,16 @@ fn compare_ast_node<'e, 's, 'w>(
|
||||
for attribute_name in wasm_attributes_map.keys() {
|
||||
let mut layer = WasmDiffResult::default();
|
||||
layer.name = Cow::Owned(attribute_name.clone());
|
||||
let wasm_attribute_value = wasm_attributes_map
|
||||
.get(attribute_name)
|
||||
.ok_or("Key should exist in both wasm and elisp at this point.")?;
|
||||
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())
|
||||
.ok_or("Key should exist in both wasm and elisp at this point.")?;
|
||||
layer.extend(compare_json_value(
|
||||
source,
|
||||
emacs_attribute_value,
|
||||
wasm_attribute_value,
|
||||
)?)?;
|
||||
let emacs_attribute_value = emacs_attributes_map.get(emacs_key.as_str()).map(|e| *e);
|
||||
let inner_layer =
|
||||
compare_optional_json_value(source, emacs_attribute_value, wasm_attribute_value)?;
|
||||
if !inner_layer.name.is_empty() {
|
||||
layer.children.push(inner_layer);
|
||||
} else {
|
||||
layer.extend(inner_layer)?;
|
||||
}
|
||||
result.children.push(layer);
|
||||
}
|
||||
}
|
||||
@ -213,7 +283,7 @@ fn compare_ast_node<'e, 's, 'w>(
|
||||
(emacs_standard_properties.post_blank, "post-blank"),
|
||||
] {
|
||||
match (emacs_value, wasm_standard_properties.get(wasm_name)) {
|
||||
(None, None) => {}
|
||||
(None, None) | (None, Some(serde_json::Value::Null)) => {}
|
||||
(None, Some(_)) => {
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
|
@ -45,8 +45,6 @@ impl<'s> WasmDiffResult<'s> {
|
||||
|
||||
pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
self.print_indented(0, original_document)
|
||||
// println!("{:#?}", self);
|
||||
// todo!()
|
||||
}
|
||||
|
||||
fn print_indented(
|
||||
|
@ -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?);
|
||||
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(())
|
||||
}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user