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