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