diff options
| author | 2020-05-25 16:32:32 +0300 | |
|---|---|---|
| committer | 2020-06-30 14:12:50 +0200 | |
| commit | af2fd0b8dc0894fdb96656351bf2015d4df73813 (patch) | |
| tree | 1697a641ce1670cf0959a09319c0ba049ed1ae3b /testing/tests | |
| parent | e71e6806496027089b5c3f0dd764bebe9abbf735 (diff) | |
| download | askama-af2fd0b8dc0894fdb96656351bf2015d4df73813.tar.gz askama-af2fd0b8dc0894fdb96656351bf2015d4df73813.tar.bz2 askama-af2fd0b8dc0894fdb96656351bf2015d4df73813.zip  | |
Add tests for allow whitespaces patch
Diffstat (limited to '')
| -rw-r--r-- | testing/tests/whitespace.rs | 41 | 
1 files changed, 41 insertions, 0 deletions
diff --git a/testing/tests/whitespace.rs b/testing/tests/whitespace.rs new file mode 100644 index 0000000..befc7d1 --- /dev/null +++ b/testing/tests/whitespace.rs @@ -0,0 +1,41 @@ +use askama::Template; + +#[derive(askama::Template, Default)] +#[template(path = "allow-whitespaces.html")] +struct AllowWhitespaces { +    tuple: (u64, u64, u64, u64), +    string: &'static str, +    option: Option<bool>, +    nested_1: AllowWhitespacesNested1, +} + +#[derive(Default)] +struct AllowWhitespacesNested1 { +    nested_2: AllowWhitespacesNested2, +} + +#[derive(Default)] +struct AllowWhitespacesNested2 { +    array: &'static [&'static str], +    hash: std::collections::HashMap<&'static str, &'static str>, +} + +impl AllowWhitespaces { +    fn f0(&self) -> &str { +        "" +    } +    fn f1(&self, _a: &str) -> &str { +        "" +    } +    fn f2(&self, _a: &str, _b: &str) -> &str { +        "" +    } +} + +#[test] +fn test_extra_whitespace() { +    let mut template = AllowWhitespaces::default(); +    template.nested_1.nested_2.array = &["a0", "a1", "a2", "a3"]; +    template.nested_1.nested_2.hash.insert("key", "value"); +    assert_eq!(template.render().unwrap(), "\n0\n0\n0\n0\n\n\n\n0\n0\n0\n0\n0\n\na0\na1\nvalue\n\n\n\n\n\n[\n  \"a0\",\n  \"a1\",\n  \"a2\",\n  \"a3\"\n]\n[\n  \"a0\",\n  \"a1\",\n  \"a2\",\n  \"a3\"\n][\n  \"a0\",\n  \"a1\",\n  \"a2\",\n  \"a3\"\n]\n[\n  \"a1\"\n][\n  \"a1\"\n]\n[\n  \"a1\",\n  \"a2\"\n][\n  \"a1\",\n  \"a2\"\n]\n[][]1-1-1\n3333 3\n2222 2\n0000 0\n3333 3\n\ntruefalse\nfalsefalsefalse\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); +}  | 
