head 1.7; access; symbols STRING_DIVERT_0_96:1.7 STRING_DIVERT_0_95:1.6 STRING_DIVERT_0_94:1.6 STRING_DIVERT_0_93:1.3 STRING_DIVERT_0_92:1.2 STRING_DIVERT_0_91:1.2; locks; strict; comment @# @; 1.7 date 2005.11.16.12.08.49; author rse; state Exp; branches; next 1.6; commitid pA9WqyMLYDm0RY9r; 1.6 date 2005.02.22.13.21.34; author rse; state Exp; branches; next 1.5; 1.5 date 2005.02.22.11.04.16; author rse; state Exp; branches; next 1.4; 1.4 date 2004.11.03.08.11.18; author rse; state Exp; branches; next 1.3; 1.3 date 2003.09.22.12.58.25; author rse; state Exp; branches; next 1.2; 1.2 date 2003.05.23.11.09.57; author rse; state Exp; branches; next 1.1; 1.1 date 2003.05.22.18.56.51; author rse; state Exp; branches; next ; desc @@ 1.7 log @o add folding loop detection to "string" method o use anonymous names already in "new" method o don't follow diversions on "folding" method to allow one to divert back to upper objects, too. o document that "folding" method returns all foldings if no name or object is specified. o change sample2.pl to show the usual "head" diversion once one is already diverted in "body". @ text @## ## String::Divert - String Object supporting Folding and Diversion ## Copyright (c) 2003-2005 Ralf S. Engelschall ## ## This file is part of String::Divert, a Perl module providing ## a string object supporting folding and diversion. ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version ## 2.0 of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file; if not, write to the Free Software Foundation, ## Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ## ## test.pl: Module Test Suite ## use 5.006; use Test::More tests => 37; # test: module loading BEGIN { use_ok('String::Divert') }; # test: object creation my $x = new String::Divert; ok(defined($x), "object creation"); $x->destroy; $x = new String::Divert; ok(defined($x), "object (re)creation"); $x->name("xx"); ok($x->name() eq "xx", "overwritten object name"); $x->name("x"); my $y = $x->clone(); ok($x != $y, "cloning"); # test: simple content ok($x->string() eq "", "empty initial content"); $x->append("foo"); $x->append("bar"); ok($x->string() eq "foobar", "appended content"); $x->assign("quux"); ok($x->string() eq "quux", "assigned content"); $x->assign("foo"); ok($x->string() eq "foo", "(re)assigned content"); $x->append("bar"); ok($x->string() eq "foobar", "append after assign"); # test: content overwrite mode $x->assign("foo"); $x->overwrite('once'); $x->append("bar"); $x->append("quux"); ok($x->string() eq "barquux", "appending with overwrite 'once'"); $x->overwrite('always'); $x->append("bar"); $x->append("quux"); ok($x->string() eq "quux", "appending with overwrite 'always'"); $x->overwrite('none'); $x->append("bar"); $x->append("quux"); ok($x->string() eq "quuxbarquux", "appending with overwrite 'none'"); # test: content folding $x->assign("foo"); $x->fold("bar"); $x->append("quux"); my $bar = $x->folding("bar"); ok(defined($bar), "folding object retrival 1"); ok($x->string() eq "fooquux", "folding 1"); $bar->append("bar"); ok($x->string() eq "foobarquux", "folding 2"); $bar->fold("baz"); $bar->append("bar2"); $bar->fold("baz"); $bar->append("bar3"); ok($x->string() eq "foobarbar2bar3quux", "folding 3"); my $baz = $x->folding("baz"); ok(defined($baz), "folding object retrival 2"); $baz->append("baz"); ok($baz->string() eq "baz", "folding 3"); ok($bar->string() eq "barbazbar2bazbar3", "folding 4"); ok($x->string() eq "foobarbazbar2bazbar3quux", "folding 5"); $baz->assign("XX"); ok($baz->string() eq "XX", "folding 6"); ok($bar->string() eq "barXXbar2XXbar3", "folding 7"); ok($x->string() eq "foobarXXbar2XXbar3quux", "folding 8"); my @@foldings = $x->folding(); ok(@@foldings == 3, "folding 9"); # test: content diversion $x->assign("foo"); $x->fold("bar"); $x->append("quux"); $x->divert("bar"); $x->append("bar1"); $x->fold("baz"); $x->append("bar2"); $x->divert("baz"); $x->append("baz"); ok($x->string() eq "baz", "diversion 1"); $x->undivert; ok($x->string() eq "bar1bazbar2", "diversion 2"); $x->undivert; ok($x->string() eq "foobar1bazbar2quux", "diversion 3"); $x->divert("bar"); $x->divert("baz"); my @@diversions = $x->diversion(); ok(@@diversions == 2, "diversion 4"); $x->undivert(0); @@diversions = $x->diversion(); ok(@@diversions == 0, "diversion 5"); # test: operator overloading ok($x->overload == 0, "default overloading mode"); $x->overload(1); ok($x->overload == 1, "default overloading mode"); $x->assign("foo"); ok("$x" eq "foo", "stringify operation"); $x .= "bar"; ok("$x" eq "foobar", "appending string"); $x *= "baz"; $x .= "quux"; ok("$x" eq "foobarquux", "appending folding"); $x >> "baz"; $x .= "baz"; $x << 0; ok("$x" eq "foobarbazquux", "diversion"); # configuring folder patters $x->assign("x"); $x->folder('{#%s#}', '\{#([a-zA-Z_][a-zA-Z0-9_.-]*)#\}'); ok("$x" eq "x", "folder pattern 1"); @ 1.6 log @o add "copy constructor" in overloaded API plus a copying() method for selecting what to do in the "copy constructor": passing the object as is or cloning via clone() method. o add clone() method for recursively cloning object o replace "die" with Carp's "croak" for better error messages @ text @d26 1 a26 1 use Test::More tests => 38; a36 1 ok($x->name() eq "", "object name"); @ 1.5 log @say hello to 2005 here, to @ text @d26 1 a26 1 use Test::More tests => 37; d41 2 @ 1.4 log @include year 2004 in Copyright @ text @d3 1 a3 1 ## Copyright (c) 2003-2004 Ralf S. Engelschall @ 1.3 log @fix obj->folder(format, pattern) implementation @ text @d3 1 a3 1 ## Copyright (c) 2003 Ralf S. Engelschall @ 1.2 log @o direct MakeMaker to not install sample[12].pl o cleanup naming of module, etc. o remove trailing whitespaces from codes o cleanup and extend documentation @ text @d26 1 a26 1 use Test::More tests => 36; d134 5 @ 1.1 log @finally add this little nasty beast to CVS @ text @d2 2 a3 2 ## String::Divert - Diversion String Object ## Copyright (c) 2003 Ralf S. Engelschall d5 2 a6 2 ## This file is part of String::Divert, a Perl module for ## dealing with strings containing nested diversions. d25 1 @