From 40be079d5d0ea988303cd70034d11c92fbb8fa39 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 7 Mar 2023 12:14:07 +0100 Subject: Add tests for whitespace argument in template derive proc-macro --- askama_derive/src/config.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'askama_derive') diff --git a/askama_derive/src/config.rs b/askama_derive/src/config.rs index 22aada7..cf22a72 100644 --- a/askama_derive/src/config.rs +++ b/askama_derive/src/config.rs @@ -549,4 +549,34 @@ mod tests { .unwrap(); assert_eq!(config.whitespace, WhitespaceHandling::Minimize); } + + #[cfg(feature = "toml")] + #[test] + fn test_whitespace_in_template() { + // Checking that template arguments have precedence over general configuration. + // So in here, in the template arguments, there is `whitespace = "minimize"` so + // the `WhitespaceHandling` should be `Minimize` as well. + let config = Config::new( + r#" + [general] + whitespace = "suppress" + "#, + Some(&"minimize".to_owned()), + ) + .unwrap(); + assert_eq!(config.whitespace, WhitespaceHandling::Minimize); + + let config = Config::new(r#""#, Some(&"minimize".to_owned())).unwrap(); + assert_eq!(config.whitespace, WhitespaceHandling::Minimize); + } + + #[test] + fn test_config_whitespace_error() { + let config = Config::new(r#""#, Some(&"trim".to_owned())); + if let Err(err) = config { + assert_eq!(err.msg, "invalid value for `whitespace`: \"trim\""); + } else { + panic!("Config::new should have return an error"); + } + } } -- cgit