1 | #!perl
|
---|
2 | #
|
---|
3 | # test apparatus for Text::Template module
|
---|
4 | # still incomplete.
|
---|
5 |
|
---|
6 | use strict;
|
---|
7 | use warnings;
|
---|
8 | use Test::More tests => 7;
|
---|
9 | use File::Temp;
|
---|
10 |
|
---|
11 | use_ok 'Text::Template' or exit 1;
|
---|
12 |
|
---|
13 | my $tfh = File::Temp->new;
|
---|
14 |
|
---|
15 | Text::Template->import('fill_in_file', 'fill_in_string');
|
---|
16 |
|
---|
17 | $Q::n = $Q::n = 119;
|
---|
18 |
|
---|
19 | # (1) Test fill_in_string
|
---|
20 | my $out = fill_in_string('The value of $n is {$n}.', PACKAGE => 'Q');
|
---|
21 | is $out, 'The value of $n is 119.';
|
---|
22 |
|
---|
23 | # (2) Test fill_in_file
|
---|
24 | my $TEMPFILE = $tfh->filename;
|
---|
25 |
|
---|
26 | print $tfh 'The value of $n is {$n}.', "\n";
|
---|
27 | close $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');
|
---|
32 | is $out, "The value of \$n is 8128.\n";
|
---|
33 |
|
---|
34 | # (3) Jonathan Roy reported this bug:
|
---|
35 | open my $ofh, '>', $TEMPFILE or die "Couldn't open test file: $!; aborting";
|
---|
36 | print $ofh "With a message here? [% \$var %]\n";
|
---|
37 | close $ofh or die "Couldn't close test file: $!; aborting";
|
---|
38 | $out = fill_in_file($TEMPFILE,
|
---|
39 | DELIMITERS => [ '[%', '%]' ],
|
---|
40 | HASH => { "var" => \"It is good!" });
|
---|
41 | is $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!" });
|
---|
47 | is $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.
|
---|
52 | use vars qw($string $foo $r);
|
---|
53 | $string = 'Hello {$foo}';
|
---|
54 | $foo = "Don";
|
---|
55 | $r = fill_in_string($string);
|
---|
56 | is $r, 'Hello Don';
|
---|
57 |
|
---|
58 | # (6) This test failed in 1.25. It's a variation on (5)
|
---|
59 | package Q2;
|
---|
60 | use Text::Template 'fill_in_string';
|
---|
61 | use vars qw($string $foo $r);
|
---|
62 | $string = 'Hello {$foo}';
|
---|
63 | $foo = "Don";
|
---|
64 | $r = fill_in_string($string);
|
---|
65 |
|
---|
66 | package main;
|
---|
67 |
|
---|
68 | is $Q2::r, 'Hello Don';
|
---|