/
tt3.t
117 lines (84 loc) · 3.29 KB
/
tt3.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#============================================================= -*-perl-*-
#
# t/engine/tt3.t
#
# Test script for the Template::TT3:Engine::TT3 module.
#
# Run with -h option for help.
#
# Written by Andy Wardley <abw@wardley.org>
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
#========================================================================
use Badger
lib => '../../lib',
Filesystem => 'Bin';
use Template::TT3::Test
debug => 'Template::TT3::Engine::TT3 Template::TT3::Templates',
args => \@ARGV,
tests => 16;
#-----------------------------------------------------------------------
# basic load/new tests
#-----------------------------------------------------------------------
use Template::TT3::Engine::TT3;
pass( 'loaded Template::TT3::Engine::TT3' );
use constant TT3 => 'Template::TT3::Engine::TT3';
my $engine = TT3->new;
ok( $engine, 'created a new TT3 engine' );
#-----------------------------------------------------------------------
# import TT3 constant shortcut
#-----------------------------------------------------------------------
package Template::TT3::Test::LoadTT3;
use Template::TT3::Engine::TT3 'TT3';
use Template::TT3::Test;
my $tt3 = TT3->new;
is( TT3, 'Template::TT3::Engine::TT3', 'imported TT3 constant' );
ok( $tt3, 'created a new TT3 engine from imported constant' );
#-----------------------------------------------------------------------
# access the hub
#-----------------------------------------------------------------------
my $hub = $tt3->hub;
ok( $hub, "got hub from engine: $hub" );
#-----------------------------------------------------------------------
# fetch a template from text
#-----------------------------------------------------------------------
my $template = $tt3->template( text => 'Hello [% name or "World" %]!' )
|| die $tt3->reason;
ok( $template, 'fetched template from text' );
ok( $template->id, 'template id is ' . $template->id );
ok( $template->hub, 'template hub is ' . $template->hub );
ok( $template->dialect, 'template dialect is ' . $template->dialect );
ok( $template->templates, 'template templates is ' . $template->templates );
is(
$template->fill, # A bit of TT3 history in the
'Hello World!', # making - this was the first full
'processed Hello World template text' # template TT3 ever processed!
);
is(
$template->fill( name => 'Badger' ),
'Hello Badger!',
'processed Hello Badger template text'
);
#-----------------------------------------------------------------------
# create an engine with a template_path
#-----------------------------------------------------------------------
package main;
$tt3 = TT3->new(
template_path => Bin->dir('templates')
);
ok( $tt3, 'created template engine with custom template_path' );
$template = $tt3->template( file => 'hello.tt3' )
|| die $tt3->reason;
ok( $template, 'fetched hello.tt3 template from file' );
is(
$template->fill, # This was the first template file
"Hello World!\n", # TT3 ever processed.
'processed Hello World template file'
);
is(
$template->fill( name => 'Badger' ),
"Hello Badger!\n",
'processed Hello Badger template file'
);