From 5cad82f38e800a42717284f20e7e0923add1e32f Mon Sep 17 00:00:00 2001 From: max Date: Mon, 11 Dec 2023 16:43:16 +0200 Subject: Allow included templates to `extend`, `import`, and `macro` Signed-off-by: max --- testing/tests/include.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'testing/tests') diff --git a/testing/tests/include.rs b/testing/tests/include.rs index f461a7b..c11d96f 100644 --- a/testing/tests/include.rs +++ b/testing/tests/include.rs @@ -12,3 +12,44 @@ fn test_include() { let s = IncludeTemplate { strs: &strs }; assert_eq!(s.render().unwrap(), "\n INCLUDED: foo\n INCLUDED: bar") } + +#[derive(Template)] +#[template(path = "include-extends.html")] +struct IncludeExtendsTemplate<'a> { + name: &'a str, +} + +#[test] +fn test_include_extends() { + let template = IncludeExtendsTemplate { name: "Alice" }; + + assert_eq!( + template.render().unwrap(), + "
\n \ +

Welcome

\n \ +
\n \ +

Below me is the header

\n \ + foo\n \ +

Above me is the header

\n\ +
\n\ + Hello, Alice!\n\ +
" + ); +} + +#[derive(Template)] +#[template(path = "include-macro.html")] +struct IncludeMacroTemplate<'a> { + name: &'a str, + name2: &'a str, +} + +#[test] +fn test_include_macro() { + let template = IncludeMacroTemplate { + name: "Alice", + name2: "Bob", + }; + + assert_eq!(template.render().unwrap(), "Hello, Alice!\nHowdy, Bob!"); +} -- cgit