From cd781a7dcf0b231d219d3af9e65464f9b25b9411 Mon Sep 17 00:00:00 2001 From: Tom Alexander <tom@fizz.buzz> Date: Sun, 24 Sep 2023 03:09:51 -0400 Subject: [PATCH] Add simple test to prove the scan for in-buffer settings is still working. --- src/parser/in_buffer_settings.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/parser/in_buffer_settings.rs b/src/parser/in_buffer_settings.rs index 824c2da..58976ab 100644 --- a/src/parser/in_buffer_settings.rs +++ b/src/parser/in_buffer_settings.rs @@ -113,3 +113,33 @@ pub(crate) fn apply_in_buffer_settings<'g, 's, 'sf>( Ok(new_settings) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn scan_test() -> Result<(), Box<dyn std::error::Error>> { + let input = OrgSource::new( + r#" +foo + #+archive: bar + +baz #+category: lorem + +#+label: ipsum + +#+todo: dolar +cat +"#, + ); + let (remaining, settings) = scan_for_in_buffer_settings(input)?; + assert_eq!(Into::<&str>::into(remaining), "cat\n"); + let keys: Vec<_> = settings.iter().map(|kw| kw.key).collect(); + // category is skipped because it is not the first non-whitespace on the line. + // + // label is skipped because it is not an in-buffer setting. + assert_eq!(keys, vec!["archive", "todo"]); + Ok(()) + } +}