perl-XML-LibXML / t / 16docnodes.t

use strict;
use warnings;

use XML::LibXML;
# Should be 11.
use Test::More tests => 11;

# this test fails under XML-LibXML-1.00 with a segfault after the
# second parsing.  it was fixed by putting in code in getChildNodes
# to handle the special case where the node was the document node

  my $input = <<EOD;
<doc>
   <clean>   </clean>
   <dirty>   A   B   </dirty>
   <mixed>
      A
      <clean>   </clean>
      B
      <dirty>   A   B   </dirty>
      C
   </mixed>
</doc>
EOD

for my $time (0 .. 2) {
    my $parser = XML::LibXML->new();
    my $doc = $parser->parse_string($input);
    my @a = $doc->getChildnodes;
    # TEST*3
    is(scalar(@a), 1, "1 Child node - time $time");
}

my $parser = XML::LibXML->new();
my $doc = $parser->parse_string($input);
for my $time (0 .. 2) {
    my $e = $doc->getFirstChild;
    # TEST*3
    isa_ok ($e, 'XML::LibXML::Element',
        "first child is an Element - time No. $time"
    );
}

for my $time (0 .. 2) {
    my $e = $doc->getLastChild;
    # TEST*3
    isa_ok($e,'XML::LibXML::Element',
        "last child is an element - time No. $time"
    );
}

##
# Test Ticket 7645
{
    my $in = pack('U', 0x00e4);
    my $doc = XML::LibXML::Document->new();

    my $node = XML::LibXML::Element->new('test');
    $node->setAttribute(contents => $in);
    $doc->setDocumentElement($node);

    # TEST
    is( $node->serialize(), '<test contents="&#xE4;"/>', 'Node serialise works.' );

    $doc->setEncoding('utf-8');
    # Second output
    # TEST
    is( $node->serialize(),
        encodeToUTF8( 'iso-8859-1', '<test contents="�"/>' ),
        'UTF-8 node serialize',
    );
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.