Dancer2-Template-TextTemplate
view release on metacpan or search on metacpan
t/01_engine.t view on Meta::CPAN
use Test::More tests => 18;
use Test::API;
use Test::Fatal;
use File::Temp ();
use autodie ':all';
### Checking module interface
my $module;
BEGIN {
$module = 'Dancer2::Template::TextTemplate::FakeEngine';
use_ok $module;
}
class_api_ok $module, qw{
new
caching expires cache_stringrefs
delimiters
prepend
safe safe_opcodes safe_disposable
process
};
my $e = new_ok $module;
### Checking default values
is $e->caching, 1, 'caching is enabled by default';
is $e->expires, 3600, 'cached instances expire after 3600 sec by default';
is_deeply $e->delimiters, [ '{', '}' ], 'delimiters are { and } by default';
### Real-life example
is(
exception {
$e->caching(0);
$e->expires(0);
$e->delimiters( [qw/ `[+ +]´ /] );
},
undef,
'successfully modified attributes'
);
# Creates a $template_file and a $template_string from an untouched
# $reference_file, so that we can safely change the content of $template_file
# without modifying versioned test-suite files.
my $reference_file = 't/test.template';
my $template_string = do {
open my $fh, '<', $reference_file or BAIL_OUT "Can't read $reference_file";
local $/;
<$fh>;
};
my $tmp_fh = File::Temp->new( UNLINK => 0 );
my $template_file = $tmp_fh->filename;
print {$tmp_fh} $template_string;
close $tmp_fh;
my $template_args = { totoro => { fly => 2 } };
my $expected_string = "41 42 43\n";
is $e->process( $template_file, $template_args ), $expected_string,
'template files are correctly computed';
( run in 0.967 second using v1.01-cache-2.11-cpan-54e63673c56 )