7
use lib File::Spec->catdir(File::Spec->curdir,"t");
19
my $doc='<d>foo bar fooo baz</d>';
21
my $t= XML::Twig->parse( $doc);
22
$t->root->split( '(fo+)', e => { att => '$1' } );
23
is( $t->sprint, '<d><e att="foo">foo</e> bar <e att="fooo">fooo</e> baz</d>', 'split, with $1 on attribute value');
25
$t= XML::Twig->parse( $doc);
26
$t->root->split( '(fo+)', e => { '$1' => 'v$1' } );
27
is( $t->sprint, '<d><e foo="vfoo">foo</e> bar <e fooo="vfooo">fooo</e> baz</d>', 'split, with $1 on attribute name and value');
29
$t= XML::Twig->parse( $doc);
30
$t->root->split( '(fo+)', '$1' );
31
is( $t->sprint, '<d><foo>foo</foo> bar <fooo>fooo</fooo> baz</d>', 'split, with $1 on tag name');
34
$t= XML::Twig->parse( $doc);
35
$t->root->split( '(foo+)', '$1', '' );
36
is( $t->sprint, '<d><foo>foo</foo> bar <fooo>fooo</fooo> baz</d>', 'split, with $1 on tag name');
38
$t= XML::Twig->parse( $doc);
39
$t->root->split( '(fo+)(.*?)(a[rz])', x => { class => 'f' }, '', a => { class => 'x' });
40
is( $t->sprint, '<d><x class="f">foo</x> b<a class="x">ar</a> <x class="f">fooo</x> b<a class="x">az</a></d>', 'split, checking that it works with non capturing grouping');
42
$t= XML::Twig->parse( $doc);
43
$t->root->split( '(fo+)(.*?)(a[rz])', x => { class => '$1' }, '', a => { class => '$3' });
44
is( $t->sprint, '<d><x class="foo">foo</x> b<a class="ar">ar</a> <x class="fooo">fooo</x> b<a class="az">az</a></d>', 'split, with $1 and $3 on att value');
48
{ my $t= XML::Twig->parse( '<d><e>e1</e><s><e>e2</e></s></d>');
49
is( join( '-', $t->findvalues( '//e')), 'e1-e2', 'findvalues');
52
{ my $html='<html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"/></head><body><p>boo</p></body></html>';
54
my $well_formed = qq{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">$html};
55
my $short_doctype = qq{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">$html};
57
my $t= XML::Twig->new->parse( $well_formed);
58
is_like( $t->sprint, $well_formed, 'valid xhtml');
59
if( _use( 'HTML::TreeBuilder'))
60
{ my $th= XML::Twig->new->parse_html( $well_formed);
61
is_like( $t->sprint, $well_formed, 'valid xhtml (parsed as html)');
63
my $t3= XML::Twig->new->parse_html( $short_doctype);
64
is_like( $t3->sprint, $html, 'xhtml without SYSTEM in DOCTYPE (parsed as html, no DOCTYPE output)');
66
my $t4= XML::Twig->new( output_html_doctype => 1)->parse_html( $short_doctype);
67
is_like( $t4->sprint, $well_formed, 'xhtml without SYSTEM in DOCTYPE (parsed as html, with proper DOCTYPE output)');
72
my $t2= XML::Twig->new->safe_parse( $short_doctype);
73
nok( $t2, 'xhtml without SYSTEM in DOCTYPE');