Code structure for radio links and radio targets.

This commit is contained in:
Tom Alexander
2023-04-24 18:55:15 -04:00
parent 5c37373419
commit 64c17e654a
5 changed files with 132 additions and 7 deletions

View File

@@ -29,6 +29,8 @@ use crate::parser::PlainListItem;
use crate::parser::PlainText;
use crate::parser::Planning;
use crate::parser::PropertyDrawer;
use crate::parser::RadioLink;
use crate::parser::RadioTarget;
use crate::parser::RegularLink;
use crate::parser::Section;
use crate::parser::SrcBlock;
@@ -144,6 +146,8 @@ fn compare_object<'s>(
Object::StrikeThrough(obj) => compare_strike_through(source, emacs, obj),
Object::PlainText(obj) => compare_plain_text(source, emacs, obj),
Object::RegularLink(obj) => compare_regular_link(source, emacs, obj),
Object::RadioLink(obj) => compare_radio_link(source, emacs, obj),
Object::RadioTarget(obj) => compare_radio_target(source, emacs, obj),
}
}
@@ -915,16 +919,25 @@ fn compare_plain_text<'s>(
let mut this_status = DiffStatus::Good;
let mut message = None;
let text = emacs.as_text()?;
let emacs_text_length = {
let start_ind: usize = text.properties.get(0).expect("Should have start index.").as_atom()?.parse()?;
let end_ind: usize = text.properties.get(1).expect("Should have end index.").as_atom()?.parse()?;
end_ind - start_ind
};
let start_ind: usize = text
.properties
.get(0)
.expect("Should have start index.")
.as_atom()?
.parse()?;
let end_ind: usize = text
.properties
.get(1)
.expect("Should have end index.")
.as_atom()?
.parse()?;
let emacs_text_length = end_ind - start_ind;
if rust.source.len() != emacs_text_length {
this_status = DiffStatus::Bad;
message = Some(format!(
"(emacs len != rust len) {:?} != {:?}",
emacs_text_length, rust.source.len()
emacs_text_length,
rust.source.len()
));
}
let unquoted_text = text.unquote()?;
@@ -1104,3 +1117,49 @@ fn compare_regular_link<'s>(
children: Vec::new(),
})
}
fn compare_radio_link<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s RadioLink<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let emacs_name = "link";
if assert_name(emacs, emacs_name).is_err() {
this_status = DiffStatus::Bad;
}
if assert_bounds(source, emacs, rust).is_err() {
this_status = DiffStatus::Bad;
}
Ok(DiffResult {
status: this_status,
name: emacs_name.to_owned(),
message: None,
children: Vec::new(),
})
}
fn compare_radio_target<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s RadioTarget<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let emacs_name = "radio-target";
if assert_name(emacs, emacs_name).is_err() {
this_status = DiffStatus::Bad;
}
if assert_bounds(source, emacs, rust).is_err() {
this_status = DiffStatus::Bad;
}
Ok(DiffResult {
status: this_status,
name: emacs_name.to_owned(),
message: None,
children: Vec::new(),
})
}