Compare the standard properties.
This commit is contained in:
parent
58290515b5
commit
a5e108bc37
@ -16,4 +16,6 @@ pub(crate) use compare_field::EmacsField;
|
||||
pub(crate) use elisp_fact::ElispFact;
|
||||
pub use sexp::sexp;
|
||||
pub use sexp::Token;
|
||||
pub(crate) use util::get_emacs_standard_properties;
|
||||
pub(crate) use util::get_property_quoted_string;
|
||||
pub(crate) use util::EmacsStandardProperties;
|
||||
|
@ -145,20 +145,20 @@ fn assert_post_blank<'b, 's, S: StandardProperties<'s> + ?Sized>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct EmacsStandardProperties {
|
||||
begin: Option<usize>,
|
||||
pub(crate) struct EmacsStandardProperties {
|
||||
pub(crate) begin: Option<usize>,
|
||||
#[allow(dead_code)]
|
||||
post_affiliated: Option<usize>,
|
||||
pub(crate) post_affiliated: Option<usize>,
|
||||
#[allow(dead_code)]
|
||||
contents_begin: Option<usize>,
|
||||
pub(crate) contents_begin: Option<usize>,
|
||||
#[allow(dead_code)]
|
||||
contents_end: Option<usize>,
|
||||
end: Option<usize>,
|
||||
pub(crate) contents_end: Option<usize>,
|
||||
pub(crate) end: Option<usize>,
|
||||
#[allow(dead_code)]
|
||||
post_blank: Option<usize>,
|
||||
pub(crate) post_blank: Option<usize>,
|
||||
}
|
||||
|
||||
fn get_emacs_standard_properties(
|
||||
pub(crate) fn get_emacs_standard_properties(
|
||||
emacs: &Token<'_>,
|
||||
) -> Result<EmacsStandardProperties, Box<dyn std::error::Error>> {
|
||||
let children = emacs.as_list()?;
|
||||
|
@ -15,7 +15,7 @@ use crate::wasm::to_wasm::ToWasmStandardProperties;
|
||||
#[serde(tag = "ast_node")]
|
||||
#[serde(rename = "org-data")]
|
||||
pub struct WasmDocument<'s, 'p> {
|
||||
standard_properties: WasmStandardProperties,
|
||||
pub(crate) standard_properties: WasmStandardProperties,
|
||||
additional_properties: Vec<(String, &'s str)>,
|
||||
pub(crate) children: Vec<WasmAstNode<'s, 'p>>,
|
||||
pub(crate) category: Option<&'p str>,
|
||||
|
@ -67,5 +67,6 @@ pub use document::WasmDocument;
|
||||
pub(crate) use headline::WasmHeadline;
|
||||
pub use parse_result::ParseResult;
|
||||
pub(crate) use section::WasmSection;
|
||||
pub(crate) use standard_properties::WasmStandardProperties;
|
||||
pub use to_wasm::ToWasm;
|
||||
pub use to_wasm::ToWasmContext;
|
||||
|
@ -7,11 +7,11 @@ use crate::types::StandardProperties;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub(crate) struct WasmStandardProperties {
|
||||
begin: usize,
|
||||
end: usize,
|
||||
contents_begin: Option<usize>,
|
||||
contents_end: Option<usize>,
|
||||
post_blank: PostBlank,
|
||||
pub(crate) begin: usize,
|
||||
pub(crate) end: usize,
|
||||
pub(crate) contents_begin: Option<usize>,
|
||||
pub(crate) contents_end: Option<usize>,
|
||||
pub(crate) post_blank: PostBlank,
|
||||
}
|
||||
|
||||
impl<'s, SP: StandardProperties<'s>> ToWasmStandardProperties for SP {
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use super::elisp_compare::WasmElispCompare;
|
||||
use crate::compare::get_emacs_standard_properties;
|
||||
use crate::compare::get_property_quoted_string;
|
||||
use crate::compare::ElispFact;
|
||||
use crate::compare::EmacsField;
|
||||
@ -9,6 +10,7 @@ use crate::wasm::WasmAstNode;
|
||||
use crate::wasm::WasmDocument;
|
||||
use crate::wasm::WasmHeadline;
|
||||
use crate::wasm::WasmSection;
|
||||
use crate::wasm::WasmStandardProperties;
|
||||
use crate::wasm_test::macros::wasm_compare;
|
||||
|
||||
pub fn wasm_compare_document<'b, 's, 'p>(
|
||||
@ -343,3 +345,74 @@ fn wasm_compare_property_quoted_string<
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn wasm_compare_standard_properties<'b, 's>(
|
||||
_source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
wasm: &WasmStandardProperties,
|
||||
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
|
||||
let mut result = WasmDiffResult::default();
|
||||
let mut layer = WasmDiffResult::default();
|
||||
layer.name = "standard-properties".into();
|
||||
let standard_properties = get_emacs_standard_properties(emacs)?;
|
||||
|
||||
if Some(wasm.begin) != standard_properties.begin {
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
property = "begin",
|
||||
emacs = standard_properties.begin,
|
||||
wasm = Some(wasm.begin),
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if Some(wasm.end) != standard_properties.end {
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
property = "end",
|
||||
emacs = standard_properties.end,
|
||||
wasm = Some(wasm.end),
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if wasm.contents_begin != standard_properties.contents_begin {
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
property = "contents-begin",
|
||||
emacs = standard_properties.contents_begin,
|
||||
wasm = wasm.contents_begin,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if wasm.contents_end != standard_properties.contents_end {
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
property = "contents-end",
|
||||
emacs = standard_properties.contents_end,
|
||||
wasm = wasm.contents_end,
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
if Some(wasm.post_blank).map(|post_blank| post_blank as usize) != standard_properties.post_blank
|
||||
{
|
||||
layer.status.push(WasmDiffStatus::Bad(
|
||||
format!(
|
||||
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
|
||||
property = "post-blank",
|
||||
emacs = standard_properties.post_blank,
|
||||
wasm = Some(wasm.post_blank),
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
}
|
||||
|
||||
result.children.push(layer);
|
||||
Ok(result)
|
||||
}
|
||||
|
@ -39,6 +39,11 @@ macro_rules! wasm_compare {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Compare standard properties
|
||||
result.extend(wasm_compare_standard_properties($source, $emacs, &$wasm.standard_properties)?)?;
|
||||
}
|
||||
|
||||
{
|
||||
// Compare children.
|
||||
result.extend(wasm_compare_list(
|
||||
|
Loading…
x
Reference in New Issue
Block a user