xref: /freebsd/crypto/openssl/external/perl/Text-Template-1.56/t/prepend.t (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1#!perl
2#
3# Tests for PREPEND features
4# These tests first appeared in version 1.22.
5
6use strict;
7use warnings;
8use Test::More tests => 10;
9
10use_ok 'Text::Template' or exit 1;
11
12@Emptyclass1::ISA = 'Text::Template';
13@Emptyclass2::ISA = 'Text::Template';
14
15my $tin = q{The value of $foo is: {$foo}};
16
17Text::Template->always_prepend(q{$foo = "global"});
18
19my $tmpl1 = Text::Template->new(
20    TYPE   => 'STRING',
21    SOURCE => $tin);
22
23my $tmpl2 = Text::Template->new(
24    TYPE    => 'STRING',
25    SOURCE  => $tin,
26    PREPEND => q{$foo = "template"});
27
28$tmpl1->compile;
29$tmpl2->compile;
30
31my $t1 = $tmpl1->fill_in(PACKAGE => 'T1');
32my $t2 = $tmpl2->fill_in(PACKAGE => 'T2');
33my $t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T3');
34
35is $t1, 'The value of $foo is: global';
36is $t2, 'The value of $foo is: template';
37is $t3, 'The value of $foo is: fillin';
38
39Emptyclass1->always_prepend(q{$foo = 'Emptyclass global';});
40$tmpl1 = Emptyclass1->new(
41    TYPE   => 'STRING',
42    SOURCE => $tin);
43
44$tmpl2 = Emptyclass1->new(
45    TYPE    => 'STRING',
46    SOURCE  => $tin,
47    PREPEND => q{$foo = "template"});
48
49$tmpl1->compile;
50$tmpl2->compile;
51
52$t1 = $tmpl1->fill_in(PACKAGE => 'T4');
53$t2 = $tmpl2->fill_in(PACKAGE => 'T5');
54$t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6');
55
56is $t1, 'The value of $foo is: Emptyclass global';
57is $t2, 'The value of $foo is: template';
58is $t3, 'The value of $foo is: fillin';
59
60$tmpl1 = Emptyclass2->new(
61    TYPE   => 'STRING',
62    SOURCE => $tin);
63
64$tmpl2 = Emptyclass2->new(
65    TYPE    => 'STRING',
66    SOURCE  => $tin,
67    PREPEND => q{$foo = "template"});
68
69$tmpl1->compile;
70$tmpl2->compile;
71
72$t1 = $tmpl1->fill_in(PACKAGE => 'T4');
73$t2 = $tmpl2->fill_in(PACKAGE => 'T5');
74$t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6');
75
76is $t1, 'The value of $foo is: global';
77is $t2, 'The value of $foo is: template';
78is $t3, 'The value of $foo is: fillin';
79