summaryrefslogtreecommitdiffstats
path: root/t/block-helpers.t
diff options
context:
space:
mode:
Diffstat (limited to 't/block-helpers.t')
-rw-r--r--t/block-helpers.t94
1 files changed, 94 insertions, 0 deletions
diff --git a/t/block-helpers.t b/t/block-helpers.t
index 961b2dc..ac6f54f 100644
--- a/t/block-helpers.t
+++ b/t/block-helpers.t
@@ -375,4 +375,98 @@ RENDERED
);
}
+render_ok(
+ {
+ function => {
+ list => sub {
+ my ($context, $items, $options) = @_;
+
+ if (@$items) {
+ my $out = '<ul>';
+ for my $item (@$items) {
+ $out .= '<li>';
+ $out .= $options->{fn}->($item);
+ $out .= '</li>';
+ }
+ $out .= '</ul>';
+ return $out;
+ }
+ else {
+ return '<p>' . $options->{inverse}->($context) . '</p>';
+ }
+ },
+ },
+ },
+ q[{{#list people}}{{name}}{{^}}<em>Nobody's here</em>{{/list}}],
+ {
+ people => [
+ { name => 'Alan' },
+ { name => 'Yehuda' },
+ ],
+ },
+ q[<ul><li>Alan</li><li>Yehuda</li></ul>],
+ "helper with inverse"
+);
+
+render_ok(
+ {
+ function => {
+ list => sub {
+ my ($context, $items, $options) = @_;
+
+ if (@$items) {
+ my $out = '<ul>';
+ for my $item (@$items) {
+ $out .= '<li>';
+ $out .= $options->{fn}->($item);
+ $out .= '</li>';
+ }
+ $out .= '</ul>';
+ return $out;
+ }
+ else {
+ return '<p>' . $options->{inverse}->($context) . '</p>';
+ }
+ },
+ },
+ },
+ q[{{#list people}}{{name}}{{^}}<em>Nobody's here</em>{{/list}}],
+ {
+ people => [],
+ },
+ q[<p><em>Nobody's here</em></p>],
+ "helper with inverse (empty)"
+);
+
+render_ok(
+ {
+ function => {
+ list => sub {
+ my ($context, $items, $options) = @_;
+
+ if (@$items) {
+ my $out = '<ul>';
+ for my $item (@$items) {
+ $out .= '<li>';
+ $out .= $options->{fn}->($item);
+ $out .= '</li>';
+ }
+ $out .= '</ul>';
+ return $out;
+ }
+ else {
+ return '<p>' . $options->{inverse}->($context) . '</p>';
+ }
+ },
+ },
+ },
+ q[{{#list people}}Hello{{^}}{{message}}{{/list}}],
+ {
+ people => [],
+ message => "Nobody's here",
+ },
+ q[<p>Nobody&#39;s here</p>],
+ "helper with inverse (inverse has variables)"
+);
+
done_testing;