3 # test apparatus for Text::Template module
6 use Text::Template 'fill_in_file', 'fill_in_string';
8 die "This is the test program for Text::Template version 1.46.
9 You are using version $Text::Template::VERSION instead.
10 That does not make sense.\n
12 unless $Text::Template::VERSION == 1.46;
19 # (1) Test fill_in_string
20 $out = fill_in_string('The value of $n is {$n}.', PACKAGE => 'Q' );
21 print +($out eq 'The value of $n is 119.' ? '' : 'not '), "ok $n\n";
24 # (2) Test fill_in_file
26 open F, "> $TEMPFILE" or die "Couldn't open test file: $!; aborting";
27 print F 'The value of $n is {$n}.', "\n";
28 close F or die "Couldn't write test file: $!; aborting";
31 $out = fill_in_file($TEMPFILE, PACKAGE => 'R');
32 print +($out eq "The value of \$n is 8128.\n" ? '' : 'not '), "ok $n\n";
35 # (3) Jonathan Roy reported this bug:
36 open F, "> $TEMPFILE" or die "Couldn't open test file: $!; aborting";
37 print F "With a message here? [% \$var %]\n";
38 close F or die "Couldn't close test file: $!; aborting";
39 $out = fill_in_file($TEMPFILE, DELIMITERS => ['[%', '%]'],
40 HASH => { "var" => \"It is good!" });
41 print +($out eq "With a message here? It is good!\n" ? '' : 'not '), "ok $n\n";
44 # (4) It probably occurs in fill_this_in also:
46 Text::Template->fill_this_in("With a message here? [% \$var %]\n",
47 DELIMITERS => ['[%', '%]'],
48 HASH => { "var" => \"It is good!" });
49 print +($out eq "With a message here? It is good!\n" ? '' : 'not '), "ok $n\n";
52 # (5) This test failed in 1.25. It was supplied by Donald L. Greer Jr.
53 # Note that it's different from (1) in that there's no explicit
55 use vars qw($string $foo $r);
56 $string='Hello {$foo}';
58 $r = fill_in_string($string);
59 print (($r eq 'Hello Don' ? '' : 'not '), 'ok ', $n++, "\n");
61 # (6) This test failed in 1.25. It's a variation on (5)
63 use Text::Template 'fill_in_string';
64 use vars qw($string $foo $r);
65 $string='Hello {$foo}';
67 $r = fill_in_string($string);
68 print (($r eq 'Hello Don' ? '' : 'not '), 'ok ', $main::n++, "\n");
72 END { $TEMPFILE && unlink $TEMPFILE }