blob: 95c366c3b7abedaf676e4bc138b9c7dfe5ae4fc8 (
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
|
#[macro_use]
extern crate askama;
extern crate iron;
use askama::Template;
use iron::{status, Response};
#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate<'a> {
name: &'a str,
}
#[derive(Template)]
#[template(path = "hello.txt")]
struct HelloTextTemplate<'a> {
name: &'a str,
}
#[test]
fn test_iron() {
let rsp = Response::with((status::Ok, HelloTemplate { name: "world" }));
let mut buf = Vec::new();
let _ = rsp.body.unwrap().write_body(&mut buf);
assert_eq!(buf, b"Hello, world!");
let content_type = rsp.headers.get::<iron::headers::ContentType>().unwrap();
assert_eq!(format!("{}", content_type), "text/html; charset=utf-8");
}
#[test]
fn test_iron_non_html() {
let rsp = Response::with((status::Ok, HelloTextTemplate { name: "world" }));
let mut buf = Vec::new();
let _ = rsp.body.unwrap().write_body(&mut buf);
assert_eq!(buf, b"Hello, world!");
let content_type = rsp.headers.get::<iron::headers::ContentType>();
assert_eq!(content_type, None);
}
|