use strict; use warnings; use XML::Generator::RSS10; use Test::More; BEGIN { eval { require XML::SAX::Writer }; if ($@) { plan skip_all => 'Cannot run tests without XML::SAX::Writer.'; } else { } } { my $out; my $writer = XML::SAX::Writer->new( Output => \$out ); my $gen = XML::Generator::RSS10->new( Handler => $writer, pretty => 1 ); $gen->item( title => 'Item title', link => 'http://example.com/foo', ); $gen->channel( title => 'Channel title', link => 'http://example.com/', description => 'channel description', ); like( $out, qr/<\?xml\s+version=.1\.0.\?>/s, 'has processing instruction' ); like( $out, qr{rdf:RDF[^>]+xmlns=.http://purl.org/rss/1.0/.}s, 'has rdf:RDF tag with proper namespace' ); my %ns = ( dc => 'http://purl.org/dc/elements/1.1/', sy => 'http://purl.org/rss/1.0/modules/syndication/', rdf => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', ); while ( my ( $p, $uri ) = each %ns ) { like( $out, qr{xmlns:\Q$p\E=.\Q$uri\E.}s, "expect to find $p namespace declaration" ); } like( $out, qr{}s, 'expect to find item tag' ); like( $out, qr{]+>.*Item title.*}s, 'expect to find title tag inside item tag' ); like( $out, qr{]+>.*http://example\.com/foo.*}s, 'expect to find link tag inside item tag' ); like( $out, qr{}s, 'expect to find channel tag' ); like( $out, qr{]+>.*Channel title.*}s, 'expect to find title tag inside channel tag' ); like( $out, qr{]+>.*http://example\.com/.*}s, 'expect to find link tag inside channel tag' ); like( $out, qr{]+>.*.+}s, 'expect to find description tag inside channel tag' ); like( $out, qr{]+>.*\s*.*}s, 'expect to find items & rdf:Seq tags inside channel tag' ); like( $out, qr{\s*\s*