summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-02 16:30:06 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-02 16:30:06 -0500
commit5f753f44ba7f37c744f46f8c0334c70a05f8281b (patch)
treebb688e3540a05ea7cb51ba8723965cb1aff1c8ec /t
parentfa8c5a1f9e8dd17424bc28d01bfe661dde50ddd7 (diff)
downloadtext-handlebars-5f753f44ba7f37c744f46f8c0334c70a05f8281b.tar.gz
text-handlebars-5f753f44ba7f37c744f46f8c0334c70a05f8281b.zip
clean up helpers test
Diffstat (limited to 't')
-rw-r--r--t/helpers.t79
1 files changed, 40 insertions, 39 deletions
diff --git a/t/helpers.t b/t/helpers.t
index 7286371..ad601e9 100644
--- a/t/helpers.t
+++ b/t/helpers.t
@@ -1,49 +1,50 @@
+#!/usr/bin/env perl
use strict;
use warnings;
+use lib 't/lib';
use Test::More;
-use Text::Xslate;
-
-plan skip_all => "unimplemented";
-
-my $tx = Text::Xslate->new(syntax => 'Handlebars');
-
-# XXX I'm not sure how helpers should be registered in Perl
-# in JS, it's global which is crappy
-# Text::Xslate->new has a "function" parameter for registering helpers
-Handlebars->registerHelper(noop => sub {
- my ($context, $options) = @_;
- return $options->{fn}->($context);
-});
-
-is(
- $tx->render_string(
- '<h1>{{title}}</h1><p>{{#noop}}{{body}}{{/noop}}</p>',
- { title => 'A', body => 'the first letter' },
- ),
+use Test::Handlebars;
+
+{ local $TODO = "unimplemented"; local $SIG{__WARN__} = sub { };
+render_ok(
+ {
+ helpers => {
+ noop => sub {
+ my ($context, $options) = @_;
+ return $options->{fn}->($context);
+ },
+ },
+ },
+ '<h1>{{title}}</h1><p>{{#noop}}{{body}}{{/noop}}</p>',
+ { title => 'A', body => 'the first letter' },
'<h1>A</h1><p>the first letter</p>',
+ "noop helper"
);
-Handlebars->registerHelper(list => sub {
- my ($items, $options) = @_;
- my $out = "<ul>";
-
- for my $item (@$items) {
- $out .= "<li>" . $options->{fn}->($item) . "</li>";
- }
-
- return $out . "</ul>";
-});
-
-is(
- $tx->render_string(
- '{{#list people}}{{firstName}} {{lastName}}{{/list}}',
- { people => [
- { firstName => 'Jesse', lastName => 'Luehrs' },
- { firstName => 'Shawn', lastName => 'Moore' },
- { firstName => 'Stevan', lastName => 'Little' },
- ] },
- ),
+render_ok(
+ {
+ helpers => {
+ list => sub {
+ my ($items, $options) = @_;
+ my $out = "<ul>";
+
+ for my $item (@$items) {
+ $out .= "<li>" . $options->{fn}->($item) . "</li>";
+ }
+
+ return $out . "</ul>";
+ },
+ },
+ },
+ '{{#list people}}{{firstName}} {{lastName}}{{/list}}',
+ { people => [
+ { firstName => 'Jesse', lastName => 'Luehrs' },
+ { firstName => 'Shawn', lastName => 'Moore' },
+ { firstName => 'Stevan', lastName => 'Little' },
+ ] },
'<ul><li>Jesse Luehrs</li><li>Shawn Moore</li><li>Stevan Little</li></ul>',
+ "helpers with arguments"
);
+}
done_testing;