aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests/size_hint.rs
diff options
context:
space:
mode:
authorLibravatar Andrew Dona-Couch -- GitHub drop ICE <hi@andrewcou.ch>2023-03-06 16:18:45 -0500
committerLibravatar GitHub <noreply@github.com>2023-03-06 22:18:45 +0100
commitdc864486ec8c258388b4e006d9517e6e30c34a4d (patch)
tree4419a02845917440f2846880ddf872a649b50373 /testing/tests/size_hint.rs
parent417cb924ae1f94d54e2eb13ebc7e9fab91b84588 (diff)
downloadaskama-dc864486ec8c258388b4e006d9517e6e30c34a4d.tar.gz
askama-dc864486ec8c258388b4e006d9517e6e30c34a4d.tar.bz2
askama-dc864486ec8c258388b4e006d9517e6e30c34a4d.zip
Propogate size_hint from sub-blocks (#788)
Closes #786
Diffstat (limited to 'testing/tests/size_hint.rs')
-rw-r--r--testing/tests/size_hint.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/testing/tests/size_hint.rs b/testing/tests/size_hint.rs
new file mode 100644
index 0000000..a9f8428
--- /dev/null
+++ b/testing/tests/size_hint.rs
@@ -0,0 +1,47 @@
+use askama::Template;
+
+macro_rules! test_size {
+ ($source:literal, $expected:expr) => {{
+ #[derive(Template)]
+ #[template(source = $source, ext = "txt")]
+ struct T(bool);
+
+ assert_eq!(T::SIZE_HINT, $expected);
+ }};
+}
+
+#[test]
+fn test_cond_size_hint() {
+ test_size!("{% if self.0 %}12345{% else %}12345{% endif %}", 10);
+}
+
+#[test]
+fn test_match_size_hint() {
+ test_size!(
+ "{% match self.0 %}{% when true %}12345{% else %}12345{% endmatch %}",
+ 5
+ );
+}
+
+#[test]
+fn test_loop_size_hint() {
+ test_size!("{% for i in 0..1 %}12345{% endfor %}", 7);
+}
+
+#[test]
+fn test_block_size_hint() {
+ #[derive(Template)]
+ #[template(path = "size-child.txt")]
+ struct T;
+
+ assert_eq!(T::SIZE_HINT, 3);
+}
+
+#[test]
+fn test_super_size_hint() {
+ #[derive(Template)]
+ #[template(path = "size-child-super.txt")]
+ struct T;
+
+ assert_eq!(T::SIZE_HINT, 5);
+}