Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 105 lines (87 sloc) 2.256 kB
cf189d4 @abw added t/blocks.t
authored
1 #============================================================= -*-perl-*-
2 #
3 # t/blocks.t
4 #
5 # Test ability to INCLUDE/PROCESS a block in a template.
6 #
7 # Written by Andy Wardley <abw@andywardley.com>
8 #
9 # Copyright (C) 1996-2000 Andy Wardley. All Rights Reserved.
10 # Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
11 #
12 # This is free software; you can redistribute it and/or modify it
13 # under the same terms as Perl itself.
14 #
15 # $Id$
16 #
17 #========================================================================
18
19 use strict;
20 use lib qw( ./lib ../lib );
21 use Template::Test;
22 use Template::Provider;
23 use Cwd;
24 $^W = 1;
25
26 my $DEBUG = grep(/-d/, @ARGV);
27 #$Template::Parser::DEBUG = $DEBUG;
28 #$Template::Directive::PRETTY = $DEBUG;
29 $Template::Provider::DEBUG = $DEBUG;
a8ac400 @abw moved vmethods into separate manpage
authored
30 #$Template::Context::DEBUG = $DEBUG;
cf189d4 @abw added t/blocks.t
authored
31
32 my $path = cwd;
33 my $dir = -d 'test/lib' ? "$path/test/lib" : "$path/t/test/lib";
34
35 my $tt1 = Template->new({
36 INCLUDE_PATH => [ qw( t/test/lib test/lib ) ],
37 ABSOLUTE => 1,
38 });
39
40 my $tt2 = Template->new({
41 INCLUDE_PATH => [ qw( t/test/lib test/lib ) ],
42 EXPOSE_BLOCKS => 1,
43 ABSOLUTE => 1,
44 });
45
46 my $vars = {
47 a => 'alpha',
48 b => 'bravo',
49 dir => $dir,
50 };
51
52 test_expect(\*DATA, [ off => $tt1, on => $tt2 ], $vars);
53
54 __DATA__
55 -- test --
56 [% TRY; INCLUDE blockdef/block1; CATCH; error; END %]
57
58 -- expect --
59 file error - blockdef/block1: not found
60
61 -- test --
62 -- use on --
63 [% INCLUDE blockdef/block1 %]
64
65 -- expect --
66 This is block 1, defined in blockdef, a is alpha
67
68 -- test --
69 [% INCLUDE blockdef/block1 a='amazing' %]
70
71 -- expect --
72 This is block 1, defined in blockdef, a is amazing
73
74 -- test --
75 [% TRY; INCLUDE blockdef/none; CATCH; error; END %]
76 -- expect --
77 file error - blockdef/none: not found
78
79 -- test --
80 [% INCLUDE "$dir/blockdef/block1" a='abstract' %]
81
82 -- expect --
83 This is block 1, defined in blockdef, a is abstract
84
85 -- test --
86 [% BLOCK one -%]
87 block one
88 [% BLOCK two -%]
89 this is block two, b is [% b %]
90 [% END -%]
91 two has been defined, let's now include it
92 [% INCLUDE one/two b='brilliant' -%]
93 end of block one
94 [% END -%]
95 [% INCLUDE one -%]
96 =
97 [% INCLUDE one/two b='brazen'-%]
98 --expect --
99 block one
100 two has been defined, let's now include it
101 this is block two, b is brilliant
102 end of block one
103 =
104 this is block two, b is brazen
Something went wrong with that request. Please try again.