From ff24eef1ff7dcf3849fd1e6d9efec0de2bc57005 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 28 Jan 2020 22:49:04 +0100 Subject: Move Iron integration into a separate askama_iron crate --- askama_iron/tests/basic.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 askama_iron/tests/basic.rs (limited to 'askama_iron/tests') diff --git a/askama_iron/tests/basic.rs b/askama_iron/tests/basic.rs new file mode 100644 index 0000000..32ca839 --- /dev/null +++ b/askama_iron/tests/basic.rs @@ -0,0 +1,36 @@ +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::().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::(); + assert_eq!(content_type, None); +} -- cgit