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

cvs@template-toolkit.org cvs@template-toolkit.org
Wed, 24 Mar 2004 13:09:30 +0000


cvs         04/03/24 13:09:30

  Added:       t        cache.t
  Log:
  * added t/cache.t to test Template::Cache
  
  Revision  Changes    Path
  1.1                  TT3/t/cache.t
  
  Index: cache.t
  ===================================================================
  #============================================================= -*-perl-*-
  #
  # t/cache.t
  #
  # Test the Template::Cache.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: cache.t,v 1.1 2004/03/24 13:09:30 abw Exp $
  #
  #========================================================================
  
  use strict;
  use warnings;
  
  use lib qw( ./lib ../lib );
  use Template::Cache;
  use Test::More tests => 17;
  
  # run with -d flag to enable debugging, e.g. perl cache.t -d
  my $DEBUG = 
  $Template::Cache::DEBUG =
  grep(/^--?d(ebug)?/, @ARGV);
  
  
  #------------------------------------------------------------------------
  # some basic test of get/set methods
  #------------------------------------------------------------------------
  
  my $pkg = 'Template::Cache';
  my $cache = $pkg->new( size => 3, debug => $DEBUG ) || die $pkg->error();
  ok( $cache, 'created a cache object' );
  
  # add one
  ok( $cache->set( pi => 3.14 ), 'set pi' );
  is( $cache->get('pi'), 3.14, 'get pi' );
  is( $cache->get('pi'), 3.14, 'get pi again' );
  
  # add another
  ok( $cache->set( e => 2.71 ), 'set e' );
  is( $cache->get('e'), 2.71, 'get e' );
  is( $cache->get('e'), 2.71, 'get e again' );
  
  # update 
  ok( $cache->set( e => 2.718 ), 'set e more precise' );
  is( $cache->get('e'), 2.718, 'get e more precise' );
  
  # add another
  ok( $cache->set( a => 'foo' ), 'set a' );
  
  # check we can still get them all
  is( $cache->get('pi'), 3.14, 'still got pi' );
  is( $cache->get('e'), 2.718, 'still got e' );
  is( $cache->get('a'), 'foo', 'still got a' );
  
  # this should push us over the size limit
  ok( $cache->set( b => 'bar' ), 'set b' );
  
  # pi should have been discarded
  ok( ! defined $cache->get('pi'),'no more pi' );
  is( $cache->declined(), "not found in cache: pi", 'cache declined pi' );
  
  # but e should still be there
  is( $cache->get('e'), 2.718, 'still got e though' );
  
  print STDERR $cache->_slot_report() if $DEBUG;
  
  __END__
  
  # Local Variables:
  # mode: perl
  # perl-indent-level: 4
  # indent-tabs-mode: nil
  # End:
  #
  # vim: expandtab shiftwidth=4: