mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
56 lines
1.1 KiB
Rust
56 lines
1.1 KiB
Rust
use askama::Template;
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "macro.html")]
|
|
struct MacroTemplate<'a> {
|
|
s: &'a str,
|
|
}
|
|
|
|
#[test]
|
|
fn test_macro() {
|
|
let t = MacroTemplate { s: "foo" };
|
|
assert_eq!(t.render().unwrap(), "12foo foo foo3");
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "import.html")]
|
|
struct ImportTemplate<'a> {
|
|
s: &'a str,
|
|
}
|
|
|
|
#[test]
|
|
fn test_import() {
|
|
let t = ImportTemplate { s: "foo" };
|
|
assert_eq!(t.render().unwrap(), "foo foo foo");
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "deep-nested-macro.html")]
|
|
struct NestedTemplate;
|
|
|
|
#[test]
|
|
fn test_nested() {
|
|
let t = NestedTemplate;
|
|
assert_eq!(t.render().unwrap(), "foo");
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "deep-import-parent.html")]
|
|
struct DeepImportTemplate;
|
|
|
|
#[test]
|
|
fn test_deep_import() {
|
|
let t = DeepImportTemplate;
|
|
assert_eq!(t.render().unwrap(), "foo");
|
|
}
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "macro-short-circuit.html")]
|
|
struct ShortCircuitTemplate {}
|
|
|
|
#[test]
|
|
fn test_short_circuit() {
|
|
let t = ShortCircuitTemplate {};
|
|
assert_eq!(t.render().unwrap(), "truetruetruefalsetruetrue");
|
|
}
|