diff options
author | Jacob Rothstein <hi@jbr.me> | 2020-07-09 21:06:03 -0700 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-07-14 09:46:12 +0200 |
commit | 29cb90bceb59d9dbea94342dfdd8136e1ef494e6 (patch) | |
tree | 8d4d63527fbaa039ccf7f0982ff8849c238e68d3 /askama_tide/tests/tide.rs | |
parent | 0a6284aa91e1eb8da81d7b317fb539653e519d0a (diff) | |
download | askama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.tar.gz askama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.tar.bz2 askama-29cb90bceb59d9dbea94342dfdd8136e1ef494e6.zip |
askama tide
Diffstat (limited to '')
-rw-r--r-- | askama_tide/tests/tide.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/askama_tide/tests/tide.rs b/askama_tide/tests/tide.rs new file mode 100644 index 0000000..6fa1418 --- /dev/null +++ b/askama_tide/tests/tide.rs @@ -0,0 +1,29 @@ +use askama::Template; +use async_std::prelude::*; +use std::convert::TryInto; +use tide::{http::mime::HTML, Body, Response}; + +#[derive(Template)] +#[template(path = "hello.html")] +struct HelloTemplate<'a> { + name: &'a str, +} + +#[async_std::test] +async fn template_to_response() { + let mut res: Response = HelloTemplate { name: "world" }.into(); + assert_eq!(res.status(), 200); + assert_eq!(res.content_type(), Some(HTML)); + + let res: &mut tide::http::Response = res.as_mut(); + assert_eq!(res.body_string().await.unwrap(), "Hello, world!"); +} + +#[async_std::test] +async fn template_to_body() { + let mut body: Body = HelloTemplate { name: "world" }.try_into().unwrap(); + assert_eq!(body.mime(), &HTML); + let mut body_string = String::new(); + body.read_to_string(&mut body_string).await.unwrap(); + assert_eq!(body_string, "Hello, world!"); +} |