1#!/usr/bin/perl -T
2
3# This tests the DOMException and EventException interfaces, which are both
4# implemented by HTML::DOM::Exception
5
6use strict; use warnings;
7
8use Test::More tests => 22;
9
10
11# -------------------------#
12# Test 1: load the module
13
14BEGIN { use_ok 'HTML::DOM::Exception', ':all'; }
15
16# -------------------------#
17# Tests 2-17: check constants
18
19{
20	my $x;
21
22	for (qw/ INDEX_SIZE_ERR DOMSTRING_SIZE_ERR HIERARCHY_REQUEST_ERR
23	        WRONG_DOCUMENT_ERR INVALID_CHARACTER_ERR
24	       NO_DATA_ALLOWED_ERR NO_MODIFICATION_ALLOWED_ERR
25	     NOT_FOUND_ERR NOT_SUPPORTED_ERR INUSE_ATTRIBUTE_ERR
26	  INVALID_STATE_ERR SYNTAX_ERR INVALID_MODIFICATION_ERR
27	NAMESPACE_ERR INVALID_ACCESS_ERR /) {
28		eval "is $_, " . ++$x . ", '$_'";
29	}
30	is UNSPECIFIED_EVENT_TYPE_ERR, 0, 'UNSPECIFIED_EVENT_TYPE_ERR';
31}
32
33# --------------------------------------- #
34# Tests 18-22: constructor and object interface #
35
36{
37	my $x = new HTML::DOM::Exception NOT_SUPPORTED_ERR,
38		'Seems we lack this feature';
39	isa_ok $x, 'HTML::DOM::Exception', 'the new exception object';
40	is "$x", "Seems we lack this feature\n",
41		'string overloading that adds a newline';
42	is 0+$x, NOT_SUPPORTED_ERR, 'numeric overloading';
43	is $x->code, NOT_SUPPORTED_ERR, 'code';
44	$x = new HTML::DOM::Exception NOT_SUPPORTED_ERR,
45		qq'Another exceptional object\n';
46	is $x, "Another exceptional object\n",
47	    'string overloading when there is already a trailing newline';
48}
49