Commit | Line | Data |
e374d8da |
1 | #!perl |
2 | |
3 | use strict ; |
4 | use lib qw(t) ; |
5 | use common ; |
6 | |
7 | use File::Slurp ; |
8 | use Data::Dumper ; |
9 | |
10 | # these dirs must be in order to the deepest for rmdir to work properly |
11 | |
12 | my @tmpl_dirs = qw( templates templates/deeper templates/deeper/deepest ) ; |
13 | |
14 | my %tmpl_files = ( |
15 | |
16 | 'templates/FOO.tmpl' => <<FOO, |
17 | this loads bar <[%include BAR%]> |
18 | FOO |
19 | 'templates/deeper/BAR.tmpl' => <<BAR, |
20 | {this should hide} |
21 | BAR |
22 | 'templates/deeper/deepest/BAR.tmpl' => <<BAR, |
23 | [this should be hidden then revealed] |
24 | BAR |
25 | |
26 | ) ; |
27 | |
28 | my $tests = [ |
29 | |
30 | { |
31 | name => 'simple include', |
32 | skip => 0, |
33 | opts => { |
34 | |
35 | templates => { |
36 | 'foo' => 'bar', |
37 | } |
38 | }, |
39 | data => {}, |
40 | template => '[%INCLUDE foo%]', |
41 | expected => 'bar', |
42 | }, |
43 | { |
44 | name => 'nested includes', |
45 | skip => 0, |
46 | opts => { |
47 | templates => { |
48 | foo => '[%include bar%]', |
49 | bar => 'quux', |
50 | }, |
51 | }, |
52 | data => {}, |
53 | template => '[%INCLUDE foo%]', |
54 | expected => 'quux', |
55 | }, |
56 | { |
57 | name => 'serial includes', |
58 | skip => 0, |
59 | opts => { |
60 | templates => { |
61 | foo => 'foo is here', |
62 | bar => 'bar is too', |
63 | quux => 'quux is on the drums', |
64 | }, |
65 | }, |
66 | data => {}, |
67 | template => '[%INCLUDE foo%] [%INCLUDE bar%] [%INCLUDE quux%]', |
68 | expected => 'foo is here bar is too quux is on the drums', |
69 | }, |
70 | |
71 | { |
72 | name => 'missing include', |
73 | skip => 0, |
74 | data => {}, |
75 | keep_obj => 1, |
76 | pretest => sub { $_[0]{obj}->delete_templates() }, |
77 | error => qr/can't find/, |
78 | }, |
79 | |
80 | { |
81 | name => 'load include files', |
82 | skip => 0, |
83 | opts => { |
84 | include_paths => [ qw( |
85 | templates |
86 | templates/deeper |
87 | templates/deeper/deepest |
88 | ) ], |
89 | }, |
90 | data => {}, |
91 | template => '[%INCLUDE FOO%]', |
92 | expected => <<EXPECTED, |
93 | this loads bar <{this should hide} |
94 | > |
95 | EXPECTED |
96 | |
97 | }, |
98 | { |
99 | name => 'use lower path', |
100 | skip => 0, |
101 | opts => { |
102 | include_paths => [ qw( |
103 | templates |
104 | templates/deeper/deepest |
105 | ) ], |
106 | }, |
107 | data => {}, |
108 | expected => <<EXPECTED, |
109 | this loads bar <[this should be hidden then revealed] |
110 | > |
111 | EXPECTED |
112 | |
113 | }, |
114 | { |
115 | name => 'delete covering file', |
116 | skip => 0, |
117 | opts => { |
118 | include_paths => [ qw( |
119 | templates |
120 | templates/deeper |
121 | templates/deeper/deepest |
122 | ) ], |
123 | }, |
124 | pretest => sub { unlink 'templates/deeper/BAR.tmpl' }, |
125 | data => {}, |
126 | expected => <<EXPECTED, |
127 | this loads bar <[this should be hidden then revealed] |
128 | > |
129 | EXPECTED |
130 | |
131 | }, |
132 | ] ; |
133 | |
134 | |
135 | write_tmpl_files() ; |
136 | |
137 | template_tester( $tests ) ; |
138 | |
139 | #remove_tmpl_files() ; |
140 | |
141 | exit ; |
142 | |
143 | |
144 | sub write_tmpl_files { |
145 | |
146 | mkdir $_, 0755 for @tmpl_dirs ; |
147 | |
148 | while( my( $file, $tmpl ) = each %tmpl_files ) { |
149 | |
150 | write_file( $file, $tmpl ) ; |
151 | } |
152 | } |
153 | |
154 | sub remove_tmpl_files { |
155 | |
156 | unlink keys %tmpl_files ; |
157 | |
158 | rmdir $_ for reverse @tmpl_dirs ; |
159 | } |