08-exported.t 2.2 KB

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