Add tests for tab width.

This commit is contained in:
Tom Alexander 2023-09-29 15:47:58 -04:00
parent 9a479b33e0
commit 0c363c8dd6
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 38 additions and 0 deletions

View File

@ -3,3 +3,4 @@ The autogen tests are the tests automatically generated to compare the output of
- No prefix :: 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).

View File

@ -0,0 +1,5 @@
# "lorem" is prefixed by a tab instead of spaces, so the editor's tab-width value determines whether lorem is a sibling of baz (tab-width 8), a sibling of bar (tab-width < 8), or a child of baz (tab-width > 8).
1. foo
1. bar
1. baz
1. lorem

View File

@ -7,10 +7,12 @@ use crate::GlobalSettings;
///
/// Currently only org-list-allow-alphabetical is supported.
fn global_settings_elisp(global_settings: &GlobalSettings) -> String {
// This string concatenation is wildly inefficient but its only called in tests 🤷.
let mut ret = "".to_owned();
if global_settings.list_allow_alphabetical {
ret += "(setq org-list-allow-alphabetical t)\n"
}
ret += format!("(setq-default tab-width {})", global_settings.tab_width).as_str();
ret
}

View File

@ -1,3 +1,5 @@
// TODO: Investigate writing a proc macro to make specifying these permutations easier.
{expect_fail}
#[test]
fn autogen_{name}() -> Result<(), Box<dyn std::error::Error>> {{
@ -20,3 +22,31 @@ fn autogen_la_{name}() -> Result<(), Box<dyn std::error::Error>> {{
organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings)?;
Ok(())
}}
{expect_fail}
#[test]
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();
global_settings.tab_width = 1;
global_settings
}};
organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings)?;
Ok(())
}}
{expect_fail}
#[test]
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();
global_settings.tab_width = 16;
global_settings
}};
organic::compare::run_anonymous_compare_with_settings(org_contents.as_str(), &global_settings)?;
Ok(())
}}