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 --- testing/tests/whitespace.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'testing/tests/whitespace.rs') diff --git a/testing/tests/whitespace.rs b/testing/tests/whitespace.rs index 4793547..0e42f78 100644 --- a/testing/tests/whitespace.rs +++ b/testing/tests/whitespace.rs @@ -116,3 +116,27 @@ fn test_outer_whitespace() { test_template!(" 1{# #} ", " 1 "); test_template!("\n1{# #}\n\n\n", "\n1\n\n\n"); } + +macro_rules! test_template_ws_config { + ($config:literal, $ws:literal, $source:literal, $rendered: literal) => {{ + #[derive(Template)] + #[template(source = $source, ext = "txt", config = $config, whitespace = $ws)] + struct CondWs; + + assert_eq!(CondWs.render().unwrap(), $rendered); + }}; +} + +#[test] +fn test_template_whitespace_config() { + test_template_ws_config!("test_trim.toml", "preserve", "\t1{# #}\t2", "\t1\t2"); + test_template_ws_config!("test_trim.toml", "minimize", " 1{# #} 2", " 1 2"); + test_template_ws_config!("test_trim.toml", "suppress", " 1{# #} 2", " 12"); + test_template_ws_config!( + "test_minimize.toml", + "preserve", + "\n1{# #}\n\n\n2", + "\n1\n\n\n2" + ); + test_template_ws_config!("test_minimize.toml", "suppress", "\n1{# #}\n\n\n2", "\n12"); +} -- cgit