blob: b8a6c980c9005cc810d6634f0be2bd010ff0379d (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#[macro_use]
extern crate askama;
use askama::Template;
#[derive(Template)]
#[template(path = "match-opt.html")]
struct MatchOptTemplate<'a> {
item: Option<&'a str>,
}
#[derive(Template)]
#[template(path = "match-opt.html")]
struct MatchOptRefTemplate<'a> {
item: &'a Option<&'a str>,
}
#[test]
fn test_match_option() {
let s = MatchOptTemplate { item: Some("foo") };
assert_eq!(s.render().unwrap(), "\n\nFound literal foo\n");
let s = MatchOptTemplate { item: Some("bar") };
assert_eq!(s.render().unwrap(), "\n\nFound bar\n");
let s = MatchOptTemplate { item: None };
assert_eq!(s.render().unwrap(), "\n\nNot Found\n");
}
#[test]
fn test_match_ref_deref() {
let s = MatchOptRefTemplate { item: &Some("foo") };
assert_eq!(s.render().unwrap(), "\n\nFound literal foo\n");
}
#[derive(Template)]
#[template(path = "match-literal.html")]
struct MatchLitTemplate<'a> {
item: &'a str,
}
#[test]
fn test_match_literal() {
let s = MatchLitTemplate { item: "bar" };
assert_eq!(s.render().unwrap(), "\n\nFound literal bar\n");
let s = MatchLitTemplate { item: "qux" };
assert_eq!(s.render().unwrap(), "\n\nElse found qux\n");
}
#[derive(Template)]
#[template(path = "match-literal-num.html")]
struct MatchLitNumTemplate {
item: u32,
}
#[test]
fn test_match_literal_num() {
let s = MatchLitNumTemplate { item: 42 };
assert_eq!(s.render().unwrap(), "\n\nFound answer to everything\n");
let s = MatchLitNumTemplate { item: 23 };
assert_eq!(s.render().unwrap(), "\n\nElse found 23\n");
}
|