3 # test apparatus for Text::Template module
8 use Test::More tests => 7;
11 use_ok 'Text::Template' or exit 1;
13 my $tfh = File::Temp->new;
15 Text::Template->import('fill_in_file', 'fill_in_string');
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.';
23 # (2) Test fill_in_file
24 my $TEMPFILE = $tfh->filename;
26 print $tfh 'The value of $n is {$n}.', "\n";
27 close $tfh or die "Couldn't write test file: $!; aborting";
31 $out = fill_in_file($TEMPFILE, PACKAGE => 'R');
32 is $out, "The value of \$n is 8128.\n";
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";
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";
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
52 use vars qw($string $foo $r);
53 $string = 'Hello {$foo}';
55 $r = fill_in_string($string);
58 # (6) This test failed in 1.25. It's a variation on (5)
60 use Text::Template 'fill_in_string';
61 use vars qw($string $foo $r);
62 $string = 'Hello {$foo}';
64 $r = fill_in_string($string);
68 is $Q2::r, 'Hello Don';