[Templates-cvs] cvs commit: TT3/t/tag closed.t comment.t embedded.t escape.t open.t text.t variable.t
cvs@template-toolkit.org
cvs@template-toolkit.org
Mon, 08 Nov 2004 18:44:42 +0000
cvs 04/11/08 18:44:41
Modified: t/tag closed.t comment.t embedded.t escape.t open.t
text.t variable.t
Log:
* updated t/tag tests
Revision Changes Path
1.2 +61 -36 TT3/t/tag/closed.t
Index: closed.t
===================================================================
RCS file: /template-toolkit/TT3/t/tag/closed.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- closed.t 2003/12/19 17:30:46 1.1
+++ closed.t 2004/11/08 18:44:40 1.2
@@ -2,14 +2,14 @@
#
# t/tag/closed.t
#
-# Test the Template::TT3::Tag::Closed.pm module.
+# Test the Template::Tag::Closed.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: closed.t,v 1.1 2003/12/19 17:30:46 abw Exp $
+# $Id: closed.t,v 1.2 2004/11/08 18:44:40 abw Exp $
#
#========================================================================
@@ -17,17 +17,19 @@
use warnings;
use lib qw( ./lib ../lib ../../lib );
-use Template::TT3::Tag::Closed;
-use Test::More tests => 69;
+use Template::Tag::Closed;
+use Template::Test;
+plan(51);
+
my $DEBUG = grep /^--?d(ebug)?$/, @ARGV;
-$Template::TT3::Tag::DEBUG = $DEBUG;
+$Template::Tag::DEBUG =
+$Template::Tag::Closed::DEBUG = $DEBUG;
my $tag;
-my $pkg = 'Template::TT3::Tag::Closed';
-my $def = $Template::TT3::Tag::Closed::TAG;
+my $pkg = 'Template::Tag::Closed';
+my $def = $Template::Tag::Closed::TAG;
my $alt = {
- name => 'angles',
start => '<*',
end => '*>',
};
@@ -36,36 +38,29 @@
my $pkgtag = $pkg->pkgtag();
ok( $pkgtag, 'got class package tag' );
is( $pkgtag->{ start }, $def->{ start }, 'class package tag start' );
-is( $pkgtag->{ name }, $def->{ name }, 'class package tag name' );
# create default tag object
$tag = $pkg->new() || die $pkg->error();
ok( $tag, 'created a tag' );
is( $tag->start(), $def->{ start }, "start tag is $def->{ start }" );
-is( $tag->name(), $def->{ name }, "tag name is $def->{ name }" );
# test object pkgtag() method
$pkgtag = $tag->pkgtag();
ok( $pkgtag, 'got object package tag' );
is( $pkgtag->{ start }, $def->{ start }, 'object package tag start' );
-is( $pkgtag->{ name }, $def->{ name }, 'object package tag name' );
# update start/end tags and name
is( $tag->start($alt->{ start }), $alt->{ start }, 'set start tag' );
is( $tag->end($alt->{ end }), $alt->{ end }, 'set end tag' );
is( $tag->start(), $alt->{ start }, "start tag is $alt->{ start }" );
is( $tag->end(), $alt->{ end }, "end tag is $alt->{ end }" );
-is( $tag->name('frank'), 'frank', 'set tag name to frank' );
-is( $tag->name(), 'frank', 'tag name is now frank' );
# create custom tag object
$tag = $pkg->new($alt) || die $pkg->error();
ok( $tag, 'created alt tag' );
is( $tag->start(), $alt->{ start }, "custom start tag is $alt->{ start }" );
is( $tag->end(), $alt->{ end }, "custom end tag is $alt->{ end }" );
-is( $tag->name(), $alt->{ name }, "custom tag name is $alt->{ name }" );
-is( $tag->name('frank'), 'frank', "set custom tag name to frank" );
-is( $tag->name(), 'frank', 'custom tag name is now frank' );
+
#------------------------------------------------------------------------
@@ -73,7 +68,7 @@
#------------------------------------------------------------------------
package Template::Test::Tag1;
-use base qw( Template::TT3::Tag::Closed );
+use base qw( Template::Tag::Closed );
package main;
@@ -84,38 +79,31 @@
ok( $pkgtag, 'got Tag1 package tag' );
is( $pkgtag->{ start }, $def->{ start }, 'Tag1 class package tag start' );
is( $pkgtag->{ end }, $def->{ end }, 'Tag1 class package tag end' );
-is( $pkgtag->{ name }, $def->{ name }, 'Tag1 class package tag name' );
# create default tag object
$tag = $pkg->new() || die $pkg->error();
ok( $tag, 'created a Tag1 tag' );
is( $tag->start(), $def->{ start }, "Tag1 start tag is $def->{ start }" );
is( $tag->end(), $def->{ end }, "Tag1 end tag is $def->{ end }" );
-is( $tag->name(), $def->{ name }, "Tag1 name is $def->{ name }" );
# test object pkgtag() method
$pkgtag = $tag->pkgtag();
ok( $pkgtag, 'got Tag1 object package tag' );
is( $pkgtag->{ start }, $def->{ start }, 'Tag1 object package tag start' );
is( $pkgtag->{ end }, $def->{ end }, 'Tag1 object package tag end' );
-is( $pkgtag->{ name }, $def->{ name }, 'Tag1 package tag name' );
# update start/end tags
is( $tag->start($alt->{ start }), $alt->{ start }, 'set Tag1 start tag' );
is( $tag->end($alt->{ end }), $alt->{ end }, 'set Tag1 end tag' );
is( $tag->start(), $alt->{ start }, "Tag1 start tag is $alt->{ start }" );
is( $tag->end(), $alt->{ end }, "Tag1 end tag is $alt->{ end }" );
-is( $tag->name('barry'), 'barry', 'set tag name to barry' );
-is( $tag->name(), 'barry', 'tag name is now barry' );
# create custom tag object
$tag = $pkg->new($alt) || die $pkg->error();
ok( $tag, 'created alt Tag1 tag' );
is( $tag->start(), $alt->{ start }, "custom Tag1 start tag is $alt->{ start }" );
is( $tag->end(), $alt->{ end }, "custom Tag1 end tag is $alt->{ end }" );
-is( $tag->name(), $alt->{ name }, "custom Tag1 name is $alt->{ name }" );
-is( $tag->name('eric'), 'eric', "set Tag1 name to eric" );
-is( $tag->name(), 'eric', 'Tag1 name is now eric' );
+
#------------------------------------------------------------------------
@@ -123,13 +111,12 @@
#------------------------------------------------------------------------
package Template::Test::Tag2;
-use base qw( Template::TT3::Tag::Closed );
+use base qw( Template::Tag::Closed );
use vars qw( $TAG @PARSED );
$TAG = {
start => '[[',
end => ']]',
- name => 'squares',
};
package main;
@@ -142,38 +129,76 @@
ok( $pkgtag, 'got Tag2 package tag' );
is( $pkgtag->{ start }, $def->{ start }, 'Tag2 class package tag start' );
is( $pkgtag->{ end }, $def->{ end }, 'Tag2 class package tag end' );
-is( $pkgtag->{ name }, $def->{ name }, 'Tag2 class package tag name' );
# create default tag object
$tag = $pkg->new() || die $pkg->error();
ok( $tag, 'created a tag' );
is( $tag->start(), $def->{ start }, "Tag2 start tag is $def->{ start }" );
is( $tag->end(), $def->{ end }, "Tag2 end tag is $def->{ end }" );
-is( $tag->name(), $def->{ name }, "Tag2 name is $def->{ name }" );
# test object pkgtag() method
$pkgtag = $tag->pkgtag();
ok( $pkgtag, 'got Tag2 object package tag' );
is( $pkgtag->{ start }, $def->{ start }, 'Tag2 object package tag start' );
is( $pkgtag->{ end }, $def->{ end }, 'Tag2 object package tag end' );
-is( $pkgtag->{ name }, $def->{ name }, 'Tag2 package tag name' );
# update start/end tags and name
is( $tag->start($alt->{ start }), $alt->{ start }, 'set subclass start tag' );
is( $tag->end($alt->{ end }), $alt->{ end }, 'set subclass end tag' );
is( $tag->start(), $alt->{ start }, "subclass start tag is $alt->{ start }" );
is( $tag->end(), $alt->{ end }, "subclass end tag is $alt->{ end }" );
-is( $tag->name('mandy'), 'mandy', 'set tag name to mandy' );
-is( $tag->name(), 'mandy', 'tag name is now mandy' );
# create custom tag object
$tag = $pkg->new($alt) || die $pkg->error();
ok( $tag, 'created alt subclass tag' );
is( $tag->start(), $alt->{ start }, "custom subclass start tag is $alt->{ start }" );
is( $tag->end(), $alt->{ end }, "custom subclass end tag is $alt->{ end }" );
-is( $tag->name(), $alt->{ name }, "custom Tag2 name is $alt->{ name }" );
-is( $tag->name('doris'), 'doris', "set Tag2 name to doris" );
-is( $tag->name(), 'doris', 'Tag2 name is now doris' );
+
+
+
+#------------------------------------------------------------------------
+# test scan() and match() methods
+#------------------------------------------------------------------------
+
+package Template::Test::ScanTag;
+use base qw( Template::Tag::Closed );
+
+our $MATCH;
+
+sub parse {
+ my ($self, $textref, $handler) = @_;
+ $$textref =~ / \G .* /cgxs;
+ $MATCH = "[$self->{ match }->{ line }/$self->{ match }->{ start }]";
+ return $handler;
+}
+
+package main;
+
+$pkg = 'Template::Test::ScanTag';
+$tag = $pkg->new();
+
+my $text = "Hello World\nFoo Bar baz\nblah blah %] THE END";
+my $line = 1;
+my $match = { line => $line, char => 0, start => 'FOO' };
+
+is( $tag->scan(\$text, 'ok', $match)
+ || die($tag->error()), 'ok', 'called tag scan()' );
+
+is( $match->{ lines }, 2, 'size is 2' );
+$match->{ line } += delete $match->{ lines };
+$match->{ start } = 'BAR';
+
+is( $Template::Test::ScanTag::MATCH, '[1/FOO]',
+ "match is $Template::Test::ScanTag::MATCH" );
+
+pos $text = 0;
+
+is( $tag->scan(\$text, 'still ok', $match), 'still ok',
+ 'called tag scan() again' );
+is( $match->{ lines }, 2, 'size is 2' );
+
+is( $Template::Test::ScanTag::MATCH, '[3/BAR]',
+ "match is $Template::Test::ScanTag::MATCH" );
+
-__END__
1.3 +25 -26 TT3/t/tag/comment.t
Index: comment.t
===================================================================
RCS file: /template-toolkit/TT3/t/tag/comment.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- comment.t 2004/01/26 12:00:22 1.2
+++ comment.t 2004/11/08 18:44:40 1.3
@@ -2,14 +2,14 @@
#
# t/tag/comment.t
#
-# Test the Template::TT3::Tag::Comment.pm module.
+# Test the Template::Tag::Comment.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: comment.t,v 1.2 2004/01/26 12:00:22 abw Exp $
+# $Id: comment.t,v 1.3 2004/11/08 18:44:40 abw Exp $
#
#========================================================================
@@ -17,44 +17,42 @@
use warnings;
use lib qw( ./lib ../lib ../../lib );
-use Template::TT3::Base;
-use Template::TT3::Document;
-use Template::TT3::Scanner;
-use Template::TT3::Tag::Comment;
-use Test::More tests => 9;
+use Template::Base;
+use Template::Handler;
+use Template::Scanner;
+use Template::Tag::Comment;
+use Template::Test;
-my $DEBUG = grep /^--?d(ebug)?$/, @ARGV;
-$Template::TT3::Tag::DEBUG =
-$Template::TT3::Tag::Comment::DEBUG =
-$Template::TT3::Tag::Closed::DEBUG =
-$Template::TT3::Scanner::DEBUG = $DEBUG;
+plan(8);
+my $DEBUG = grep /^--?d(ebug)?$/, @ARGV;
+$Template::Tag::DEBUG =
+$Template::Tag::Comment::DEBUG =
+$Template::Tag::Closed::DEBUG =
+$Template::Scanner::DEBUG = $DEBUG;
-my $pkg = 'Template::TT3::Tag::Comment';
+my $hpkg = 'Template::Handler';
+my $pkg = 'Template::Tag::Comment';
my $tag = $pkg->new() || die $pkg->error();
ok( $tag, 'created a tag' );
-is( $tag->name(), 'comment', 'name is comment' );
-my $scanpkg = 'Template::TT3::Scanner';
-my $scanner = $scanpkg->new( tags => $tag)
+my $scanpkg = 'Template::Scanner';
+my $scanner = $scanpkg->new( tags => [ comment => $tag ])
|| die $scanpkg->error();
ok( $scanner, 'created a scanner' );
my $text = "# the animal\nThe cat sat on\n# The place\nthe mat # and shat";
print STDERR "INPUT: [$text]\n" if $DEBUG;
-my $docpkg = 'Template::TT3::Document';
-my $document = $docpkg->new( name => 'comment', text => \$text)
- || die $docpkg->error();
-ok( $document, 'created a document' );
+my $handler = $hpkg->new( type => 'template')
+ || die $hpkg->error();
+ok( $handler, 'created a handler' );
-$document->scan($scanner) || die $document->error();
+$scanner->scan($text, $handler) || die $scanner->error();
ok( 1, 'scanned document' );
-
-my $body = $document->body();
-ok( $body, 'got document body' );
-#print $document->dump_list($body);
+my $body = $handler->end();
+ok( $body, 'got handler body' );
my $output = body_text($body);
is( $output, "The cat sat on\nthe mat # and shat", 'output matches' );
@@ -89,7 +87,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;
1.2 +22 -26 TT3/t/tag/embedded.t
Index: embedded.t
===================================================================
RCS file: /template-toolkit/TT3/t/tag/embedded.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- embedded.t 2004/01/28 17:57:17 1.1
+++ embedded.t 2004/11/08 18:44:40 1.2
@@ -2,14 +2,14 @@
#
# t/tag/embedded.t
#
-# Test the Template::TT3::Tag::Embedded.pm module.
+# Test the Template::Tag::Embedded.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: embedded.t,v 1.1 2004/01/28 17:57:17 abw Exp $
+# $Id: embedded.t,v 1.2 2004/11/08 18:44:40 abw Exp $
#
#========================================================================
@@ -17,48 +17,43 @@
use warnings;
use lib qw( ./lib ../lib ../../lib );
-use Template::TT3::Base;
-use Template::TT3::Handler;
-use Template::TT3::Parser;
-use Template::TT3::Scanner;
-use Template::TT3::Generator::Debug;
-use Template::TT3::Tag::Embedded;
-use Template::TT3::Test qw( :all );
-use Test::More tests => 30;
+use Template::Base;
+use Template::Handler;
+use Template::Parser;
+use Template::Scanner;
+use Template::Generator::Debug;
+use Template::Tag::Embedded;
+use Template::Test qw( :all );
+plan(28);
our $DEBUG =
-$Template::TT3::Tag::Embedded::DEBUG =
+$Template::Tag::Embedded::DEBUG =
grep /^--?d(ebug)?$/, @ARGV;
# create a parser for the embedded tag
-my $parserpkg = 'Template::TT3::Parser';
+my $parserpkg = 'Template::Parser';
my $parser = $parserpkg->new()
|| die $parserpkg->error();
ok( $parser, 'created a parser' );
# create an embedded tag
-my $tagpkg = 'Template::TT3::Tag::Embedded';
+my $tagpkg = 'Template::Tag::Embedded';
my $tag = $tagpkg->new( parser => $parser )
|| die $tagpkg->error();
ok( $tag, 'created a tag' );
-is( $tag->name(), 'embedded', 'name is embedded' );
# create a scanner using the embedded tag
-my $scanpkg = 'Template::TT3::Scanner';
-my $scanner = $scanpkg->new( tags => $tag )
+my $scanpkg = 'Template::Scanner';
+my $scanner = $scanpkg->new( tags => { embedded => $tag } )
|| die $scanpkg->error();
ok( $scanner, 'created a scanner' );
# create a generator to display parsed directives
-my $genpkg = 'Template::TT3::Generator::Debug';
+my $genpkg = 'Template::Generator::Debug';
my $generator = $genpkg->new()
|| die $genpkg->error();
ok( $generator, "created a generator" );
-# create a handler to receive parse events
-my $handler = Template::TT3::Handler->new();
-ok( $handler, 'created a handler' );
-
test_expect({
handler => \&parse,
ok => \&ok,
@@ -69,8 +64,9 @@
my $test = shift;
my $input = $test->{ input };
my $result;
-
- ok( $handler->start(), "starting test $test->{ name }" );
+
+ my $handler = Template::Handler->new( type => 'template' );
+ ok( $handler, "created a handler for $test->{ name }" );
# go scan!
if ($scanner->scan(\$input, $handler)) {
@@ -262,14 +258,14 @@
-- test error --
before ${foo.bar(plonk} after
-- expect --
-<ERROR:line 1: missing ')' at end of argument list>
+<ERROR:line 1: parser error - missing ')' at end of argument list>
-- test multi-line error --
before ${foo('one',
'two').bar('zonk)}. after
-- expect --
-<ERROR:lines 1-2: unterminated string (missing ')>
+<ERROR:lines 1-2: parser error - unterminated string (missing ')>
-- test error in line further down --
one
@@ -283,4 +279,4 @@
${eight('nine)}
ten
-- expect --
-<ERROR:line 9: unterminated string (missing ')>
+<ERROR:line 9: parser error - unterminated string (missing ')>
1.4 +48 -113 TT3/t/tag/escape.t
Index: escape.t
===================================================================
RCS file: /template-toolkit/TT3/t/tag/escape.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- escape.t 2004/01/26 12:00:22 1.3
+++ escape.t 2004/11/08 18:44:40 1.4
@@ -2,14 +2,14 @@
#
# t/tag/escape.t
#
-# Test the Template::TT3::Tag::Escape.pm module.
+# Test the Template::Tag::Escape.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: escape.t,v 1.3 2004/01/26 12:00:22 abw Exp $
+# $Id: escape.t,v 1.4 2004/11/08 18:44:40 abw Exp $
#
#========================================================================
@@ -17,16 +17,18 @@
use warnings;
use lib qw( ./lib ../lib ../../lib );
-use Template::TT3::Base;
-use Template::TT3::Document;
-use Template::TT3::Scanner;
-use Template::TT3::Tag::Escape;
-use Test::More tests => 41;
+use Template::Base;
+use Template::Scanner;
+use Template::Handler;
+use Template::Tag::Escape;
+use Template::Test;
+plan(26);
+
my $DEBUG = grep /^--?d(ebug)?$/, @ARGV;
-$Template::TT3::Tag::DEBUG =
-$Template::TT3::Tag::Escape::DEBUG =
-$Template::TT3::Scanner::DEBUG = $DEBUG;
+$Template::Tag::DEBUG =
+$Template::Tag::Escape::DEBUG =
+$Template::Scanner::DEBUG = $DEBUG;
#------------------------------------------------------------------------
@@ -34,10 +36,9 @@
#------------------------------------------------------------------------
package Template::Test::Tag;
-use base qw( Template::TT3::Tag::Open );
-use vars qw( $TAG );
-$TAG = {
- name => 'dummy',
+use base qw( Template::Tag::Open );
+our $TAG = {
+ name => 'cmd',
start => '$',
end => undef,
};
@@ -63,43 +64,41 @@
start => '$',
});
my $cmdtag = $tagpkg->new({
- name => 'cmd',
start => qr/(?m:^=)/,
});
ok( $vartag, 'created a var tag' );
ok( $cmdtag, 'created a cmd tag' );
+my $hpkg = 'Template::Handler';
+
#------------------------------------------------------------------------
# basic tests
#------------------------------------------------------------------------
-my $pkg = 'Template::TT3::Tag::Escape';
+my $pkg = 'Template::Tag::Escape';
my $tag = $pkg->new() || die $pkg->error();
ok( $tag, 'created a tag' );
-is( $tag->name(), 'escape', 'name is escape' );
-my $scanpkg = 'Template::TT3::Scanner';
-my $scanner = $scanpkg->new( tags => [ $tag, $vartag ] )
+my $scanpkg = 'Template::Scanner';
+my $scanner = $scanpkg->new( tags => [ escape => $tag, variable => $vartag ] )
|| die $scanpkg->error();
ok( $scanner, 'created a scanner' );
my $text = 'The cat \$at \on\\\\the $mat and \"shat\"';
print STDERR "INPUT: [$text]\n" if $DEBUG;
-
-my $docpkg = 'Template::TT3::Document';
-my $document = $docpkg->new( name => 'escapedoc', text => \$text)
- || die $docpkg->error();
-ok( $document, 'created a document' );
+my $handler = $hpkg->new( type => 'template')
+ || die $hpkg->error();
+ok( $handler, 'created a handler' );
-$document->scan($scanner) || die $document->error();
+$scanner->scan($text, $handler) || die $scanner->error();
ok( 1, 'scanned document' );
-my $body = $document->body();
-ok( $body, 'got document body' );
+my $body = $handler->end();
+ok( $body, 'got handler body' );
my $output = body_text($body);
is( $output, 'The cat $at on\\the [var@line 1:mat] and "shat"',
@@ -110,32 +109,30 @@
print STDERR "OUTPUT: [$output]\n" if $DEBUG;
-
#------------------------------------------------------------------------
# try custom escape and range
#------------------------------------------------------------------------
-$tag = $pkg->new( name => 'pipedream', escape => '|', range => '$')
+$tag = $pkg->new( escape => '|', range => '$')
|| die $pkg->error();
ok( $tag, 'created a custom tag' );
-is( $tag->name(), 'pipedream', 'custom name is pipedream' );
-$scanner = $scanpkg->new( tags => [ $tag, $vartag ] )
+$scanner = $scanpkg->new( tags => [ escape => $tag, variable => $vartag ] )
|| die $scanpkg->error();
ok( $scanner, 'created a custom scanner' );
$text = 'The cat |$at |on| the $mat and \"shat\"';
print STDERR "CUSTOM INPUT: [$text]\n" if $DEBUG;
-$document = $docpkg->new( name => 'pipedoc', text => \$text)
- || die $docpkg->error();
-ok( $document, 'created a custom document' );
+$handler = $hpkg->new( type => 'template')
+ || die $hpkg->error();
+ok( $handler, 'created a handler' );
-$document->scan($scanner) || die $document->error();
-ok( 1, 'scanned pipe document' );
+$scanner->scan($text, $handler) || die $scanner->error();
+ok( 1, 'scanned document' );
-$body = $document->body();
-ok( $body, 'got pipe document body' );
+$body = $handler->end();
+ok( $body, 'got pipe handler body' );
$output = body_text($body);
is( $output, 'The cat $at |on| the [var@line 1:mat] and \\"shat\\"',
@@ -146,35 +143,34 @@
print STDERR "CUSTOM OUTPUT: [$output]\n" if $DEBUG;
-
#------------------------------------------------------------------------
# now regex escape and range
#------------------------------------------------------------------------
my $esctag = $pkg->new({
- name => 'regex',
escape => qr/(?m:^\\)/, # \ at start of line
range => qr/=|\$/, # escapes = or $
}) || die $pkg->error();
ok( $esctag, 'created a regex tag' );
-is( $esctag->name(), 'regex', 'regex name' );
-$scanner = $scanpkg->new( tags => [ $esctag, $vartag, $cmdtag ] )
+$scanner = $scanpkg->new( tags => [ escape => $esctag,
+ variable => $vartag,
+ command => $cmdtag ] )
|| die $scanpkg->error();
ok( $scanner, 'created a regex scanner' );
$text = "foo\n=bar\n\\=baz\n\$wing\n\\\$wang\n\\\\\$wong";
print STDERR "REGEX INPUT: [$text]\n" if $DEBUG;
-$document = $docpkg->new( name => 'regexdoc', text => \$text)
- || die $docpkg->error();
-ok( $document, 'created a regex document' );
+$handler = $hpkg->new( type => 'template')
+ || die $hpkg->error();
+ok( $handler, 'created a handler' );
-$document->scan($scanner) || die $document->error();
-ok( 1, 'scanned regex document' );
+$scanner->scan($text, $handler) || die $scanner->error();
+ok( 1, 'scanned document' );
-$body = $document->body();
+$body = $handler->end();
ok( $body, 'got regex document body' );
my $expect = "foo\n[cmd\@line 2:bar]\n=baz\n[var\@line 4:wing]\n\$wang\n\\\\[var\@line 6:wong]";
@@ -186,71 +182,8 @@
print STDERR "REGEX OUTPUT: [$output]\n" if $DEBUG;
-#------------------------------------------------------------------------
-# try and confuse the scanner by providing a basic tag regex that is
-# longer than the escape regex. The scanner sorts regexen according to
-# length to always match longest first, which in this case will be the
-# wrong order... unless we do something about it....
-# [time passes]
-#
-# Hmm, on second thoughts, it doesn't cause any problems at all. The
-# non-greedy quantifier on the (.*?) part preceeding the tag match
-# seems to make it work OK.
-#
-# Hmm, on third thoughts, maybe it does... but only if the escape char is
-# the same as another magic char.
-#------------------------------------------------------------------------
-
-# var = '$|#|var:|\'
-# esc = '\'
-
-$vartag = $tagpkg->new({
- name => 'var',
- start => qr/\$|#|var:|\\/,
-});
-ok( $vartag, 'created a complex var tag' );
-
-$pkg = 'Template::TT3::Tag::Escape';
-$esctag = $pkg->new( start => qr/\\./, strip => qr/^\\/ );
-ok( $esctag, 'created a basic escape tag' );
-
-$scanner = $scanpkg->new( tags => [ $esctag, $vartag ] )
- || die $scanpkg->error();
-ok( $scanner, 'created a confused scanner' );
-
-$text = 'foo $bar \\$baz \\\\$bong then #bang \\yes \#bang and var:foo not \var:bar';
-print STDERR "CONFUSED INPUT: [$text]\n" if $DEBUG;
-
-$document = $docpkg->new( name => 'confused', text => \$text)
- || die $docpkg->error();
-ok( $document, 'created a confused document' );
-
-ok( ! $document->scan($scanner), 'confused scanner should fail' );
-
-$scanner = $scanpkg->new( tags => [ $esctag, $vartag ], sort => 0 )
- || die $scanpkg->error();
-ok( $scanner, 'created a less confused scanner' );
-
-$document = $docpkg->new( name => 'lessconfused', text => $text)
- || die $docpkg->error();
-ok( $document, 'created a less confused document' );
-
-$document->scan($scanner) || die "scan error: ", $document->error();
-ok( 1, 'scanned less confused document' );
-$body = $document->body();
-ok( $body, 'got less confused document body' );
-
-$output = body_text($body);
-$expect = 'foo [var@line 1:bar] $baz \\[var@line 1:bong] then [var@line 1:bang] yes #bang and [var@line 1:foo] not var:bar';
-is( $output, $expect, 'less confused output matches' );
-
-dump_body($body) if $DEBUG;
-
-print STDERR "REGEX OUTPUT: [$output]\n" if $DEBUG;
-
-
sub dump_body {
my $body = shift;
@@ -275,10 +208,10 @@
return $newtext;
}
-
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;
@@ -292,6 +225,8 @@
return $text;
}
+
+
__END__
1.2 +13 -11 TT3/t/tag/open.t
Index: open.t
===================================================================
RCS file: /template-toolkit/TT3/t/tag/open.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- open.t 2004/01/24 11:44:01 1.1
+++ open.t 2004/11/08 18:44:40 1.2
@@ -2,14 +2,14 @@
#
# t/tag/open.t
#
-# Test the Template::TT3::Tag::Open.pm module.
+# Test the Template::Tag::Open.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: open.t,v 1.1 2004/01/24 11:44:01 abw Exp $
+# $Id: open.t,v 1.2 2004/11/08 18:44:40 abw Exp $
#
#========================================================================
@@ -17,11 +17,14 @@
use warnings;
use lib qw( ./lib ../lib ../../lib );
-use Template::TT3::Tag::Open;
-use Test::More tests => 6;
+use Template::Tag::Open;
+use Template::Test;
+plan(6);
+
my $DEBUG = grep /^--?d(ebug)?$/, @ARGV;
-$Template::TT3::Tag::DEBUG = $DEBUG;
+$Template::Tag::Open::DEBUG =
+$Template::Tag::DEBUG = $DEBUG;
#------------------------------------------------------------------------
@@ -29,7 +32,7 @@
#------------------------------------------------------------------------
package Template::Test::ScanTag;
-use base qw( Template::TT3::Tag::Open );
+use base qw( Template::Tag::Open );
our $MATCH;
@@ -47,13 +50,13 @@
my $text = "Hello World\nFoo Bar baz\nblah blah THE END";
my $line = 1;
-my $match = { line => $line, char => 0, start => 'FOO' };
+my $match = { line => $line, offset => 0, start => 'FOO' };
is( $tag->scan(\$text, 'ok', $match)
|| die($tag->error()), 'ok', 'called tag scan()' );
-is( $match->{ size }, 2, 'size is 2' );
-$match->{ line } += delete $match->{ size };
+is( $match->{ lines }, 2, 'size is 2' );
+$match->{ line } += delete $match->{ lines };
$match->{ start } = 'BAR';
is( $Template::Test::ScanTag::MATCH, '[1/FOO]',
@@ -63,10 +66,9 @@
is( $tag->scan(\$text, 'still ok', $match), 'still ok',
'called tag scan() again' );
-is( $match->{ size }, 2, 'size is 2' );
+is( $match->{ lines }, 2, 'size is 2' );
is( $Template::Test::ScanTag::MATCH, '[3/BAR]',
"match is $Template::Test::ScanTag::MATCH" );
-__END__
1.3 +9 -7 TT3/t/tag/text.t
Index: text.t
===================================================================
RCS file: /template-toolkit/TT3/t/tag/text.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- text.t 2004/01/26 12:00:22 1.2
+++ text.t 2004/11/08 18:44:40 1.3
@@ -2,14 +2,14 @@
#
# t/tag/text.t
#
-# Test the Template::TT3::Tag::Text.pm module.
+# Test the Template::Tag::Text.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: text.t,v 1.2 2004/01/26 12:00:22 abw Exp $
+# $Id: text.t,v 1.3 2004/11/08 18:44:40 abw Exp $
#
#========================================================================
@@ -18,15 +18,17 @@
use lib qw( ./lib ../lib ../../lib );
use Template::Base;
-use Template::TT3::Tag::Text;
-use Test::More tests => 6;
+use Template::Tag::Text;
+use Template::Test;
+plan(6);
+
my $DEBUG = grep /^--?d(ebug)?$/, @ARGV;
-$Template::TT3::Tag::DEBUG = $DEBUG;
+$Template::Tag::DEBUG = $DEBUG;
#------------------------------------------------------------------------
package Template::Test::Handler;
-use base qw( Class::Base );
+use base qw( Template::Base );
sub text {
my ($self, $text) = @_;
@@ -37,7 +39,7 @@
#------------------------------------------------------------------------
package main;
-my $pkg = 'Template::TT3::Tag::Text';
+my $pkg = 'Template::Tag::Text';
my $tag = $pkg->new() || die $pkg->error();
ok( $tag, 'created a text tag' );
1.2 +25 -24 TT3/t/tag/variable.t
Index: variable.t
===================================================================
RCS file: /template-toolkit/TT3/t/tag/variable.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- variable.t 2004/01/28 16:11:45 1.1
+++ variable.t 2004/11/08 18:44:40 1.2
@@ -9,7 +9,7 @@
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
-# $Id: variable.t,v 1.1 2004/01/28 16:11:45 abw Exp $
+# $Id: variable.t,v 1.2 2004/11/08 18:44:40 abw Exp $
#
#========================================================================
@@ -17,48 +17,47 @@
use warnings;
use lib qw( ./lib ../lib ../../lib );
-use Template::TT3::Base;
-use Template::TT3::Handler;
-use Template::TT3::Parser;
-use Template::TT3::Scanner;
-use Template::TT3::Generator::Debug;
-use Template::TT3::Tag::Variable;
-use Template::TT3::Test qw( :all );
-use Test::More tests => 30;
+use Template::Base;
+use Template::Handler;
+use Template::Parser;
+use Template::Scanner;
+use Template::Tag::Variable;
+use Template::Generator::Debug;
+use Template::Test qw( :all );
+plan(28);
our $DEBUG =
-$Template::TT3::Tag::Variable::DEBUG =
+$Template::Tag::DEBUG =
+$Template::Tag::Variable::DEBUG =
+$Template::Scanner::DEBUG =
+$Template::Generator::DEBUG =
+$Template::Generator::Debug::DEBUG =
grep /^--?d(ebug)?$/, @ARGV;
# create a parser for the variable tag
-my $parserpkg = 'Template::TT3::Parser';
+my $parserpkg = 'Template::Parser';
my $parser = $parserpkg->new()
|| die $parserpkg->error();
ok( $parser, 'created a parser' );
# create a variable tag
-my $tagpkg = 'Template::TT3::Tag::Variable';
+my $tagpkg = 'Template::Tag::Variable';
my $tag = $tagpkg->new( parser => $parser )
|| die $tagpkg->error();
ok( $tag, 'created a tag' );
-is( $tag->name(), 'variable', 'name is variable' );
# create a scanner using the variable tag
-my $scanpkg = 'Template::TT3::Scanner';
-my $scanner = $scanpkg->new( tags => $tag )
+my $scanpkg = 'Template::Scanner';
+my $scanner = $scanpkg->new( tags => { var => $tag } )
|| die $scanpkg->error();
ok( $scanner, 'created a scanner' );
# create a generator to display parsed directives
-my $genpkg = 'Template::TT3::Generator::Debug';
+my $genpkg = 'Template::Generator::Debug';
my $generator = $genpkg->new()
|| die $genpkg->error();
ok( $generator, "created a generator" );
-# create a handler to receive parse events
-my $handler = Template::TT3::Handler->new();
-ok( $handler, 'created a handler' );
-
test_expect({
handler => \&parse,
ok => \&ok,
@@ -70,7 +69,8 @@
my $input = $test->{ input };
my $result;
- ok( $handler->start(), "starting test $test->{ name }" );
+ my $handler = Template::Handler->new( type => 'template' );
+ ok( $handler, "created a handler for $test->{ name }" );
# go scan!
if ($scanner->scan(\$input, $handler)) {
@@ -103,6 +103,7 @@
<text: sat on the mat>
>
+
-- test feline co-location --
The $cat sat on the $mat
-- expect --
@@ -257,13 +258,13 @@
-- test trailing dot error --
before $foo.bar. after
-- expect --
-<ERROR:line 1: missing item after '.' (got 'after')>
+<ERROR:line 1: parser error - missing item after '.' (got 'after')>
-- test trailing dot multi-line error --
before $foo('one',
'two').bar. after
-- expect --
-<ERROR:lines 1-2: missing item after '.' (got 'after')>
+<ERROR:lines 1-2: parser error - missing item after '.' (got 'after')>
-- test error in line further down --
one
@@ -277,4 +278,4 @@
$eight('nine)
ten
-- expect --
-<ERROR:line 9: unterminated string (missing ')>
+<ERROR:line 9: parser error - unterminated string (missing ')>