1package XLSC_Test; 2use strict; 3our $AUTOLOAD; 4use Data::Dumper; 5use Test::More; 6 7my @EVENTS = ( 8 { 9 Event => 'start_document' 10 }, 11 { 12 Event => 'xml_decl', 13 Version => '1.0' 14 }, 15 { 16 Event => 'start_prefix_mapping', 17 Prefix => '', 18 NamespaceURI => 'http://foobar.com', 19 }, 20 { 21 Event => 'start_element', 22 LocalName => 'foo', 23 Prefix => '', 24 Attributes => { 25 '{}xmlns' => { 26 LocalName => 'xmlns', 27 Prefix => '', 28 Value => 'http://foobar.com', 29 Name => 'xmlns', 30 NamespaceURI => '', 31 } 32 }, 33 Name => 'foo', 34 NamespaceURI => 'http://foobar.com', 35 }, 36 { 37 Event => 'start_element', 38 LocalName => 'bar', 39 Prefix => '', 40 Attributes => { 41 '{}x' => { 42 LocalName => 'x', 43 Prefix => '', 44 Value => 1, 45 Name => 'x', 46 NamespaceURI => '' 47 } 48 }, 49 Name => 'bar', 50 NamespaceURI => 'http://foobar.com' 51 }, 52 { 53 Event => 'start_element', 54 LocalName => 'baz', 55 Prefix => '', 56 Attributes => {}, 57 Name => 'baz', 58 NamespaceURI => "http://foobar.com" 59 }, 60 { 61 Event => 'characters', 62 Data => 'whoopla', 63 }, 64 { 65 Event => 'end_element', 66 LocalName => 'baz', 67 Prefix => '', 68 Name => 'baz', 69 NamespaceURI => 'http://foobar.com' 70 }, 71 { 72 Event => 'end_element', 73 LocalName => 'bar', 74 Prefix => '', 75 Name => 'bar', 76 NamespaceURI => 'http://foobar.com' 77 }, 78 { 79 Event => 'end_element', 80 LocalName => 'foo', 81 Prefix => '', 82 Name => 'foo', 83 NamespaceURI => 'http://foobar.com' 84 }, 85 { 86 Event => 'end_prefix_mapping', 87 Prefix => '', 88 NamespaceURI => 'http://foobar.com', 89 } 90); 91 92sub new { bless { events => [ @EVENTS ] }, shift } 93 94sub DESTROY { } 95sub AUTOLOAD { 96 my ($self, $arg) = @_; 97 98 my $got_event = $AUTOLOAD; 99 $got_event =~ s/^.+:://; 100 101 $arg ||= {}; 102 my $expected = shift @{ $self->{events} }; 103 my $event = delete $expected->{Event}; 104 is ($got_event, $event, "event should be $event"); 105 is_deeply( $arg, $expected ); 106} 107 108 109package main; 110use strict; 111use Test::More( tests => 23 ); 112use XML::SAX; 113 114XML::SAX->add_parser( q{XML::LibXML::SAX::ChunkParser} ); 115 116{ 117 my $parser = XML::SAX::ParserFactory->parser( Handler => XLSC_Test->new ); 118 isa_ok($parser, "XML::LibXML::SAX::ChunkParser" ); 119} 120 121{ 122 my @chunks = ( 123 q|<?xml v|, 124 q|ersion="1.0"?>|, 125 q|<foo xml|, 126 q|ns="http://foobar.com">|, 127 q|<|, 128 q|bar x="1"|, 129 q|>|, 130 q|<baz>whoopla</b|, 131 q|az>|, 132 q|<|, 133 q|/|, 134 q|bar>|, 135 q|</foo>|, 136 ); 137 138 my $parser = XML::SAX::ParserFactory->parser( Handler => XLSC_Test->new ); 139 foreach my $chunk (@chunks) { 140 diag("parsing chunk '$chunk'"); 141 $parser->parse_chunk($chunk); 142 } 143}