[Templates-cvs] cvs commit: TT3/t/vobject text.t
cvs@template-toolkit.org
cvs@template-toolkit.org
Tue, 30 Mar 2004 11:32:42 +0100
cvs 04/03/30 10:32:41
Modified: t/vobject text.t
Log:
* added more tests
Revision Changes Path
1.3 +117 -10 TT3/t/vobject/text.t
Index: text.t
===================================================================
RCS file: /template-toolkit/TT3/t/vobject/text.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- text.t 2004/03/29 18:36:52 1.2
+++ text.t 2004/03/30 10:32:41 1.3
@@ -9,7 +9,7 @@
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
-# $Id: text.t,v 1.2 2004/03/29 18:36:52 abw Exp $
+# $Id: text.t,v 1.3 2004/03/30 10:32:41 abw Exp $
#
#========================================================================
@@ -18,22 +18,121 @@
use lib qw( ./lib ../lib ../../lib );
use Template::VObject::Text;
-use Test::More tests =>111;
+use Test::More tests =>143;
my $DEBUG =
$Template::VObject::Text::DEBUG =
grep(/^--?d(ebug)?/, @ARGV);
-my $Text = 'Template::VObject::Text';
-my $text = $Text->new('Hello World');
+my ($Text, $text, $copy, $string);
-is( $$text, 'Hello World', 'Hello World by ref' );
+#------------------------------------------------------------------------
+# constructor tests
+#------------------------------------------------------------------------
+
+$Text = 'Template::VObject::Text';
+$text = $Text->new('Hello World');
+is( $$text, 'Hello World', 'set text' );
+
+$text = $Text->new('Hello', 'World');
+is( $$text, 'HelloWorld', 'set text args' );
+
+$string = 'Hello again';
+$text = $Text->new(\$string);
+is( $$text, 'Hello again', 'set text by ref' );
+
+$copy = $Text->new($text);
+is( $$copy, 'Hello again', 'set text by copy' );
+$$text .= ', how nice to see you';
+is( $$text, 'Hello again, how nice to see you', 'text changed' );
+is( $$copy, 'Hello again', 'copy unchanged' );
+
+$copy = $Text->new($text, ', you look well');
+is( $$copy, 'Hello again, how nice to see you, you look well',
+ 'extreme pleasantries' );
+
+$text = $Text->new('a new message');
+$copy = $text->clone();
+is( $$copy, 'a new message', 'cloned text' );
+
+$copy = $text->clone(' with some more');
+is( $$copy, 'a new message with some more', 'cloned text with args' );
+
+
+#------------------------------------------------------------------------
+# append()
+#------------------------------------------------------------------------
+
+$text = $Text->new('foo ');
+is( $text->append('bar'), 'foo bar', 'appended bar' );
+is( $text->text(), 'foo ', 'still foo' );
+
+
+#------------------------------------------------------------------------
+# defined()
+#------------------------------------------------------------------------
+
+ok( $text->defined(), 'text is defined' );
+
+$text = $Text->new('');
+ok( $text->defined(), 'empty text is still defined' );
+is( $$text, '', 'empty text' );
+
+$text = $Text->new();
+ok( ! $text->defined(), 'no text is not defined' );
+is( $$text, undef, 'no text specified' );
+
+$text = $Text->new(undef);
+ok( ! $text->defined(), 'undef text is not defined' );
+is( $$text, undef, 'undefined text' );
+
+$text = $Text->new(undef, undef);
+ok( ! $text->defined(), 'multi-undef text is not defined' );
+is( $$text, undef, 'multi-undefined text' );
+
+# make sure we can append text onto an undefined value without
+# any problems or warnings
+is( $text->append('wiz'), 'wiz', 'appended wiz onto undef' );
+
+
+#------------------------------------------------------------------------
+# hash()
+#------------------------------------------------------------------------
+
+$text = $Text->new('hash text');
+my $hash = $text->hash();
+is( ref $hash, 'HASH', 'got hash' );
+is( scalar keys %$hash, 1, 'one text item in hash' );
+is( $hash->{ text }, 'hash text', 'got hash text' );
+
+$text = $Text->new('hash name');
+$hash = $text->hash('name');
+is( ref $hash, 'HASH', 'got hash' );
+is( scalar keys %$hash, 1, 'one name item in hash' );
+is( $hash->{ name }, 'hash name', 'got hash name' );
+
+$text = $Text->new('hash values');
+$hash = $text->hash('name', age => 35, beard => 'goatee');
+is( ref $hash, 'HASH', 'got hash values' );
+is( scalar keys %$hash, 3, 'three items in hash' );
+is( $hash->{ name }, 'hash values', 'got hash values' );
+is( $hash->{ age }, '35', 'got age' );
+is( $hash->{ beard }, 'goatee', 'got a goatee beard' );
+
+
+
+#------------------------------------------------------------------------
+# some simple accessor tests
+#------------------------------------------------------------------------
+
+$text = $Text->new('Hello World');
is( $text->text(), 'Hello World', 'Hello World by method' );
is( $text->upper(), 'HELLO WORLD', 'HELLO WORLD upper' );
is( $text->lower(), 'hello world', 'hello world lower' );
is( $text->text(), 'Hello World', 'Hello World unchanged' );
+
my $upper = $text->can('upper');
my $source = 'Goodbye Cruel World';
is( &$upper(\$source), 'GOODBYE CRUEL WORLD', 'upper sub call' );
@@ -41,7 +140,12 @@
#========================================================================
+# TODO: object tests
+#
+ok( 1, 'TODO: lots more Text object tests' );
+#========================================================================
+
sub tvm {
my ($vmeth, @args) = @_;
@@ -52,7 +156,7 @@
ok( ! defined tvm( nonsuch => 'hello' ), 'undefined handler' );
$text = 'The foo string';
-my ($list, $hash);
+my $list;
#------------------------------------------------------------------------
@@ -100,9 +204,10 @@
is( tvm( push => $text, ' more foo', ' even more foo' ),
'The foo string more foo even more foo', 'multiple push' );
-is( tvm( suffix => $text, ' more foo' ),
+is( tvm( append => $text, ' more foo' ),
'The foo string more foo', 'single append' );
-is( tvm( suffix => $text, ' more foo', ' even more foo' ),
+
+is( tvm( append => $text, ' more foo', ' even more foo' ),
'The foo string more foo even more foo', 'multiple append' );
is( tvm( shift => $text, 'The ' ),
@@ -112,12 +217,14 @@
is( tvm( unshift => $text, 'This is ' ),
'This is The foo string', 'single unshift' );
+
is( tvm( unshift => $text, 'And this', ' ', 'still is', ' ' ),
'And this still is The foo string', 'multiple unshift' );
-is( tvm( prefix => $text, 'This is ' ),
+is( tvm( prepend => $text, 'This is ' ),
'This is The foo string', 'single prepend' );
-is( tvm( prefix => $text, 'And this', ' ', 'still is', ' ' ),
+
+is( tvm( prepend => $text, 'And this', ' ', 'still is', ' ' ),
'And this still is The foo string', 'multiple prepend' );