1#============================================================= -*-perl-*-
2#
3# t/except.t
4#
5# Test the Template::Exception module.
6#
7# Written by Andy Wardley <abw@kfs.org>
8#
9# Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
10# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
11#
12# This is free software; you can redistribute it and/or modify it
13# under the same terms as Perl itself.
14#
15# $Id$
16#
17#========================================================================
18
19use strict;
20use lib qw( ./lib ../lib );
21use Template::Test;
22use Template::Exception;
23
24my $text = 'the current output buffer';
25
26my $e1 = Template::Exception->new('e1.type', 'e1.info');
27my $e2 = Template::Exception->new('e2.type', 'e2.info', \$text);
28
29ok( $e1 );
30ok( $e2 );
31ok( $e1->type() eq 'e1.type' );
32ok( $e2->info() eq 'e2.info' );
33
34my @ti = $e1->type_info();
35ok( $ti[0] eq 'e1.type' );
36ok( $ti[1] eq 'e1.info' );
37
38ok( $e2->as_string() eq 'e2.type error - e2.info' );
39ok( $e2->text() eq 'the current output buffer' );
40
41my $prepend = 'text to prepend ';
42$e2->text(\$prepend);
43ok( $e2->text() eq 'text to prepend the current output buffer' );
44
45my @handlers = ('something', 'e2', 'e1.type');
46ok( $e1->select_handler(@handlers) eq 'e1.type' );
47ok( $e2->select_handler(@handlers) eq 'e2' );
48
49my $e3 = Template::Exception->new('e3.type', 'e3.info', undef);
50ok( $e3 );
51ok( $e3->text() eq '');
52ok( $e3->as_string() eq 'e3.type error - e3.info' );
53
54# test to check that overloading fallback works properly
55# by using a non explicitly defined op
56ok( $e3 ne "fish");
57