Permalink
Browse files

test for parse-file()

  • Loading branch information...
1 parent 486c525 commit 33cbc49c2461be5711a062076712e3a3bd04a855 @afiskon committed Sep 6, 2012
Showing with 18 additions and 5 deletions.
  1. +4 −4 lib/Sitemap/XML/Parser.pm6
  2. +14 −1 t/main.t
@@ -10,13 +10,13 @@ has $!parser = XML::Parser::Tiny.new;
has $!w3cdtf = DateTime::Format::W3CDTF.new;
method parse-url ( Str $url ) {
- my $data = LWP::Simple.get($url);
- self.parse($data);
+ my $data = LWP::Simple.get($url).decode('UTF-8');
+ return self.parse($data);
}
method parse-file ( Str $fname ) {
my $data = slurp($fname);
- self.parse($data);
+ return self.parse($data);
}
method parse ( Str $data ) {
@@ -45,7 +45,7 @@ method parse ( Str $data ) {
@urls.push( $(%info) );
}
- return @urls;
+ return $( @urls );
}
method !check-loc ( %info is copy ) {
View
@@ -3,6 +3,20 @@ use lib 'lib';
use Test;
use Sitemap::XML::Parser;
+my $parser = Sitemap::XML::Parser.new;
+{ # parse-file() test
+ try {
+ chdir('t');
+ CATCH { return; }
+ }
+ my $rslt = $parser.parse-file('sitemap.xml');
+ ok( $rslt[0]{'loc'}.isa('URI') );
+ $rslt[0]{'loc'} = $rslt[0]{'loc'}.Str;
+ ok( $rslt[0]{'lastmod'}.isa('DateTime') );
+ $rslt[0]{'lastmod'} = $rslt[0]{'lastmod'}.Str;
+ ok($rslt eqv [{loc=>'http://example.com/',lastmod=>'2005-01-01T00:00:00Z',changefreq=>'monthly',priority=>0.8}]);
+}
+
my @invalid = (
'trash',
'<bebebe />',
@@ -112,7 +126,6 @@ for @changefreq_list -> $changefreq {
];
}
-my $parser = Sitemap::XML::Parser.new;
for @invalid -> $sitemap {
dies_ok({ $parser.parse($sitemap) });
}

0 comments on commit 33cbc49

Please sign in to comment.