diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-03-06 21:52:14 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-03-09 13:35:00 +0100 |
commit | 4233b3114fd9db8a036b1744d1ddec070e37d145 (patch) | |
tree | 2a07e3fa882fd342cbb55a6153843c883f5129af /testing/tests/whitespace.rs | |
parent | ca083f59fcf151725b4f86719674a153fded4eb5 (diff) | |
download | askama-4233b3114fd9db8a036b1744d1ddec070e37d145.tar.gz askama-4233b3114fd9db8a036b1744d1ddec070e37d145.tar.bz2 askama-4233b3114fd9db8a036b1744d1ddec070e37d145.zip |
Update tests for whitespace characters handling
Diffstat (limited to 'testing/tests/whitespace.rs')
-rw-r--r-- | testing/tests/whitespace.rs | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/testing/tests/whitespace.rs b/testing/tests/whitespace.rs index d38fdaa..4793547 100644 --- a/testing/tests/whitespace.rs +++ b/testing/tests/whitespace.rs @@ -66,21 +66,53 @@ macro_rules! test_template { fn test_minimize_whitespace() { test_template_minimize!( "\n1\r\n{% if true %}\n\n2\r\n\r\n{% endif %} 3\r\n\r\n\r\n", - "\n1\n\n2\n 3" + "\n1\n\n2\n 3\r\n\r\n\r\n" ); test_template_minimize!( "\n1\r\n{%+ if true %}\n\n2\r\n\r\n{% endif %} 3\r\n\r\n\r\n", - "\n1\r\n\n2\n 3" + "\n1\r\n\n2\n 3\r\n\r\n\r\n" ); test_template_minimize!( "\n1\r\n{%- if true %}\n\n2\r\n\r\n{% endif %} 3\r\n\r\n\r\n", - "\n1\n2\n 3" + "\n1\n2\n 3\r\n\r\n\r\n" ); - test_template_minimize!(" \n1 \n{% if true %} 2 {% endif %}3 ", " \n1\n 2 3"); + test_template_minimize!(" \n1 \n{% if true %} 2 {% endif %}3 ", " \n1\n 2 3 "); test_template!( "\n1\r\n{%~ if true ~%}\n\n2\r\n\r\n{%~ endif ~%} 3\r\n\r\n\r\n", - "\n1\n\n2\n 3" + "\n1\n\n2\n 3\r\n\r\n\r\n" ); - test_template!(" \n1 \n{%~ if true ~%} 2 {%~ endif ~%}3 ", " \n1\n 2 3"); + test_template!( + " \n1 \n{%~ if true ~%} 2 {%~ endif ~%}3 ", + " \n1\n 2 3 " + ); +} + +macro_rules! test_template_config { + ($config:literal, $source:literal, $rendered: literal) => {{ + #[derive(Template)] + #[template(source = $source, ext = "txt", config = $config)] + struct CondWs; + + assert_eq!(CondWs.render().unwrap(), $rendered); + }}; +} + +#[test] +fn test_outer_whitespace() { + test_template_config!("test_trim.toml", "\t1\t\t", "\t1\t\t"); + test_template_config!("test_trim.toml", " 1 ", " 1 "); + test_template_config!("test_trim.toml", "\n1\n\n\n", "\n1\n\n\n"); + test_template_config!("test_trim.toml", "\t1{# #}\t", "\t1"); + test_template_config!("test_trim.toml", " 1{# #} ", " 1"); + test_template_config!("test_trim.toml", "\n1{# #}\n\n\n", "\n1"); + test_template_minimize!("\t1{# #} ", "\t1 "); + test_template_minimize!("\t1{# #}\t", "\t1 "); + test_template_minimize!("\t1{# #} ", "\t1 "); + test_template_minimize!("\t1{# #}\t\t", "\t1 "); + test_template_minimize!(" 1{# #} ", " 1 "); + test_template_minimize!("\n1{# #}\n\n\n", "\n1\n"); + test_template!("\t1{# #}\t", "\t1\t"); + test_template!(" 1{# #} ", " 1 "); + test_template!("\n1{# #}\n\n\n", "\n1\n\n\n"); } |