From 17d50c83f2a4be7405fa151fb66620c132b01f0f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 4 Oct 2012 18:21:30 -0500 Subject: implement the built-in block helpers --- t/block-helper-builtins.t | 178 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 t/block-helper-builtins.t (limited to 't') diff --git a/t/block-helper-builtins.t b/t/block-helper-builtins.t new file mode 100644 index 0000000..338e067 --- /dev/null +++ b/t/block-helper-builtins.t @@ -0,0 +1,178 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use lib 't/lib'; +use Test::More; +use Test::Handlebars; + +render_ok( + <<'TEMPLATE', +
+

{{title}}

+ + {{#with author}} +

By {{firstName}} {{lastName}}

+ {{/with}} +
+TEMPLATE + { + title => 'My first post!', + author => { + firstName => 'Charles', + lastName => 'Jolley', + }, + }, + <<'RENDERED', +
+

My first post!

+ +

By Charles Jolley

+
+RENDERED + "with helper" +); + +{ local $TODO = "unimplemented"; local $SIG{__WARN__} = sub { }; +render_ok( + <<'TEMPLATE', + +TEMPLATE + { + people => [ + "Yehuda Katz", + "Alan Johnson", + "Charles Jolley", + ], + }, + <<'RENDERED', + +RENDERED + "each helper" +); +} + +render_ok( + <<'TEMPLATE', +
+ {{#if author}} +

{{firstName}} {{lastName}}

+ {{/if}} +
+TEMPLATE + {}, + <<'RENDERED', +
+
+RENDERED + "if helper (false)" +); + +render_ok( + <<'TEMPLATE', +
+ {{#if author}} +

{{firstName}} {{lastName}}

+ {{/if}} +
+TEMPLATE + { + author => 1, + firstName => "Yehuda", + lastName => "Katz", + }, + <<'RENDERED', +
+

Yehuda Katz

+
+RENDERED + "if helper (true)" +); + +{ local $TODO = "unimplemented"; +render_ok( + <<'TEMPLATE', +
+ {{#if author}} +

{{firstName}} {{lastName}}

+ {{else}} +

Unknown Author

+ {{/if}} +
+TEMPLATE + {}, + <<'RENDERED', +
+

Unknown Author

+
+RENDERED + "if/else helper (false)" +); + +render_ok( + <<'TEMPLATE', +
+ {{#if author}} +

{{firstName}} {{lastName}}

+ {{else}} +

Unknown Author

+ {{/if}} +
+TEMPLATE + { + author => 1, + firstName => "Yehuda", + lastName => "Katz", + }, + <<'RENDERED', +
+

Yehuda Katz

+
+RENDERED + "if/else helper (true)" +); +} + +render_ok( + <<'TEMPLATE', +
+ {{#unless license}} +

WARNING: This entry does not have a license!

+ {{/unless}} +
+TEMPLATE + {}, + <<'RENDERED', +
+

WARNING: This entry does not have a license!

+
+RENDERED + "unless helper (false)" +); + +render_ok( + <<'TEMPLATE', +
+ {{#unless license}} +

WARNING: This entry does not have a license!

+ {{/unless}} +
+TEMPLATE + { + license => 1, + }, + <<'RENDERED', +
+
+RENDERED + "unless helper (true)" +); + +done_testing; -- cgit v1.2.3