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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#![allow(clippy::disallowed_names)]
use askama::Template;
#[derive(Template)]
#[template(path = "compare.html")]
struct CompareTemplate {
a: usize,
b: usize,
c: usize,
}
#[test]
fn test_compare() {
let t = CompareTemplate { a: 1, b: 1, c: 2 };
assert_eq!(t.render().unwrap(), "tf\ntf\ntf\ntf\ntf\ntf");
}
#[derive(Template)]
#[template(path = "operators.html")]
struct OperatorsTemplate {
a: usize,
b: usize,
c: usize,
}
#[test]
fn test_operators() {
let t = OperatorsTemplate { a: 1, b: 1, c: 2 };
assert_eq!(t.render().unwrap(), "muldivmodaddrshlshbandbxorborandor");
}
#[derive(Template)]
#[template(path = "precedence.html")]
struct PrecedenceTemplate {}
#[test]
fn test_precedence() {
let t = PrecedenceTemplate {};
assert_eq!(t.render().unwrap(), "6".repeat(7));
}
#[derive(Template)]
#[template(path = "ranges.txt")]
struct RangesTemplate<'a> {
foo: Vec<&'a str>,
}
#[test]
fn test_ranges() {
let t = RangesTemplate {
foo: vec!["a", "b", "c", "d"],
};
assert_eq!(t.render().unwrap(), "abcd\nbcd\n\na\nab");
}
#[derive(Template)]
#[template(source = "{{ true && true }}{{ false || true }}", ext = "txt")]
struct ShortCircuitTemplate {}
#[test]
fn test_short_circuit() {
let t = ShortCircuitTemplate {};
assert_eq!(t.render().unwrap(), "truetrue");
}
|