[Templates-cvs] cvs commit: TT3/t/tag directive.t

cvs@template-toolkit.org cvs@template-toolkit.org
Tue, 09 Nov 2004 13:31:38 +0000


cvs         04/11/09 13:31:38

  Modified:    t/tag    directive.t
  Log:
  * updated tests for Template::Tag::Directive
  
  Revision  Changes    Path
  1.6       +60 -40    TT3/t/tag/directive.t
  
  Index: directive.t
  ===================================================================
  RCS file: /template-toolkit/TT3/t/tag/directive.t,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- directive.t	2004/01/28 17:56:51	1.5
  +++ directive.t	2004/11/09 13:31:37	1.6
  @@ -2,14 +2,14 @@
   #
   # t/tag/directive.t
   #
  -# Test the Template::TT3::Tag::Directive.pm module.
  +# Test the Template::Tag::Directive.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: directive.t,v 1.5 2004/01/28 17:56:51 abw Exp $
  +# $Id: directive.t,v 1.6 2004/11/09 13:31:37 abw Exp $
   #
   #========================================================================
   
  @@ -17,58 +17,71 @@
   use warnings;
   
   use lib qw( ./lib ../lib ../../lib );
  -use Template::TT3::Base;
  -use Template::TT3::Document;
  -use Template::TT3::Scanner;
  -use Template::TT3::Tag::Directive;
  -use Test::More tests => 16;
  +use Template::Base;
  +use Template::Handler;
  +use Template::Scanner;
  +use Template::Tag::Directive;
  +use Template::Test;
   
  +plan(14);
  +
   my $DEBUG = grep /^--?d(ebug)?$/, @ARGV;
  -#$Template::TT3::Tag::DEBUG = 
  -#$Template::TT3::Scanner::DEBUG =
  -$Template::TT3::Handler::DEBUG =
  -$Template::TT3::Tag::Directive::DEBUG = 
  -$Template::TT3::Document::DEBUG = $DEBUG;
  +$Template::Tag::DEBUG = 
  +#$Template::Scanner::DEBUG =
  +$Template::Tag::Directive::DEBUG = 
  +$Template::Handler::DEBUG = $DEBUG;
   
   
  -my $pkg = 'Template::TT3::Tag::Directive';
  +my $pkg = 'Template::Tag::Directive';
   my $tag = $pkg->new() || die $pkg->error();
   ok( $tag, 'created a tag' );
  -is( $tag->name(), 'directive', 'name is directive' );
  +#is( $tag->name(), 'directive', 'name is directive' );
   
  -my $scanpkg = 'Template::TT3::Scanner';
  -my $scanner = $scanpkg->new( tags => $tag ) 
  +my $scanpkg = 'Template::Scanner';
  +my $scanner = $scanpkg->new( tags => [ directive => $tag ]) 
       || die $scanpkg->error();
   ok( $scanner, 'created a scanner' );
   
  -my $text = "The [% cat \n %] sat  \n [%= on %] the [% \n mat -%] \n\t \t[%# and shat =%]\n\n[% - how about that? -%]\n\n";
  -print STDERR "INPUT: [$text]\n" if $DEBUG;
  +my $text =<<EOF;
  +The [% cat 
  + %] sat  
  + [%= on %] the [% 
  + mat -%] 
  +\t \t[%# and shat =%]
  +
  +[% how; 
  +   about;
  +   that
  +-%]
  +[% hello -%]
  +EOF
   
  +print STDERR "INPUT: [$text]\n" if $DEBUG;
   
  -my $docpkg = 'Template::TT3::Document';
  -my $document = $docpkg->new( name => 'dirtag', text => $text ) 
  -    || die $docpkg->error();
  -ok( $document, 'created a document' );
  +my $hpkg = 'Template::Handler';
  +my $handler = $hpkg->new( type => 'template' )
  +    || die $hpkg->error();
  +ok( $handler, 'created a handler' );
   
  -ok( ! defined $document->scan($scanner), 'scanner failed' );
  -is( $document->error(), 'lines 1-2: no parser defined for directive tag', 
  +ok( ! $scanner->scan($text, $handler), 'scanner failed' );
  +is( $scanner->error(), 'line 1: no parser defined for directive tag', 
       'no parser defined' );
   
   
  -
   #------------------------------------------------------------------------
   # define a simple custom parser
   #------------------------------------------------------------------------
   
   package Template::Test::Parser;
  -use Template::TT3::Parser;
  -use base qw( Template::TT3::Parser );
  +use Template::Parser;
  +use base qw( Template::Parser );
   
   sub parse_directive {
       my ($self, $textref, $handler, $match) = @_;
  -    if ($$textref =~ / \G (.+) $/cgx) {
  -        my $locn = $match->{ size } 
  -            ? join('-', $match->{ line }, $match->{ line } + $match->{ size })
  +
  +    if ($$textref =~ / \G (\w+) /cgsx) {
  +        my $locn = $match->{ lines } 
  +            ? join('-', $match->{ line }, $match->{ line } + $match->{ lines })
               : $match->{ line };
           my $text = "[$locn/$1]";
           return [ text => \$text ];
  @@ -87,10 +100,10 @@
   
   $tag = $pkg->new( parser => $parser ) || die $pkg->error();
   ok( $tag, 'created a tag with parser' );
  -is( $tag->name(), 'directive', 'name is directive' );
  +#is( $tag->name(), 'directive', 'name is directive' );
   is( $tag->parser(), $parser, 'parser is installed' );
   
  -$scanner = $scanpkg->new( tags => $tag ) 
  +$scanner = $scanpkg->new( tags => [ directive => $tag ]) 
       || die $scanpkg->error();
   ok( $scanner, 'created a scanner with parser' );
   
  @@ -98,18 +111,24 @@
   print STDERR "INPUT: [$text]\n" if $DEBUG;
   
   
  -$document = $docpkg->new( name => 'dirtag', text => \$text ) 
  -    || die $docpkg->error();
  -ok( $document, 'created a document with parser' );
  +$handler = $hpkg->new( type => 'template' )
  +    || die $hpkg->error();
  +ok( $handler, 'created a handler' );
   
  -ok( $document->scan($scanner), 'scanner suceeded' );
  +ok( $scanner->scan($text, $handler) || die($scanner->error()), 
  +    'scanner succeeded' );
   
  -my $body = $document->body();
  -#print $document->dump_list($body);
  +my $body = $handler->end();
  +#print $scanner->dump_item($body);
   
   my $output = body_text($body);
  +
  +# can't support line ranges with open tags because we haven't scanned
  +# ahead to the end tag yet, so we don't know how long the tag content is
  +#is( $output, "The [1-2/cat] sat [3/on] the [3-4/mat] [7/- how about that?]", 
  +#    'output matches' );
   
  -is( $output, "The [1-2/cat] sat [3/on] the [3-4/mat] [7/- how about that?]", 
  +is( $output, "The [1/cat] sat [3/on] the [3/mat] [7/how][8/about][9/that][11/hello]", 
       'output matches' );
   
   
  @@ -124,7 +143,8 @@
   
   sub body_text {
       my $body = shift;
  -    is( shift @$body, 'template', 'body is a template' );
  +    is( $body->[0], 'template', 'body is a template' );
  +    $body = $body->[1];
       my $text = '';
       while (@$body) {
           my $item = shift @$body;