From 5f753f44ba7f37c744f46f8c0334c70a05f8281b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 2 Oct 2012 16:30:06 -0500 Subject: clean up helpers test --- t/helpers.t | 79 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 39 deletions(-) (limited to 't') 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( - '

{{title}}

{{#noop}}{{body}}{{/noop}}

', - { 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); + }, + }, + }, + '

{{title}}

{{#noop}}{{body}}{{/noop}}

', + { title => 'A', body => 'the first letter' }, '

A

the first letter

', + "noop helper" ); -Handlebars->registerHelper(list => sub { - my ($items, $options) = @_; - my $out = ""; -}); - -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 = ""; + }, + }, + }, + '{{#list people}}{{firstName}} {{lastName}}{{/list}}', + { people => [ + { firstName => 'Jesse', lastName => 'Luehrs' }, + { firstName => 'Shawn', lastName => 'Moore' }, + { firstName => 'Stevan', lastName => 'Little' }, + ] }, '', + "helpers with arguments" ); +} done_testing; -- cgit v1.2.3