~ubuntu-branches/debian/jessie/libxml-twig-perl/jessie

« back to all changes in this revision

Viewing changes to t/test_3_39.t

  • Committer: Package Import Robot
  • Author(s): Bart Martens
  • Date: 2014-01-05 22:58:27 UTC
  • mfrom: (1.3.5)
  • Revision ID: package-import@ubuntu.com-20140105225827-k8vqp9bffrupmdj5
Tags: 1:3.44-1
* New upstream release.  Closes: #720457, #721395, #694523.
* debian/control: Updated Homepage.  Closes: #720616.
* debian/patches/series: Added.  Enables patches.
* debian/patches/07_691028.diff: Added.  Closes: #691028.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
use strict;
 
3
 
 
4
 
 
5
use Carp;
 
6
use File::Spec;
 
7
use lib File::Spec->catdir(File::Spec->curdir,"t");
 
8
use tools;
 
9
 
 
10
$|=1;
 
11
my $DEBUG=0;
 
12
 
 
13
use XML::Twig;
 
14
 
 
15
my $TMAX=12;
 
16
print "1..$TMAX\n";
 
17
 
 
18
 
19
my $doc='<d>foo bar fooo baz</d>';
 
20
 
 
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');
 
24
 
 
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');
 
28
 
 
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');
 
32
 
 
33
 
 
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');
 
37
 
 
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');
 
41
 
 
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');
 
45
 
 
46
}
 
47
 
 
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');
 
50
}
 
51
 
 
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>';
 
53
 
 
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};
 
56
 
 
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)');
 
62
 
 
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)');
 
65
 
 
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)');
 
68
    }
 
69
  else
 
70
    { skip( 3); }
 
71
 
 
72
  my $t2= XML::Twig->new->safe_parse( $short_doctype);
 
73
  nok( $t2, 'xhtml without SYSTEM in DOCTYPE');
 
74
 
 
75
 
 
76
}
 
77
 
 
78