aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests/size_hint.rs
blob: a9f84286a608b8ca3ce5ff9f4ac7fecb9d691809 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use askama::Template;

macro_rules! test_size {
    ($source:literal, $expected:expr) => {{
        #[derive(Template)]
        #[template(source = $source, ext = "txt")]
        struct T(bool);

        assert_eq!(T::SIZE_HINT, $expected);
    }};
}

#[test]
fn test_cond_size_hint() {
    test_size!("{% if self.0 %}12345{% else %}12345{% endif %}", 10);
}

#[test]
fn test_match_size_hint() {
    test_size!(
        "{% match self.0 %}{% when true %}12345{% else %}12345{% endmatch %}",
        5
    );
}

#[test]
fn test_loop_size_hint() {
    test_size!("{% for i in 0..1 %}12345{% endfor %}", 7);
}

#[test]
fn test_block_size_hint() {
    #[derive(Template)]
    #[template(path = "size-child.txt")]
    struct T;

    assert_eq!(T::SIZE_HINT, 3);
}

#[test]
fn test_super_size_hint() {
    #[derive(Template)]
    #[template(path = "size-child-super.txt")]
    struct T;

    assert_eq!(T::SIZE_HINT, 5);
}