Add tests for odd headline levels.

This commit is contained in:
Tom Alexander 2023-09-29 16:37:22 -04:00
parent 0c363c8dd6
commit 07e11e359a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
9 changed files with 56 additions and 19 deletions

View File

@ -1,6 +1,7 @@
* Autogen tests
The autogen tests are the tests automatically generated to compare the output of Organic vs the upstream Emacs Org-mode parser using the sample documents in the =org_mode_samples= folder. They will have a prefix based on the settings for each test.
- No prefix :: The test is run with the default settings (The upstream Emacs Org-mode determines the default settings)
- default :: The test is run with the default settings (The upstream Emacs Org-mode determines the default settings)
- la :: Short for "list alphabetic". Enables alphabetic plain lists.
- t# :: Sets the tab-width to # (as in t4 sets the tab-width to 4).
- odd :: Sets the org-odd-levels-only setting to true (meaning "odd" as opposed to "oddeven").

View File

@ -6,9 +6,9 @@ use crate::compare::parse::emacs_parse_file_org_document;
use crate::compare::parse::get_emacs_version;
use crate::compare::parse::get_org_mode_version;
use crate::compare::sexp::sexp;
use crate::context::GlobalSettings;
use crate::context::LocalFileAccessInterface;
use crate::parser::parse_with_settings;
use crate::GlobalSettings;
use crate::LocalFileAccessInterface;
pub fn run_anonymous_compare<P: AsRef<str>>(
org_contents: P,

View File

@ -1,7 +1,8 @@
use std::path::Path;
use std::process::Command;
use crate::GlobalSettings;
use crate::context::HeadlineLevelFilter;
use crate::settings::GlobalSettings;
/// Generate elisp to configure org-mode parsing settings
///
@ -12,7 +13,15 @@ fn global_settings_elisp(global_settings: &GlobalSettings) -> String {
if global_settings.list_allow_alphabetical {
ret += "(setq org-list-allow-alphabetical t)\n"
}
if global_settings.tab_width != crate::settings::DEFAULT_TAB_WIDTH {
ret += format!("(setq-default tab-width {})", global_settings.tab_width).as_str();
}
if global_settings.odd_levels_only != HeadlineLevelFilter::default() {
ret += match global_settings.odd_levels_only {
HeadlineLevelFilter::Odd => "(setq org-odd-levels-only t)\n",
HeadlineLevelFilter::OddEven => "(setq org-odd-levels-only nil)\n",
};
}
ret
}

View File

@ -29,6 +29,8 @@ pub struct GlobalSettings<'g, 's> {
pub odd_levels_only: HeadlineLevelFilter,
}
pub const DEFAULT_TAB_WIDTH: IndentationLevel = 8;
impl<'g, 's> GlobalSettings<'g, 's> {
fn new() -> GlobalSettings<'g, 's> {
GlobalSettings {
@ -39,8 +41,8 @@ impl<'g, 's> GlobalSettings<'g, 's> {
in_progress_todo_keywords: BTreeSet::new(),
complete_todo_keywords: BTreeSet::new(),
list_allow_alphabetical: false,
tab_width: 8,
odd_levels_only: HeadlineLevelFilter::OddEven,
tab_width: DEFAULT_TAB_WIDTH,
odd_levels_only: HeadlineLevelFilter::default(),
}
}
}
@ -51,8 +53,14 @@ impl<'g, 's> Default for GlobalSettings<'g, 's> {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum HeadlineLevelFilter {
Odd,
OddEven,
}
impl Default for HeadlineLevelFilter {
fn default() -> Self {
HeadlineLevelFilter::OddEven
}
}

View File

@ -26,5 +26,6 @@ pub use file_access_interface::FileAccessInterface;
pub use file_access_interface::LocalFileAccessInterface;
pub use global_settings::GlobalSettings;
pub use global_settings::HeadlineLevelFilter;
pub use global_settings::DEFAULT_TAB_WIDTH;
pub(crate) use list::List;
pub(crate) use parser_with_context::parser_with_context;

View File

@ -11,6 +11,10 @@ mod iter;
pub mod parser;
pub mod types;
pub use context::FileAccessInterface;
pub use context::GlobalSettings;
pub use context::LocalFileAccessInterface;
pub mod settings {
pub use crate::context::FileAccessInterface;
pub use crate::context::GlobalSettings;
pub use crate::context::HeadlineLevelFilter;
pub use crate::context::LocalFileAccessInterface;
pub use crate::context::DEFAULT_TAB_WIDTH;
}

View File

@ -5,8 +5,8 @@ use std::path::Path;
use ::organic::parser::parse;
use organic::parser::parse_with_settings;
use organic::GlobalSettings;
use organic::LocalFileAccessInterface;
use organic::settings::GlobalSettings;
use organic::settings::LocalFileAccessInterface;
#[cfg(feature = "tracing")]
use crate::init_tracing::init_telemetry;

View File

@ -11,8 +11,8 @@ use super::OrgSource;
use crate::context::HeadlineLevelFilter;
use crate::error::CustomError;
use crate::error::Res;
use crate::settings::GlobalSettings;
use crate::types::Keyword;
use crate::GlobalSettings;
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
pub(crate) fn scan_for_in_buffer_settings<'s>(

View File

@ -1,8 +1,8 @@
// TODO: Investigate writing a proc macro to make specifying these permutations easier.
// TODO: Investigate writing a proc macro to make specifying these combinations easier. For example, currently I am only setting 1 setting per test to keep the repetition reasonable when I should be mixing all the different combinations.
{expect_fail}
#[test]
fn autogen_{name}() -> Result<(), Box<dyn std::error::Error>> {{
fn autogen_default_{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.");
organic::compare::run_anonymous_compare(org_contents.as_str())?;
@ -15,7 +15,7 @@ fn autogen_la_{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.");
let global_settings = {{
let mut global_settings = organic::GlobalSettings::default();
let mut global_settings = organic::settings::GlobalSettings::default();
global_settings.list_allow_alphabetical = true;
global_settings
}};
@ -29,7 +29,7 @@ fn autogen_t1_{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.");
let global_settings = {{
let mut global_settings = organic::GlobalSettings::default();
let mut global_settings = organic::settings::GlobalSettings::default();
global_settings.tab_width = 1;
global_settings
}};
@ -43,10 +43,24 @@ fn autogen_t16_{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.");
let global_settings = {{
let mut global_settings = organic::GlobalSettings::default();
let mut global_settings = organic::settings::GlobalSettings::default();
global_settings.tab_width = 16;
global_settings
}};
organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings)?;
Ok(())
}}
{expect_fail}
#[test]
fn autogen_odd_{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.");
let global_settings = {{
let mut global_settings = organic::settings::GlobalSettings::default();
global_settings.odd_levels_only = organic::settings::HeadlineLevelFilter::Odd;
global_settings
}};
organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings)?;
Ok(())
}}