Add src block properties.
These are largely the same as example blocks but with a :language property.
This commit is contained in:
@@ -1727,11 +1727,161 @@ fn compare_src_block<'b, 's>(
|
||||
_source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
rust: &'b SrcBlock<'s>,
|
||||
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
let this_status = DiffStatus::Good;
|
||||
let message = None;
|
||||
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error + 's>> {
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let mut message = None;
|
||||
|
||||
// TODO: Compare :language :switches :parameters :number-lines :preserve-indent :retain-labels :use-labels :label-fmt :value
|
||||
// Compare language
|
||||
let language = get_property_quoted_string(emacs, ":language")?;
|
||||
if language.as_ref().map(String::as_str) != rust.language {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Language mismatch (emacs != rust) {:?} != {:?}",
|
||||
language, rust.language
|
||||
));
|
||||
}
|
||||
|
||||
// Compare value
|
||||
let contents = get_property_quoted_string(emacs, ":value")?.unwrap_or(String::new());
|
||||
if contents != rust.contents {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Value mismatch (emacs != rust) {:?} != {:?}",
|
||||
contents, rust.contents
|
||||
));
|
||||
}
|
||||
|
||||
// Compare switches
|
||||
let switches = get_property_quoted_string(emacs, ":switches")?;
|
||||
match (switches.as_ref().map(String::as_str), rust.switches) {
|
||||
(None, None) => {}
|
||||
(Some(""), None) => {}
|
||||
(None, Some("")) => {
|
||||
unreachable!("The organic parser would return a None instead of an empty string.");
|
||||
}
|
||||
(Some(e), Some(r)) if e == r => {}
|
||||
_ => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Switches mismatch (emacs != rust) {:?} != {:?}",
|
||||
switches, rust.switches
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Compare number-lines
|
||||
let number_lines = get_property(emacs, ":number-lines")?;
|
||||
match (number_lines, &rust.number_lines) {
|
||||
(None, None) => {}
|
||||
(Some(number_lines), Some(rust_number_lines)) => {
|
||||
let token_list = number_lines.as_list()?;
|
||||
let number_type = token_list
|
||||
.get(0)
|
||||
.map(Token::as_atom)
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.ok_or(":number-lines should have a type.")?;
|
||||
let number_value = token_list
|
||||
.get(2)
|
||||
.map(Token::as_atom)
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.map(|val| val.parse::<LineNumber>())
|
||||
.map_or(Ok(None), |r| r.map(Some))?
|
||||
.ok_or(":number-lines should have a value.")?;
|
||||
match (number_type, number_value, rust_number_lines) {
|
||||
("new", emacs_val, SwitchNumberLines::New(rust_val)) if emacs_val == *rust_val => {}
|
||||
("continued", emacs_val, SwitchNumberLines::Continued(rust_val))
|
||||
if emacs_val == *rust_val => {}
|
||||
_ => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Number lines mismatch (emacs != rust) {:?} != {:?}",
|
||||
number_lines, rust.number_lines
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Number lines mismatch (emacs != rust) {:?} != {:?}",
|
||||
number_lines, rust.number_lines
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
// Compare preserve-indent
|
||||
let preserve_indent = get_property_boolean(emacs, ":preserve-indent")?;
|
||||
if preserve_indent {
|
||||
// I don't know what :preserve-indent is for, but it seems to always be nil. This is here to alert me to value being non-nil so I can investigate.
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!("Non-nil :preserve-indent {:?}", preserve_indent));
|
||||
}
|
||||
|
||||
// Compare retain-labels
|
||||
// retain-labels is t by default, nil if -r is set, or a number if -k and -r is set.
|
||||
let retain_labels = get_property_unquoted_atom(emacs, ":retain-labels")?;
|
||||
if let Some(retain_labels) = retain_labels {
|
||||
if retain_labels == "t" {
|
||||
match rust.retain_labels {
|
||||
RetainLabels::Yes => {}
|
||||
_ => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Retain labels mismatch (emacs != rust) {:?} != {:?}",
|
||||
retain_labels, rust.retain_labels
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let retain_labels: CharOffsetInLine = get_property_numeric(emacs, ":retain-labels")?.expect("Cannot be None or else the earlier get_property_unquoted_atom would have been None.");
|
||||
match (retain_labels, &rust.retain_labels) {
|
||||
(e, RetainLabels::Keep(r)) if e == *r => {}
|
||||
_ => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Retain labels mismatch (emacs != rust) {:?} != {:?}",
|
||||
retain_labels, rust.retain_labels
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
match rust.retain_labels {
|
||||
RetainLabels::No => {}
|
||||
_ => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Retain labels mismatch (emacs != rust) {:?} != {:?}",
|
||||
retain_labels, rust.retain_labels
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compare use-labels
|
||||
let use_labels = get_property_boolean(emacs, ":use-labels")?;
|
||||
if use_labels != rust.use_labels {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Use labels mismatch (emacs != rust) {:?} != {:?}",
|
||||
use_labels, rust.use_labels
|
||||
));
|
||||
}
|
||||
|
||||
// Compare label-fmt
|
||||
let label_format = get_property_quoted_string(emacs, ":label-fmt")?;
|
||||
match (label_format.as_ref(), rust.label_format) {
|
||||
(None, None) => {}
|
||||
(Some(emacs_label_format), Some(rust_label_format))
|
||||
if emacs_label_format == rust_label_format => {}
|
||||
_ => {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Label format mismatch (emacs != rust) {:?} != {:?}",
|
||||
label_format, rust.label_format
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(DiffResult {
|
||||
status: this_status,
|
||||
|
||||
Reference in New Issue
Block a user