From 6a0925c2c2028654fe8facb9f4388352b8d380d6 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 4 Oct 2012 17:41:58 -0500 Subject: rename this test --- t/block-helpers.t | 378 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ t/helpers.t | 378 ------------------------------------------------------ 2 files changed, 378 insertions(+), 378 deletions(-) create mode 100644 t/block-helpers.t delete mode 100644 t/helpers.t (limited to 't') diff --git a/t/block-helpers.t b/t/block-helpers.t new file mode 100644 index 0000000..50f3fe0 --- /dev/null +++ b/t/block-helpers.t @@ -0,0 +1,378 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use lib 't/lib'; +use Test::More; +use Test::Handlebars; + +render_ok( + { + function => { + noop => sub { + my ($context, $options) = @_; + return $options->{fn}->($context); + }, + }, + }, + <<'TEMPLATE', +
+

{{title}}

+
+ {{#noop}}{{body}}{{/noop}} +
+
+TEMPLATE + { title => 'A', body => 'the first letter' }, + <<'RENDERED', +
+

A

+
+ the first letter +
+
+RENDERED + "noop helper" +); + +render_ok( + { + function => { + with => sub { + my ($context, $new_context, $options) = @_; + return $options->{fn}->($new_context); + }, + }, + }, + <<'TEMPLATE', +
+

{{title}}

+ {{#with story}} +
{{{intro}}}
+
{{{body}}}
+ {{/with}} +
+TEMPLATE + { + title => 'First Post', + story => { + intro => 'Before the jump', + body => 'After the jump', + }, + }, + <<'RENDERED', +
+

First Post

+
Before the jump
+
After the jump
+
+RENDERED + "with helper" +); + +render_ok( + { + function => { + with => sub { + my ($context, $new_context, $options) = @_; + return $options->{fn}->($new_context); + }, + each => sub { + my ($context, $list, $options) = @_; + + my $ret = ''; + for my $new_context (@$list) { + $ret .= $options->{fn}->($new_context); + } + + return $ret; + }, + }, + }, + <<'TEMPLATE', +
+

{{title}}

+ {{#with story}} +
{{{intro}}}
+
{{{body}}}
+ {{/with}} +
+
+ {{#each comments}} +
+

{{subject}}

+ {{{body}}} +
+ {{/each}} +
+TEMPLATE + { + title => 'First Post', + story => { + intro => 'Before the jump', + body => 'After the jump', + }, + comments => [ + { subject => "Subject A", body => "Body A" }, + { subject => "Subject B", body => "Body B" }, + ], + }, + <<'RENDERED', +
+

First Post

+
Before the jump
+
After the jump
+
+
+
+

Subject A

+ Body A +
+
+

Subject B

+ Body B +
+
+RENDERED + "each helper" +); + +render_ok( + { + function => { + list => sub { + my ($context, $items, $options) = @_; + my $out = "\n"; + }, + }, + }, + <<'TEMPLATE', +{{#list nav}} + {{title}} +{{/list}} +TEMPLATE + { + nav => [ + { + url => 'http://www.yehudakatz.com', + title => 'Katz Got Your Tongue', + }, + { + url => 'http://www.sproutcore.com/block', + title => 'SproutCore Blog', + }, + ], + }, + <<'RENDERED', + +RENDERED + "list helper" +); + +render_ok( + { + function => { + if => sub { + my ($context, $conditional, $options) = @_; + if ($conditional) { + return $options->{fn}->($context); + } + return ''; + }, + }, + }, + <<'TEMPLATE', +{{#if isActive}} + Active +{{/if}} +TEMPLATE + { + isActive => 1, + }, + <<'RENDERED', + Active +RENDERED + "if helper (true)" +); + +render_ok( + { + function => { + if => sub { + my ($context, $conditional, $options) = @_; + if ($conditional) { + return $options->{fn}->($context); + } + return ''; + }, + }, + }, + <<'TEMPLATE', +{{#if isActive}} + Active +{{/if}} +TEMPLATE + { + isActive => 0, + }, + <<'RENDERED', +RENDERED + "if helper (false)" +); + +{ local $TODO = "unimplemented"; local $SIG{__WARN__} = sub { }; +render_ok( + { + function => { + if => sub { + my ($context, $conditional, $options) = @_; + if ($conditional) { + return $options->{fn}->($context); + } + else { + return $options->{inverse}->($context); + } + }, + }, + }, + <<'TEMPLATE', +{{#if isActive}} + Active +{{else}} + Inactive +{{/if}} +TEMPLATE + { + isActive => 1, + }, + <<'RENDERED', + Active +RENDERED + "if/else helper (true)" +); + +render_ok( + { + function => { + if => sub { + my ($context, $conditional, $options) = @_; + if ($conditional) { + return $options->{fn}->($context); + } + else { + return $options->{inverse}->($context); + } + }, + }, + }, + <<'TEMPLATE', +{{#if isActive}} + Active +{{else}} + Inactive +{{/if}} +TEMPLATE + { + isActive => 0, + }, + <<'RENDERED', + Inactive +RENDERED + "if/else helper (false)" +); + +render_ok( + { + function => { + list => sub { + my ($context, $items, $options) = @_; + + my $attrs = join ' ', map { $_ => $options->{hash}{$_} } + sort keys %{ $options->{hash} }; + + return ""; + }, + }, + }, + <<'TEMPLATE', +{{list nav id="nav-bar" class="top"}} + {{title}} +{{/list}} +TEMPLATE + { + nav => [ + { + url => 'http://www.yehudakatz.com', + title => 'Katz Got Your Tongue', + }, + { + url => 'http://www.sproutcore.com/block', + title => 'SproutCore Blog', + }, + ], + }, + <<'RENDERED', + +RENDERED + "helper arguments" +); + +render_ok( + { + function => { + list => sub { + my ($context, $items, $options) = @_; + + my $out = ""; + return $out; + }, + }, + }, + <<'TEMPLATE', +{{#list array}} + {{@index}}. {{title}} +{{/list}} +TEMPLATE + { + array => [ + "Foo", + "Bar", + "Baz", + ], + }, + <<'RENDERED', + +RENDERED + "helper private variables" +); +} + +done_testing; diff --git a/t/helpers.t b/t/helpers.t deleted file mode 100644 index 50f3fe0..0000000 --- a/t/helpers.t +++ /dev/null @@ -1,378 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; -use lib 't/lib'; -use Test::More; -use Test::Handlebars; - -render_ok( - { - function => { - noop => sub { - my ($context, $options) = @_; - return $options->{fn}->($context); - }, - }, - }, - <<'TEMPLATE', -
-

{{title}}

-
- {{#noop}}{{body}}{{/noop}} -
-
-TEMPLATE - { title => 'A', body => 'the first letter' }, - <<'RENDERED', -
-

A

-
- the first letter -
-
-RENDERED - "noop helper" -); - -render_ok( - { - function => { - with => sub { - my ($context, $new_context, $options) = @_; - return $options->{fn}->($new_context); - }, - }, - }, - <<'TEMPLATE', -
-

{{title}}

- {{#with story}} -
{{{intro}}}
-
{{{body}}}
- {{/with}} -
-TEMPLATE - { - title => 'First Post', - story => { - intro => 'Before the jump', - body => 'After the jump', - }, - }, - <<'RENDERED', -
-

First Post

-
Before the jump
-
After the jump
-
-RENDERED - "with helper" -); - -render_ok( - { - function => { - with => sub { - my ($context, $new_context, $options) = @_; - return $options->{fn}->($new_context); - }, - each => sub { - my ($context, $list, $options) = @_; - - my $ret = ''; - for my $new_context (@$list) { - $ret .= $options->{fn}->($new_context); - } - - return $ret; - }, - }, - }, - <<'TEMPLATE', -
-

{{title}}

- {{#with story}} -
{{{intro}}}
-
{{{body}}}
- {{/with}} -
-
- {{#each comments}} -
-

{{subject}}

- {{{body}}} -
- {{/each}} -
-TEMPLATE - { - title => 'First Post', - story => { - intro => 'Before the jump', - body => 'After the jump', - }, - comments => [ - { subject => "Subject A", body => "Body A" }, - { subject => "Subject B", body => "Body B" }, - ], - }, - <<'RENDERED', -
-

First Post

-
Before the jump
-
After the jump
-
-
-
-

Subject A

- Body A -
-
-

Subject B

- Body B -
-
-RENDERED - "each helper" -); - -render_ok( - { - function => { - list => sub { - my ($context, $items, $options) = @_; - my $out = "\n"; - }, - }, - }, - <<'TEMPLATE', -{{#list nav}} - {{title}} -{{/list}} -TEMPLATE - { - nav => [ - { - url => 'http://www.yehudakatz.com', - title => 'Katz Got Your Tongue', - }, - { - url => 'http://www.sproutcore.com/block', - title => 'SproutCore Blog', - }, - ], - }, - <<'RENDERED', - -RENDERED - "list helper" -); - -render_ok( - { - function => { - if => sub { - my ($context, $conditional, $options) = @_; - if ($conditional) { - return $options->{fn}->($context); - } - return ''; - }, - }, - }, - <<'TEMPLATE', -{{#if isActive}} - Active -{{/if}} -TEMPLATE - { - isActive => 1, - }, - <<'RENDERED', - Active -RENDERED - "if helper (true)" -); - -render_ok( - { - function => { - if => sub { - my ($context, $conditional, $options) = @_; - if ($conditional) { - return $options->{fn}->($context); - } - return ''; - }, - }, - }, - <<'TEMPLATE', -{{#if isActive}} - Active -{{/if}} -TEMPLATE - { - isActive => 0, - }, - <<'RENDERED', -RENDERED - "if helper (false)" -); - -{ local $TODO = "unimplemented"; local $SIG{__WARN__} = sub { }; -render_ok( - { - function => { - if => sub { - my ($context, $conditional, $options) = @_; - if ($conditional) { - return $options->{fn}->($context); - } - else { - return $options->{inverse}->($context); - } - }, - }, - }, - <<'TEMPLATE', -{{#if isActive}} - Active -{{else}} - Inactive -{{/if}} -TEMPLATE - { - isActive => 1, - }, - <<'RENDERED', - Active -RENDERED - "if/else helper (true)" -); - -render_ok( - { - function => { - if => sub { - my ($context, $conditional, $options) = @_; - if ($conditional) { - return $options->{fn}->($context); - } - else { - return $options->{inverse}->($context); - } - }, - }, - }, - <<'TEMPLATE', -{{#if isActive}} - Active -{{else}} - Inactive -{{/if}} -TEMPLATE - { - isActive => 0, - }, - <<'RENDERED', - Inactive -RENDERED - "if/else helper (false)" -); - -render_ok( - { - function => { - list => sub { - my ($context, $items, $options) = @_; - - my $attrs = join ' ', map { $_ => $options->{hash}{$_} } - sort keys %{ $options->{hash} }; - - return ""; - }, - }, - }, - <<'TEMPLATE', -{{list nav id="nav-bar" class="top"}} - {{title}} -{{/list}} -TEMPLATE - { - nav => [ - { - url => 'http://www.yehudakatz.com', - title => 'Katz Got Your Tongue', - }, - { - url => 'http://www.sproutcore.com/block', - title => 'SproutCore Blog', - }, - ], - }, - <<'RENDERED', - -RENDERED - "helper arguments" -); - -render_ok( - { - function => { - list => sub { - my ($context, $items, $options) = @_; - - my $out = ""; - return $out; - }, - }, - }, - <<'TEMPLATE', -{{#list array}} - {{@index}}. {{title}} -{{/list}} -TEMPLATE - { - array => [ - "Foo", - "Bar", - "Baz", - ], - }, - <<'RENDERED', - -RENDERED - "helper private variables" -); -} - -done_testing; -- cgit v1.2.3-54-g00ecf