From 28cf6bf29b4d0e88f8fcd2ded52d9bca03149df9 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 19 Oct 2012 11:26:58 -0500 Subject: add test for loading just the syntax on its own --- t/mustache-spec-syntax-only.t | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 t/mustache-spec-syntax-only.t (limited to 't/mustache-spec-syntax-only.t') 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; -- cgit v1.2.3