1#============================================================= -*-perl-*-
2#
3# t/capture.t
4#
5# Test that the output from a directive block can be assigned to a 
6# variable.
7#
8# Written by Andy Wardley <abw@kfs.org>
9#
10# Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
11# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
12#
13# This is free software; you can redistribute it and/or modify it
14# under the same terms as Perl itself.
15#
16# $Id$
17#
18#========================================================================
19
20use strict;
21use lib qw( ./lib ../lib );
22use Template::Test;
23$^W = 1;
24
25$Template::Test::DEBUG = 0;
26
27my $config = {
28    POST_CHOMP => 1,
29};
30
31my $replace = {
32    a => 'alpha',
33    b => 'bravo',
34};
35
36test_expect(\*DATA, $config, $replace);
37
38__DATA__
39
40-- test --
41[% BLOCK foo %]
42This is block foo, a is [% a %]
43[% END %]
44[% b = INCLUDE foo %]
45[% c = INCLUDE foo a = 'ammended' %]
46b: <[% b %]>
47c: <[% c %]>
48-- expect --
49b: <This is block foo, a is alpha>
50c: <This is block foo, a is ammended>
51
52-- test --
53[% d = BLOCK %]
54This is the block, a is [% a %]
55[% END %]
56[% a = 'charlie' %]
57a: [% a %]   d: [% d %]
58-- expect --
59a: charlie   d: This is the block, a is alpha
60
61-- test --
62[% e = IF a == 'alpha' %]
63a is [% a %]
64[% ELSE %]
65that was unexpected
66[% END %]
67e: [% e %]
68-- expect --
69e: a is alpha
70
71-- test --
72[% a = FOREACH b = [1 2 3] %]
73[% b %],
74[%- END %]
75a is [% a %]
76
77-- expect --
78a is 1,2,3,
79
80-- test --
81[% BLOCK userinfo %]
82name: [% user +%]
83[% END %]
84[% out = PROCESS userinfo FOREACH user = [ 'tom', 'dick', 'larry' ] %]
85Output:
86[% out %]
87-- expect --
88Output:
89name: tom
90name: dick
91name: larry
92
93
94
95