[Templates-cvs] cvs commit: Template2/t vmeth.t
cvs@template-toolkit.org
cvs@template-toolkit.org
cvs 06/02/01 14:53:42
Modified: t vmeth.t
Log:
* added tests for replace() scalar virtual method with support for
backreferences
Revision Changes Path
2.24 +56 -14 Template2/t/vmeth.t
Index: vmeth.t
===================================================================
RCS file: /template-toolkit/Template2/t/vmeth.t,v
retrieving revision 2.23
retrieving revision 2.24
diff -u -r2.23 -r2.24
--- vmeth.t 2006/02/01 09:13:17 2.23
+++ vmeth.t 2006/02/01 14:53:42 2.24
@@ -13,7 +13,7 @@
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
-# $Id: vmeth.t,v 2.23 2006/02/01 09:13:17 abw Exp $
+# $Id: vmeth.t,v 2.24 2006/02/01 14:53:42 abw Exp $
#
#========================================================================
@@ -696,18 +696,12 @@
-- expect --
message: Hello World
--- stop --
--- test --
-[% var = 'foo'; var.replace('f(o+)$', 'b$1') %]
--- expect --
-boo
+#------------------------------------------------------------------------
+# test the new substr() method
+#------------------------------------------------------------------------
--- test --
-[% var = 'foo|bar/baz'; var.replace('(fo+)|(bar)(.*)$', '[ $1 | $2 | $3 ]') %]
--- expect --
-[ foo | bar | ]
-- test --
[% text = 'Hello World' -%]
@@ -718,8 +712,8 @@
-- expect --
a: World!
b: Hello!
-c: Hello!
-d: Goodbye World!
+c: Goodbye World!
+d: Hello World!
-- test --
[% text = 'foo bar baz wiz waz woz' -%]
@@ -730,5 +724,53 @@
-- expect --
a: bar
b: wiz waz woz
-c: foo bar baz
-d: FOO wiz waz woz
+c: FOO wiz waz woz
+d: foo bar baz wiz waz woz
+
+
+#------------------------------------------------------------------------
+# test the new replace() method with backrefs
+#------------------------------------------------------------------------
+
+-- test --
+[% text = 'The cat sat on the mat';
+ text.replace( '(\w+) sat on the (\w+)',
+ 'dirty $1 shat on the filthy $2' )
+%]
+-- expect --
+The dirty cat shat on the filthy mat
+
+
+# test more than 9 captures to make sure $10, $11, etc., work ok
+-- test --
+[% text = 'one two three four five six seven eight nine ten eleven twelve thirteen';
+ text.replace(
+ '(\w+) (\w+) (\w+) (\w+) (\w+) (\w+) (\w+) (\w+) (\w+) (\w+) (\w+) (\w+)',
+ '[$12-$11-$10-$9-$8-$7-$6-$5-$4-$3-$2-$1]'
+ )
+%]
+-- expect --
+[twelve-eleven-ten-nine-eight-seven-six-five-four-three-two-one] thirteen
+
+
+-- test --
+[% text = 'one two three four five six seven eight nine ten eleven twelve thirteen';
+ text.replace(
+ '(\w+) ',
+ '[$1]-'
+ )
+%]
+-- expect --
+[one]-[two]-[three]-[four]-[five]-[six]-[seven]-[eight]-[nine]-[ten]-[eleven]-[twelve]-thirteen
+
+-- test --
+[% var = 'foo'; var.replace('f(o+)$', 'b$1') %]
+-- expect --
+boo
+
+-- test --
+[% var = 'foo|bar/baz'; var.replace('(fo+)\|(bar)(.*)$', '[ $1, $2, $3 ]') %]
+-- expect --
+[ foo, bar, /baz ]
+
+