File: capture.t

package info (click to toggle)
libtemplate-perl 2.24-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,660 kB
  • sloc: perl: 14,518; makefile: 15; sh: 5
file content (94 lines) | stat: -rw-r--r-- 1,628 bytes parent folder | download | duplicates (2)
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
#============================================================= -*-perl-*-
#
# t/capture.t
#
# Test that the output from a directive block can be assigned to a 
# variable.
#
# Written by Andy Wardley <abw@kfs.org>
#
# Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id$
#
#========================================================================

use strict;
use lib qw( ./lib ../lib );
use Template::Test;
$^W = 1;

$Template::Test::DEBUG = 0;

my $config = {
    POST_CHOMP => 1,
};

my $replace = {
    a => 'alpha',
    b => 'bravo',
};

test_expect(\*DATA, $config, $replace);

__DATA__

-- test --
[% BLOCK foo %]
This is block foo, a is [% a %]
[% END %]
[% b = INCLUDE foo %]
[% c = INCLUDE foo a = 'ammended' %]
b: <[% b %]>
c: <[% c %]>
-- expect --
b: <This is block foo, a is alpha>
c: <This is block foo, a is ammended>

-- test --
[% d = BLOCK %]
This is the block, a is [% a %]
[% END %]
[% a = 'charlie' %]
a: [% a %]   d: [% d %]
-- expect --
a: charlie   d: This is the block, a is alpha

-- test --
[% e = IF a == 'alpha' %]
a is [% a %]
[% ELSE %]
that was unexpected
[% END %]
e: [% e %]
-- expect --
e: a is alpha

-- test --
[% a = FOREACH b = [1 2 3] %]
[% b %],
[%- END %]
a is [% a %]

-- expect --
a is 1,2,3,

-- test --
[% BLOCK userinfo %]
name: [% user +%]
[% END %]
[% out = PROCESS userinfo FOREACH user = [ 'tom', 'dick', 'larry' ] %]
Output:
[% out %]
-- expect --
Output:
name: tom
name: dick
name: larry