From 06e0702a2a0ff0be0851ccb011df516d49047888 Mon Sep 17 00:00:00 2001 From: vallentin Date: Mon, 11 Jan 2021 19:48:37 +0100 Subject: [PATCH] Added constants test --- testing/tests/simple.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index 0c6b17e01..c179b5a62 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -72,6 +72,36 @@ fn test_variables_no_escape() { ); } +const FOO: &str = "FOO"; +const FOO_BAR: &str = "FOO BAR"; + +#[derive(Template)] +#[template( + source = "{{ foo }} {{ foo_bar }} {{ FOO }} {{ FOO_BAR }} {{ self::FOO }} {{ self::FOO_BAR }} {{ Self::BAR }} {{ Self::BAR_BAZ }}", + ext = "txt" +)] +struct ConstTemplate { + foo: &'static str, + foo_bar: &'static str, +} + +impl ConstTemplate { + const BAR: &'static str = "BAR"; + const BAR_BAZ: &'static str = "BAR BAZ"; +} + +#[test] +fn test_constants() { + let t = ConstTemplate { + foo: "foo", + foo_bar: "foo bar", + }; + assert_eq!( + t.render().unwrap(), + "foo foo bar FOO FOO BAR FOO FOO BAR BAR BAR BAZ" + ); +} + #[derive(Template)] #[template(path = "if.html")] struct IfTemplate {