Permalink
Browse files

* added map.t and math.t

git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@341 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information...
1 parent eb4e01f commit 0de05388a63ccb8983337570dfdba4f1b4ef705a @abw committed Mar 12, 2002
Showing with 178 additions and 0 deletions.
  1. +149 −0 t/map.t
  2. +29 −0 t/math.t
View
149 t/map.t
@@ -0,0 +1,149 @@
+#============================================================= -*-perl-*-
+#
+# t/map.t
+#
+# Test the Template::Map module.
+#
+# Written by Andy Wardley <abw@kfs.org>
+#
+# Copyright (C) 2000 Andy Wardley. All Rights Reserved.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the same terms as Perl itself.
+#
+# $Id$
+#
+#========================================================================
+
+use strict;
+use lib qw( ./lib ../lib );
+use Template::Test qw( :all );
+$^W = 1;
+
+# just testing
+ok(1);
+exit();
+
+use Template::Map;
+
+#$Template::Map::DEBUG = 1;
+#$Template::Test::DEBUG = 0;
+#$Template::Parser::DEBUG = 1;
+#$Template::Directive::PRETTY = 1;
+$Template::Test::PRESERVE = 1;
+
+
+my $map = Template::Map->new();
+assert( $map );
+
+my $res = $map->map('foo');
+assert( $res );
+assert( ref $res eq 'ARRAY' );
+match( scalar @$res, 1 );
+match( $res->[0], 'foo' );
+
+
+$map = Template::Map->new( default => 'bar' );
+assert( $map );
+
+$res = $map->map('foo');
+assert( $res );
+assert( ref $res eq 'ARRAY' );
+match( scalar @$res, 2 );
+match( $res->[0], 'foo' );
+match( $res->[1], 'bar' );
+
+
+$map = Template::Map->new( prefix => 'my/', default => 'bar' );
+assert( $map );
+
+$res = $map->map('foo');
+assert( $res );
+assert( ref $res eq 'ARRAY' );
+match( scalar @$res, 2 );
+match( $res->[0], 'my/foo' );
+match( $res->[1], 'bar' );
+
+
+$map = Template::Map->new( {
+ prefix => 'my/',
+ suffix => '.tt2',
+ default => 'bar',
+} );
+assert( $map );
+
+$res = $map->map('foo');
+assert( $res );
+assert( ref $res eq 'ARRAY' );
+match( scalar @$res, 2 );
+match( $res->[0], 'my/foo.tt2' );
+match( $res->[1], 'bar' );
+
+
+$map = Template::Map->new( {
+ format => 'try/%s/first',
+ prefix => 'my/',
+ suffix => '.tt2',
+ default => 'bar',
+} );
+assert( $map );
+
+$res = $map->map('foo');
+assert( $res );
+assert( ref $res eq 'ARRAY' );
+match( scalar @$res, 3 );
+match( $res->[0], 'try/foo/first' );
+match( $res->[1], 'my/foo.tt2' );
+match( $res->[2], 'bar' );
+
+
+$map = Template::Map->new( {
+ format => [ 'try/%s/first', 'then/%s/next' ],
+ prefix => 'my/',
+ suffix => '.tt2',
+ default => 'bar',
+} );
+assert( $map );
+
+$res = $map->map('foo');
+assert( $res );
+assert( ref $res eq 'ARRAY' );
+match( scalar @$res, 4 );
+match( $res->[0], 'try/foo/first' );
+match( $res->[1], 'then/foo/next' );
+match( $res->[2], 'my/foo.tt2' );
+match( $res->[3], 'bar' );
+
+
+$map = Template::Map->new( {
+ format => [ 'zeroth', 'try/%s/first', 'then/%s/next' ],
+ default => 'bar',
+} );
+assert( $map );
+
+$res = $map->map('foo');
+assert( $res );
+assert( ref $res eq 'ARRAY' );
+match( scalar @$res, 5 );
+match( $res->[0], 'zeroth' );
+match( $res->[1], 'try/foo/first' );
+match( $res->[2], 'then/foo/next' );
+match( $res->[3], 'foo' );
+match( $res->[4], 'bar' );
+
+match( $map->name('foo'), 'foo' );
+match( $map->name([]), 'list' );
+match( $map->name({}), 'hash' );
+match( $map->name(bless {}, 'Foo::Bar'), 'Foo_Bar' );
+
+package Foo::Bar::Baz;
+
+sub TT_name {
+ return 'floozy';
+}
+
+package main;
+
+match( $map->name(bless {}, 'Foo::Bar::Baz'), 'floozy' );
+
+
View
@@ -0,0 +1,29 @@
+#============================================================= -*-perl-*-
+#
+# t/math.t
+#
+# Test the Math plugin module.
+#
+# Written by Andy Wardley <abw@kfs.org> and ...
+#
+# Copyright (C) 2002 Andy Wardley. All Rights Reserved.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the same terms as Perl itself.
+#
+# $Id$
+#
+#========================================================================
+
+use strict;
+use lib qw( ./lib ../lib );
+use Template::Test qw( :all );
+$^W = 1;
+
+test_expect(\*DATA);
+
+__DATA__
+-- test --
+[% USE Math; Math.sqrt(9) %]
+-- expect --
+3

0 comments on commit 0de0538

Please sign in to comment.