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
19use strict;
20use lib qw( ./lib ../lib );
21use Template::Test;
22use Template::Provider;
23use Cwd;
24$^W = 1;
25
26my $DEBUG = grep(/-d/, @ARGV);
27#$Template::Parser::DEBUG = $DEBUG;
28#$Template::Directive::PRETTY = $DEBUG;
29$Template::Provider::DEBUG = $DEBUG;
30#$Template::Context::DEBUG = $DEBUG;
31
32my $path = cwd;
33my $dir  = -d 'test/lib' ? "$path/test/lib" : "$path/t/test/lib";
34
35my $tt1 = Template->new({
36    INCLUDE_PATH => [ qw( t/test/lib test/lib ) ],
37    ABSOLUTE => 1,
38});
39
40my $tt2 = Template->new({
41    INCLUDE_PATH => [ qw( t/test/lib test/lib ) ],
42    EXPOSE_BLOCKS => 1,
43    ABSOLUTE => 1,
44});
45
46my $vars = {
47    a => 'alpha',
48    b => 'bravo',
49    dir => $dir,
50};
51
52test_expect(\*DATA, [ off => $tt1, on => $tt2 ], $vars);
53
54__DATA__
55-- test --
56[% TRY; INCLUDE blockdef/block1; CATCH; error; END %]
57
58-- expect --
59file error - blockdef/block1: not found
60
61-- test --
62-- use on --
63[% INCLUDE blockdef/block1 %]
64
65-- expect --
66This is block 1, defined in blockdef, a is alpha
67
68-- test --
69[% INCLUDE blockdef/block1 a='amazing' %]
70
71-- expect --
72This is block 1, defined in blockdef, a is amazing
73
74-- test -- 
75[% TRY; INCLUDE blockdef/none; CATCH; error; END %]
76-- expect --
77file error - blockdef/none: not found
78
79-- test --
80[% INCLUDE "$dir/blockdef/block1" a='abstract' %]
81
82-- expect --
83This is block 1, defined in blockdef, a is abstract
84
85-- test --
86[% BLOCK one -%]
87block one
88[% BLOCK two -%]
89this is block two, b is [% b %]
90[% END -%]
91two has been defined, let's now include it
92[% INCLUDE one/two b='brilliant' -%]
93end of block one
94[% END -%]
95[% INCLUDE one -%]
96=
97[% INCLUDE one/two b='brazen'-%]
98--expect --
99block one
100two has been defined, let's now include it
101this is block two, b is brilliant
102end of block one
103=
104this is block two, b is brazen
105