[Templates] [PATCH] Constants and '
Leon Brocard
acme@astray.com
Tue, 3 Sep 2002 11:11:20 +0100
--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
The new compile time constant folding is very cool, however, it is
missing one vital character. If I change constants.t to use "Andy 'Da
Man' Wardley" (note the two single quotes) (see attached patch) then
it fails with:
acme@parrot Template2 $ ~/bin/perl -Iblib/lib -Iblib/arch t/constants.t
FAILED 2:
expect: ['Andy \'Da Man\' Wardley']
result: ['Andy \'Da Man' Wardley']
1..39
ok 1 - created constants namespace
FAILED 2: - author match
not ok 2 - author match
ok 3 - single match
ok 4 - double match
ok 5 - col.back match
ok 6 - col.text match
ok 7 - created Template::Directive factory
ok 8 - created Template::Parser parser
ok 9
ok 10 - col.back folded
ok 11 - col.user unfolded
ok 12 - created Template::Parser parser
ok 13
ok 14 - col.back folded
ok 15 - col.user unfolded
ok 16 - created tt1
ok 17 - created tt2
ok 18 - created tt3
ok 19 - running test_expect()
ok 20 - template processor is engaged
ok 21 - input read and split into 9 tests
Template process failed: file error - Bad name after Wardley' at (eval 3) line 9, <DATA> line 1.
FAILED 22: - template text 1 process FAILED: hello [% const.author %]\n[% "bac...
not ok 22 - template text 1 process FAILED: hello [% const.author %]\n[% "bac...
FAILED 23: - (obviously did not match expected)
not ok 23 - (obviously did not match expected)
ok 24 - template text 2 processed OK: [% const.col.keys.sort.join(', '...
ok 25 - template text 2 matched expected
ok 26 - template text 3 processed OK: [% const.col.keys.sort.join(cons...
ok 27 - template text 3 matched expected
ok 28 - template text 4 processed OK: zero [% const.counter %]\none [% ...
ok 29 - template text 4 matched expected
ok 30 - template text 5 processed OK: [% "$constants.author thinks " %...
ok 31 - template text 5 matched expected
ok 32 - template text 6 processed OK: [% "$const.author thinks " -%]\n[...
ok 33 - template text 6 matched expected
ok 34 - template text 7 processed OK: no [% const.foo %]?
ok 35 - template text 7 matched expected
ok 36 - template text 8 processed OK: fave [% const.fave %]\ncol [% co...
ok 37 - template text 8 matched expected
ok 38 - defer references processed OK: [% "$key\n" FOREACH key = consta...
ok 39 - defer references matched expected
... because it is only escaping one single quote. The simple patch to
Template::Namespace::Constants adds a g modifier to the substitution,
and the tests now pass and our code now works.
So, please apply both attached patches.
Cheers, Leon
--
Leon Brocard.............................http://www.astray.com/
scribot.................................http://www.scribot.com/
... It works better if you plug it in
--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="constants.t.patch"
Index: t/constants.t
===================================================================
RCS file: /template-toolkit/Template2/t/constants.t,v
retrieving revision 1.4
diff -u -r1.4 constants.t
--- t/constants.t 2002/07/29 17:23:47 1.4
+++ t/constants.t 2002/09/03 10:04:12
@@ -30,7 +30,7 @@
my $n = 0;
my $constants = {
- author => 'Andy Wardley',
+ author => 'Andy \'Da Man\' Wardley',
single => 'foo\'bar',
double => "foo'bar",
joint => ', ',
@@ -44,7 +44,7 @@
my $namespace = Template::Namespace::Constants->new( $constants );
ok( $namespace, 'created constants namespace' );
-is( $namespace->ident([ 'constants', 0, "'author'", 0 ]), "'Andy Wardley'",
+is( $namespace->ident([ 'constants', 0, "'author'", 0 ]), q{'Andy \'Da Man\' Wardley'},
'author match' );
is( $namespace->ident([ 'constants', 0, "'single'", 0 ]), "'foo\\'bar'",
'single match' );
@@ -76,7 +76,7 @@
my $text = $parsed->{ BLOCK };
-ok( $text =~ /'Andy Wardley'/, 'author folded' );
+ok( $text =~ /'Andy 'Da Man' Wardley'/, 'author folded' );
ok( $text =~ /"back is " . '#ffffff'/, 'col.back folded' );
ok( $text =~ /stash->get\(\['col', 0, 'user', 0\]\)/, 'col.user unfolded' );
@@ -100,7 +100,7 @@
$text = $parsed->{ BLOCK };
-ok( $text =~ /'Andy Wardley'/, 'author folded' );
+ok( $text =~ /'Andy 'Da Man' Wardley'/, 'author folded' );
ok( $text =~ /"back is " . '#ffffff'/, 'col.back folded' );
ok( $text =~ /stash->get\(\['col', 0, 'user', 0\]\)/, 'col.user unfolded' );
@@ -152,7 +152,7 @@
[% "back is $const.col.back" %] and text is [% const.col.text %]
col.user is [% col.user %]
-- expect --
-hello Andy Wardley
+hello Andy 'Da Man' Wardley
back is #ffffff and text is #000000
col.user is red
--ikeVEW9yuYc//A+q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Constants.pm.patch"
Index: lib/Template/Namespace/Constants.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Namespace/Constants.pm,v
retrieving revision 1.11
diff -u -r1.11 Constants.pm
--- lib/Template/Namespace/Constants.pm 2002/08/15 16:42:09 1.11
+++ lib/Template/Namespace/Constants.pm 2002/09/03 10:04:55
@@ -92,7 +92,7 @@
return Template::Directive->ident(\@save);
}
- $result =~ s/'/\\'/;
+ $result =~ s/'/\\'/g;
$self->DEBUG(" * resolved => '$result'\n") if $DEBUG;
@@ -192,4 +192,4 @@
=head1 SEE ALSO
-L<Template::Directive|Template::Directive>
\ No newline at end of file
+L<Template::Directive|Template::Directive>
--ikeVEW9yuYc//A+q--