xref: /freebsd/crypto/openssl/external/perl/Text-Template-1.56/t/exported.t (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1#!perl
2#
3# test apparatus for Text::Template module
4# still incomplete.
5
6use strict;
7use warnings;
8use Test::More tests => 7;
9use File::Temp;
10
11use_ok 'Text::Template' or exit 1;
12
13my $tfh = File::Temp->new;
14
15Text::Template->import('fill_in_file', 'fill_in_string');
16
17$Q::n = $Q::n = 119;
18
19# (1) Test fill_in_string
20my $out = fill_in_string('The value of $n is {$n}.', PACKAGE => 'Q');
21is $out, 'The value of $n is 119.';
22
23# (2) Test fill_in_file
24my $TEMPFILE = $tfh->filename;
25
26print $tfh 'The value of $n is {$n}.', "\n";
27close $tfh or die "Couldn't write test file: $!; aborting";
28
29$R::n = $R::n = 8128;
30
31$out = fill_in_file($TEMPFILE, PACKAGE => 'R');
32is $out, "The value of \$n is 8128.\n";
33
34# (3) Jonathan Roy reported this bug:
35open my $ofh, '>', $TEMPFILE or die "Couldn't open test file: $!; aborting";
36print $ofh "With a message here? [% \$var %]\n";
37close $ofh or die "Couldn't close test file: $!; aborting";
38$out = fill_in_file($TEMPFILE,
39    DELIMITERS => [ '[%', '%]' ],
40    HASH => { "var" => \"It is good!" });
41is $out, "With a message here? It is good!\n";
42
43# (4) It probably occurs in fill_this_in also:
44$out = Text::Template->fill_this_in("With a message here? [% \$var %]\n",
45    DELIMITERS => [ '[%', '%]' ],
46    HASH => { "var" => \"It is good!" });
47is $out, "With a message here? It is good!\n";
48
49# (5) This test failed in 1.25.  It was supplied by Donald L. Greer Jr.
50# Note that it's different from (1)  in that there's no explicit
51# package=> argument.
52use vars qw($string $foo $r);
53$string = 'Hello {$foo}';
54$foo    = "Don";
55$r      = fill_in_string($string);
56is $r, 'Hello Don';
57
58# (6) This test failed in 1.25.  It's a variation on (5)
59package Q2;
60use Text::Template 'fill_in_string';
61use vars qw($string $foo $r);
62$string = 'Hello {$foo}';
63$foo    = "Don";
64$r      = fill_in_string($string);
65
66package main;
67
68is $Q2::r, 'Hello Don';
69