1#!/usr/bin/perl -T
2
3use strict; use warnings; use lib 't';
4
5use Test::More tests => 17;
6use utf8;
7
8
9# -------------------------#
10# Test 1: load the module
11
12BEGIN { use_ok 'HTML::DOM'; }
13
14# -------------------------#
15# Test 2: constructor
16
17our $elem = (our $doc = new HTML::DOM)->createElement('div');
18$elem->appendChild(our $t = createTextNode $doc 'text contents');
19isa_ok $t, 'HTML::DOM::CharacterData';
20
21# -------------------------#
22# Tests 3-9: splitText
23
24eval { $t-> splitText(-9) };
25isa_ok $@, 'HTML::DOM::Exception',
26	'$@ (after splitText with a negative offset)';
27cmp_ok $@, '==', HTML::DOM::Exception::INDEX_SIZE_ERR,
28    'splitText with a negative offset throws a index size error';
29
30eval { $t-> splitText(89) };
31isa_ok $@, 'HTML::DOM::Exception',
32	'$@ (after splitText when offset > length)';
33cmp_ok $@, '==', HTML::DOM::Exception::INDEX_SIZE_ERR,
34    'splitText throws a index size error when offset > length';
35
36# All right, enough of this playing. Let's do it for real tnow.
37
38our $u = $t->splitText(5);
39is $t->data, 'text ', 'text node loses part of its text after splitText';
40is $u->data, 'contents', 'the new text node got it';
41ok firstChild $elem == $t && (childNodes $elem)[1] == $u &&
42	lastChild$elem == $u, 'the tree was modified correctly';
43
44$elem->removeChild($u);
45
46# -------------------------#
47# Tests 10-16: splitText16
48
49eval { $t-> splitText16(-9) };
50isa_ok $@, 'HTML::DOM::Exception',
51	'$@ (after splitText16 with a negative offset)';
52cmp_ok $@, '==', HTML::DOM::Exception::INDEX_SIZE_ERR,
53    'splitText16 with a negative offset throws a index size error';
54
55eval { $t-> splitText16(89) };
56isa_ok $@, 'HTML::DOM::Exception',
57	'$@ (after splitText16 when offset > length)';
58cmp_ok $@, '==', HTML::DOM::Exception::INDEX_SIZE_ERR,
59    'splitText throws a index size error when offset > length';
60
61# All right, enough of this playing. Let's do it for real tnow.
62
63$t->data('π �� 3.14');
64$u = $t->splitText16(5);
65is $t->data, 'π �� ', 'text node loses part of its text after splitText16';
66is $u->data, '3.14', 'and it was the new text node that got it';
67ok firstChild $elem == $t && (childNodes $elem)[1] == $u &&
68	lastChild$elem == $u,
69	'the tree was modified correctly by splitText16';
70
71# -------------------------#
72# Test 17: nodeValue
73
74is $doc->createTextNode('aoeusnth')->nodeValue, 'aoeusnth', 'nodeValue';
75