From 32da06776c1b1a47d1bff3a094be2f977a6ed157 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 4 Oct 2023 14:49:08 -0400 Subject: [PATCH] Handle matching no switches. --- .../example/space_for_parameters.org | 2 ++ src/compare/diff.rs | 20 +++++++++++++------ src/parser/lesser_block.rs | 2 ++ 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 org_mode_samples/lesser_element/lesser_block/example/space_for_parameters.org diff --git a/org_mode_samples/lesser_element/lesser_block/example/space_for_parameters.org b/org_mode_samples/lesser_element/lesser_block/example/space_for_parameters.org new file mode 100644 index 0000000..cdd859b --- /dev/null +++ b/org_mode_samples/lesser_element/lesser_block/example/space_for_parameters.org @@ -0,0 +1,2 @@ +#+begin_example +#+end_example diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 938622d..6b5487f 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1559,12 +1559,20 @@ fn compare_example_block<'b, 's>( // Compare switches let switches = get_property_quoted_string(emacs, ":switches")?; - if switches.as_ref().map(String::as_str) != rust.switches { - this_status = DiffStatus::Bad; - message = Some(format!( - "Switches mismatch (emacs != rust) {:?} != {:?}", - switches, rust.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 diff --git a/src/parser/lesser_block.rs b/src/parser/lesser_block.rs index 4886965..0dde4a0 100644 --- a/src/parser/lesser_block.rs +++ b/src/parser/lesser_block.rs @@ -326,6 +326,7 @@ fn _lesser_block_begin<'b, 'g, 'r, 's, 'c>( Ok((remaining, name)) } +#[derive(Debug)] struct ExampleSwitches<'s> { source: &'s str, number_lines: Option, @@ -334,6 +335,7 @@ struct ExampleSwitches<'s> { label_format: Option<&'s str>, } +#[derive(Debug)] enum SwitchState { Normal, NewLineNumber,