summaryrefslogtreecommitdiffstats
path: root/t/mustache-spec.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-03 15:05:25 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-03 15:08:29 -0500
commitb6b1bd1936ea207c74ecf0993bd3b7c55c71ec57 (patch)
tree6c67d41ca8ceedb1daeecce1fec877a46108e7e1 /t/mustache-spec.t
parentbbec479a424eda0bc48250c118aaad85ddb6ee00 (diff)
downloadtext-handlebars-b6b1bd1936ea207c74ecf0993bd3b7c55c71ec57.tar.gz
text-handlebars-b6b1bd1936ea207c74ecf0993bd3b7c55c71ec57.zip
make basic lambdas work (not block lambdas yet)
Diffstat (limited to 't/mustache-spec.t')
-rw-r--r--t/mustache-spec.t25
1 files changed, 23 insertions, 2 deletions
diff --git a/t/mustache-spec.t b/t/mustache-spec.t
index 3713abc..8ee1c10 100644
--- a/t/mustache-spec.t
+++ b/t/mustache-spec.t
@@ -9,7 +9,6 @@ use Test::Requires 'JSON', 'Path::Class';
for my $file (dir('t', 'mustache-spec', 'specs')->children) {
next unless $file =~ /\.json$/;
- next if $file->basename =~ /^~/; # for now
next if $file->basename =~ /partials/;
my $tests = decode_json($file->slurp);
note("running " . $file->basename . " tests");
@@ -17,14 +16,36 @@ for my $file (dir('t', 'mustache-spec', 'specs')->children) {
local $TODO = "unimplemented"
if $file->basename eq 'delimiters.json'
&& $test->{name} =~ /partial/i;
+ local ($TODO, $SIG{__WARN__}) = ("unimplemented", sub { })
+ if $file->basename eq '~lambdas.json'
+ && $test->{name} =~ /section/i;
render_ok(
$test->{template},
- $test->{data},
+ fix_data($test->{data}),
$test->{expected},
"$test->{name}: $test->{desc}"
);
}
}
+sub fix_data {
+ my ($data) = @_;
+
+ if (ref($data) eq 'HASH') {
+ if ($data->{__tag__} && $data->{__tag__} eq 'code') {
+ return eval $data->{perl};
+ }
+ else {
+ return { map { $_ => fix_data($data->{$_}) } keys %$data };
+ }
+ }
+ elsif (ref($data) eq 'ARRAY') {
+ return [ map { fix_data($_) } @$data ];
+ }
+ else {
+ return $data;
+ }
+}
+
done_testing;