summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-19 11:26:58 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-19 11:26:58 -0500
commit28cf6bf29b4d0e88f8fcd2ded52d9bca03149df9 (patch)
tree80f0e4445b92455972f05e50d2619c8d894360ce /t
parent481b04ace765135c4b990e90a0b872fa23f286f0 (diff)
downloadtext-handlebars-xslate-more-opcodes.tar.gz
text-handlebars-xslate-more-opcodes.zip
add test for loading just the syntax on its ownxslate-more-opcodes
Diffstat (limited to 't')
-rw-r--r--t/lib/Test/Handlebars.pm5
-rw-r--r--t/mustache-spec-syntax-only.t63
-rw-r--r--t/mustache-spec.t17
3 files changed, 75 insertions, 10 deletions
diff --git a/t/lib/Test/Handlebars.pm b/t/lib/Test/Handlebars.pm
index ececc41..c0f0da3 100644
--- a/t/lib/Test/Handlebars.pm
+++ b/t/lib/Test/Handlebars.pm
@@ -36,8 +36,11 @@ sub _render_ok {
my ($template, $env, $expected, $desc) = @_;
$opts->{cache} = 0;
+ my $create = delete $opts->{__create} || sub {
+ Text::Handlebars->new(%{ $_[0] });
+ };
- my $tx = Text::Handlebars->new(%$opts);
+ my $tx = $create->($opts);
my $exception = exception {
local $Test::Builder::Level = $Test::Builder::Level + 5;
diff --git a/t/mustache-spec-syntax-only.t b/t/mustache-spec-syntax-only.t
new file mode 100644
index 0000000..d636e6e
--- /dev/null
+++ b/t/mustache-spec-syntax-only.t
@@ -0,0 +1,63 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More;
+use Test::Handlebars;
+
+use Test::Requires 'JSON', 'Path::Class';
+
+for my $file (dir('t', 'mustache-spec', 'specs')->children) {
+ next unless $file =~ /\.json$/;
+ my $tests = decode_json($file->slurp);
+ note("running " . $file->basename . " tests");
+ for my $test (@{ $tests->{tests} }) {
+ local $TODO = "unimplemented"
+ if $file->basename eq 'partials.json'
+ && $test->{name} =~ /standalone/i
+ && $test->{name} !~ /line endings/i;
+
+ my $opts = {
+ suffix => '.mustache',
+ path => [
+ map { +{ "$_.mustache" => $test->{partials}{$_} } }
+ keys %{ $test->{partials} }
+ ],
+ __create => sub {
+ Text::Xslate->new(
+ syntax => 'Handlebars',
+ compiler => 'Text::Handlebars::Compiler', # XXX
+ %{ $_[0] },
+ );
+ },
+ };
+ render_ok(
+ $opts,
+ $test->{template},
+ 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;
diff --git a/t/mustache-spec.t b/t/mustache-spec.t
index ae69af5..abf51b7 100644
--- a/t/mustache-spec.t
+++ b/t/mustache-spec.t
@@ -17,16 +17,15 @@ for my $file (dir('t', 'mustache-spec', 'specs')->children) {
&& $test->{name} =~ /standalone/i
&& $test->{name} !~ /line endings/i;
+ my $opts = {
+ suffix => '.mustache',
+ path => [
+ map { +{ "$_.mustache" => $test->{partials}{$_} } }
+ keys %{ $test->{partials} }
+ ],
+ };
render_ok(
- ($test->{partials}
- ? ({
- suffix => '.mustache',
- path => [
- map { +{ "$_.mustache" => $test->{partials}{$_} } }
- keys %{ $test->{partials} }
- ]
- })
- : ()),
+ $opts,
$test->{template},
fix_data($test->{data}),
$test->{expected},