Skip to content

Commit

Permalink
* additional tests for Template::Map
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@613 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information
abw committed Mar 17, 2003
1 parent 9509fab commit d10da64
Showing 1 changed file with 60 additions and 10 deletions.
70 changes: 60 additions & 10 deletions t/map.t
Expand Up @@ -17,12 +17,11 @@

use strict;
use lib qw( ./lib ../lib );
use Template::Test qw( :all );
use Test::More tests => 28;
$^W = 1;

# just testing
ok(1);
exit();

use Template::Map;

Expand All @@ -32,16 +31,67 @@ use Template::Map;
#$Template::Directive::PRETTY = 1;
$Template::Test::PRESERVE = 1;

#------------------------------------------------------------------------
package Some::Kind::Of::Noodle;
sub new { bless { }, $_[0] }
sub TT_name { return 'noodle' }
#------------------------------------------------------------------------

my $map = Template::Map->new();
assert( $map );

my $res = $map->map('foo');
assert( $res );
assert( ref $res eq 'ARRAY' );
match( scalar @$res, 1 );
match( $res->[0], 'foo' );
package main;

my $pkg = 'Template::Map';
my $map = $pkg->new() || die $pkg->error();
ok( $map, 'created a default map' );
is( $map->name('foo'), 'text', "'foo' is text" );
is( $map->name(['foo']), 'list', "['foo'] is list" );
is( $map->name({ foo => 'bar' }), 'hash', "{ foo => 'bar' } is hash" );
is( $map->name(bless { }, 'Thingy'), 'Thingy', 'Thingy is a Thingy' );
is( $map->name(Some::Kind::Of::Noodle->new()), 'noodle', 'some noodles' );


$map = $pkg->new( map => { TEXT => 'string',
ARRAY => 'array',
'Some::Kind::Of::Noodle' => 'egg_noodle',
'Foo::Bar' => 'fubar' } ) || die $pkg->error();

ok( $map, 'created a custom map' );
is( $map->name('foo'), 'string', "'foo' is string" );
is( $map->name(['foo']), 'array', "['foo'] is array" );
is( $map->name({ foo => 'bar' }), 'hash', "{ foo => 'bar' } is still a hash" );
is( $map->name(bless { }, 'Thingy'), 'Thingy', 'Thingy is a Thingy' );
is( $map->name(bless { }, 'Foo::Bar'), 'fubar', 'Foo::Bar is fubar' );
is( $map->name(Some::Kind::Of::Noodle->new()), 'egg_noodle', 'egg noodle' );


my $names = $map->names('foo') || die $map->error();
ok( $names, 'got names for foo' );
is( ref $names, 'ARRAY', 'an array' );
is( scalar @$names, 1, 'one item in array' );
is( $names->[0], 'foo', 'name is foo' );

$map = $pkg->new( format => 'x/%s.tt' );
$names = $map->names('foo') || die $map->error();
ok( $names, 'got format names for foo' );
is( $names->[0], 'x/foo.tt', 'first name is x/foo.tt' );

$map = $pkg->new( format => [ 'x/%s.tt', 'y/%s.tt' ] );
$names = $map->names('bar') || die $map->error();
ok( $names, 'got names for bar' );
is( $names->[0], 'x/bar.tt', 'first name is x/bar.tt' );
is( $names->[1], 'y/bar.tt', 'second name is y/bar.tt' );

$map = $pkg->new( prefix => 'z/', suffix => '.tt' );
$names = $map->names('baz') || die $map->error();
ok( $names, 'got names for baz' );
is( $names->[0], 'z/baz.tt', 'name is z/baz.tt' );

$map = $pkg->new( default => 'pong' );
$names = $map->names('ping') || die $map->error();
ok( $names, 'got names for ping' );
is( $names->[0], 'ping', 'ping' );
is( $names->[1], 'pong', 'pong' );

__END__
$map = Template::Map->new( default => 'bar' );
assert( $map );
Expand Down

0 comments on commit d10da64

Please sign in to comment.