[Templates-cvs] cvs commit: TT3/t source.t
cvs@template-toolkit.org
cvs@template-toolkit.org
Tue, 23 Mar 2004 14:58:19 +0000
cvs 04/03/23 14:58:19
Added: t source.t
Log:
* added source.t test for Template::Source
Revision Changes Path
1.1 TT3/t/source.t
Index: source.t
===================================================================
#============================================================= -*-perl-*-
#
# t/source.t
#
# Test the Template::Source.pm module.
#
# Written by Andy Wardley <abw@wardley.org>
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id: source.t,v 1.1 2004/03/23 14:58:18 abw Exp $
#
#========================================================================
use strict;
use warnings;
use lib qw( ./lib ../lib );
use Template::Source;
use Template::Provider;
use Test::More tests => 37;
my $DEBUG =
$Template::Source::DEBUG =
grep /^--?d(ebug)?$/, @ARGV;
my $pkg = 'Template::Source';
my ($src, $text, $code);
my $dir = -d 'testdata' ? 'testdata/prova' :
-d 't/testdata' ? 't/testdata/prova' :
-d '../testdata' ? '../testdata/prova' :
die "cannot locate testdata directory";
#------------------------------------------------------------------------
# basic constructor tests
#------------------------------------------------------------------------
# make sure we must provide a name or path
$src = $pkg->new();
ok( ! $src, 'no source' );
is( $pkg->error(), 'no name or path defined', 'no name error' );
# test with a name
$src = $pkg->new( name => 'foo' );
ok( $src, 'created foo source' );
is( $src->name(), 'foo', 'name is foo' );
is( $src->path(), 'foo', 'path is foo' );
is( $src->id(), 'foo', 'id is foo' );
# test with a path
$src = $pkg->new( path => '/foo/bar' );
ok( $src, 'created bar source' );
is( $src->name(), 'bar', 'name is bar' );
is( $src->path(), '/foo/bar', 'path is /foo/bar' );
is( $src->id(), '/foo/bar', 'id is /foo/bar' );
# test with separate names and paths
$src = $pkg->new( path => '/foo/bar', name => 'baz' );
ok( $src, 'created baz source' );
is( $src->name(), 'baz', 'name is baz' );
is( $src->path(), '/foo/bar', 'path is /foo/bar' );
is( $src->id(), '/foo/bar', 'id is /foo/bar' );
#------------------------------------------------------------------------
# test with text and code, both as scalars and scalar refs
#------------------------------------------------------------------------
$src = $pkg->new({
name => 'wam',
text => 'wam text',
code => 'wam code'
});
ok( $src, 'created wam source' );
$text = $src->text();
ok( $text, 'got wam text' );
is( $$text, 'wam text', 'wam text correct' );
$code = $src->code();
ok( $code, 'got wam code' );
is( $$code, 'wam code', 'wam code correct' );
$text = "bam text";
$code = "bam code";
$src = $pkg->new({
name => 'bam',
text => \$text,
code => \$code,
});
ok( $src, 'created bam source' );
is( ${ $src->text() }, 'bam text', 'got bam text' );
is( ${ $src->code() }, 'bam code', 'got bam code' );
#------------------------------------------------------------------------
# test options parameter, options() and option() methods
#------------------------------------------------------------------------
$src = $pkg->new({
name => 'opt',
options => {
cache => 0,
store => 1,
colour => 'orange',
},
});
ok( $src, 'created opt source' );
# direct hash access
my $opts = $src->options();
ok( $opts, 'got options' );
is( $opts->{ cache }, 0, 'do not cache' );
is( $opts->{ store }, 1, 'do store' );
is( $opts->{ colour }, 'orange', 'colour is orange' );
# access via option() method
is( $src->option('cache'), 0, 'do not cache option' );
is( $src->option('store'), 1, 'do store option' );
is( $src->option('colour'), 'orange', 'colour is orange option' );
#------------------------------------------------------------------------
# test with provider for generating unique ids
#------------------------------------------------------------------------
my $provider = Template::Provider->new( id => 'wiz' )
|| die Template::Provider->error();
ok( $provider, 'created provider' );
# test with separate names and paths
$src = $pkg->new( path => '/crash/bang', provider => $provider );
ok( $src, 'created bang source' );
is( $src->name(), 'bang', 'name is bang' );
is( $src->path(), '/crash/bang', 'path is /crash/bang' );
is( $src->id(), 'wiz:/crash/bang', 'id is wiz:/crash/bang' );
#------------------------------------------------------------------------
# TODO: test provider/load arguments by accessing text lazily
#------------------------------------------------------------------------
ok(1, 'TODO: test provider/load options' );
#------------------------------------------------------------------------
# TODO: test time, stat and fresh
#------------------------------------------------------------------------
ok(1, 'TODO: test time/stat/fresh options' );
__END__
# Local Variables:
# mode: perl
# perl-indent-level: 4
# indent-tabs-mode: nil
# End:
#
# vim: expandtab shiftwidth=4: