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