exported.t 1.8 KB

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