[Templates-cvs] cvs commit: TT3/t provider.t

cvs@template-toolkit.org cvs@template-toolkit.org
Mon, 29 Mar 2004 17:27:05 +0100


cvs         04/03/29 16:27:04

  Modified:    t        provider.t
  Log:
  more tests
  
  Revision  Changes    Path
  1.6       +22 -19    TT3/t/provider.t
  
  Index: provider.t
  ===================================================================
  RCS file: /template-toolkit/TT3/t/provider.t,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- provider.t	2004/03/24 14:14:30	1.5
  +++ provider.t	2004/03/29 16:27:04	1.6
  @@ -9,7 +9,7 @@
   # This is free software; you can redistribute it and/or modify it
   # under the same terms as Perl itself.
   #
  -# $Id: provider.t,v 1.5 2004/03/24 14:14:30 abw Exp $
  +# $Id: provider.t,v 1.6 2004/03/29 16:27:04 abw Exp $
   #
   #========================================================================
   
  @@ -19,7 +19,7 @@
   use lib qw( ./lib ../lib );
   use File::Spec;
   use Template::Provider;
  -use Test::More tests => 71;
  +use Test::More tests => 72;
   
   my $DEBUG = 
   $Template::Provider::DEBUG =
  @@ -291,7 +291,7 @@
   
   
   #------------------------------------------------------------------------
  -# test fetch() method with real files
  +# test get() method with real files
   #------------------------------------------------------------------------
   
   my $a = File::Spec->catfile($dir, 'prova');
  @@ -302,30 +302,29 @@
   ok( $prov, 'created file provider' );
   
   
  -my $foo = $prov->fetch('foo') || die $prov->error();
  +my $foo = $prov->get('foo') || die $prov->error();
   ok( $foo, 'provided file foo' );
   
   my $text = $foo->text()
       || die $foo->error();
   ok( $text, 'got foo text' );
  -ok( $$text =~ /^This is prova\/foo/, 'got foo text' );
  +ok( $text =~ /^This is prova\/foo/, 'got foo text' );
   
  -my $freshwoz = $prov->fetch('/wiz/waz/woz', fresh => 1) || die $prov->error();
  +my $freshwoz = $prov->get('/wiz/waz/woz', fresh => 1) || die $prov->error();
   ok( $freshwoz, 'provided fresh file woz' );
   
   # check that fresh got set to 1
   is( $freshwoz->fresh(), 1, 'fresh woz file is always fresh' );
   
  -my $woz = $prov->fetch('/wiz/waz/woz', life => 1) || die $prov->error();
  +my $woz = $prov->get('/wiz/waz/woz', life => 1) || die $prov->error();
   ok( $woz, 'provided woz file with life of 1 second' );
   
   # check that life got set to 1
   is( $woz->life(), 1, 'woz life is 1 second' );
   
  -$text = $woz->text()
  -    || die $woz->error();
  +$text = $woz->text() || die $woz->error();
   ok( $text, 'got foo text' );
  -ok( $$text =~ /^This is the woz file/, 'got woz text' );
  +like( $text, qr/^This is the woz file/, 'got woz text' );
   
   # ah! minty fresh breath!
   ok( $woz->fresh(), 'file is fresh' );
  @@ -334,7 +333,7 @@
   my $wozfile = File::Spec->catfile($a, 'wiz/waz/woz');
   rename($wozfile, "$wozfile.old");
   open(FP, ">$wozfile") || die "$wozfile: $!\n";
  -print FP $$text;
  +print FP $text;
   close(FP);
   
   ok( 1, 'going to sleep for a second for freshness check...' );
  @@ -347,19 +346,23 @@
   ok( $freshwoz->fresh(), 'fresh woz is still fresh' );
   
   
  +ok( 1, "TODO: path should be path, not complete path and name???" );
  +#print "woz name: ", $woz->name(), "\n";
  +#print "woz path: ", $woz->path(), "\n";
   
  +
   #------------------------------------------------------------------------
  -# test subclass fetch() method
  +# test subclass get() method
   #------------------------------------------------------------------------
   
  -ok( ! $prov->fetch('nosuchfile'), 'no fetch' );
  -is( $prov->error(), 'nosuchfile not found',
  +ok( ! $prov->get('nosuchfile'), 'no fetch' );
  +is( $prov->error(), 'file not found: nosuchfile',
       'nosuchfile not found' );
   
   package Provider1;
   use base qw( Template::Provider );
   
  -sub fetch {
  +sub get {
       my ($self, $name, $opts) = @_;
       return "fetch: $name";
   }
  @@ -371,7 +374,7 @@
       debug => $DEBUG,
   }) || die Provider->error();
   
  -my $result = $prov->fetch('wiz') || die $prov->error();
  +my $result = $prov->get('wiz') || die $prov->error();
   
   is( $result, 'fetch: wiz', 'fetch wiz' );
   
  @@ -386,7 +389,7 @@
   package Provider2;
   use base qw( Template::Provider );
   
  -sub fetch_path {
  +sub get_path {
       my ($self, $path, $name, $opts) = @_;
       push(@DATA, "$path/$name");
       return 0;
  @@ -399,8 +402,8 @@
       debug => $DEBUG,
   }) || die Provider->error();
   
  -$result = $prov->fetch('waz');
  -is( $result, 0, 'fetch_path() provider declined' );
  +$result = $prov->get('waz');
  +ok( ! defined $result, 'get_path() provider declined' );
   
   is( $DATA[0], '/foo/waz', 'got /foo/waz path' );
   is( $DATA[1], '/bar/waz', 'got /bar/waz path' );