11-prepend.t 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!perl
  2. #
  3. # Tests for PREPEND features
  4. # These tests first appeared in version 1.22.
  5. use Text::Template;
  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..9\n";
  12. my $n = 1;
  13. @Emptyclass1::ISA = 'Text::Template';
  14. @Emptyclass2::ISA = 'Text::Template';
  15. my $tin = q{The value of $foo is: {$foo}};
  16. Text::Template->always_prepend(q{$foo = "global"});
  17. $tmpl1 = Text::Template->new(TYPE => 'STRING',
  18. SOURCE => $tin,
  19. );
  20. $tmpl2 = Text::Template->new(TYPE => 'STRING',
  21. SOURCE => $tin,
  22. PREPEND => q{$foo = "template"},
  23. );
  24. $tmpl1->compile;
  25. $tmpl2->compile;
  26. $t1 = $tmpl1->fill_in(PACKAGE => 'T1');
  27. $t2 = $tmpl2->fill_in(PACKAGE => 'T2');
  28. $t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T3');
  29. ($t1 eq 'The value of $foo is: global') or print "not ";
  30. print "ok $n\n"; $n++;
  31. ($t2 eq 'The value of $foo is: template') or print "not ";
  32. print "ok $n\n"; $n++;
  33. ($t3 eq 'The value of $foo is: fillin') or print "not ";
  34. print "ok $n\n"; $n++;
  35. Emptyclass1->always_prepend(q{$foo = 'Emptyclass global';});
  36. $tmpl1 = Emptyclass1->new(TYPE => 'STRING',
  37. SOURCE => $tin,
  38. );
  39. $tmpl2 = Emptyclass1->new(TYPE => 'STRING',
  40. SOURCE => $tin,
  41. PREPEND => q{$foo = "template"},
  42. );
  43. $tmpl1->compile;
  44. $tmpl2->compile;
  45. $t1 = $tmpl1->fill_in(PACKAGE => 'T4');
  46. $t2 = $tmpl2->fill_in(PACKAGE => 'T5');
  47. $t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6');
  48. ($t1 eq 'The value of $foo is: Emptyclass global') or print "not ";
  49. print "ok $n\n"; $n++;
  50. ($t2 eq 'The value of $foo is: template') or print "not ";
  51. print "ok $n\n"; $n++;
  52. ($t3 eq 'The value of $foo is: fillin') or print "not ";
  53. print "ok $n\n"; $n++;
  54. $tmpl1 = Emptyclass2->new(TYPE => 'STRING',
  55. SOURCE => $tin,
  56. );
  57. $tmpl2 = Emptyclass2->new(TYPE => 'STRING',
  58. SOURCE => $tin,
  59. PREPEND => q{$foo = "template"},
  60. );
  61. $tmpl1->compile;
  62. $tmpl2->compile;
  63. $t1 = $tmpl1->fill_in(PACKAGE => 'T4');
  64. $t2 = $tmpl2->fill_in(PACKAGE => 'T5');
  65. $t3 = $tmpl2->fill_in(PREPEND => q{$foo = "fillin"}, PACKAGE => 'T6');
  66. ($t1 eq 'The value of $foo is: global') or print "not ";
  67. print "ok $n\n"; $n++;
  68. ($t2 eq 'The value of $foo is: template') or print "not ";
  69. print "ok $n\n"; $n++;
  70. ($t3 eq 'The value of $foo is: fillin') or print "not ";
  71. print "ok $n\n"; $n++;