perl-XML-LibXML / t / 47load_xml_callbacks.t

#!/usr/bin/perl
 
# Fix the handling of XML::LibXML::InputCallbacks at load_xml().
# - https://rt.cpan.org/Ticket/Display.html?id=58190
# - The problem was that the input callbacks were not cloned in
# _clone().

use strict;
use warnings;

use Test::More tests => 3;

use XML::LibXML;

{
    my $got_open = 0;
    my $got_read = 0;
    my $got_close = 0;

    my $input_callbacks = XML::LibXML::InputCallback->new();
    $input_callbacks->register_callbacks([
            sub { 1 },
            sub { $got_open = 1; open my $fh, '<', shift; return $fh; },
            sub { $got_read = 1; my $buffer; read(shift, $buffer, shift); return $buffer; },
            sub { $got_close = 1; close shift },
        ]);

    my $xml_parser = XML::LibXML->new();
    $xml_parser->input_callbacks($input_callbacks);

    my $TEST_FILENAME = 'example/dromeds.xml';

    $xml_parser->load_xml(location => $TEST_FILENAME);

    # TEST
    ok ($got_open, 'load_xml() encountered the open InputCallback');

    # TEST
    ok ($got_read, 'load_xml() encountered the read InputCallback');

    # TEST
    ok ($got_close, 'load_xml() encountered the close InputCallback');
}
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.