Permalink
Browse files

t/02-parse-url.t, t/03-parse-file.t

  • Loading branch information...
1 parent d8df08e commit fc08e8cb785bdaa7f143d99611eb39bd130fcd4b @afiskon committed Sep 6, 2012
Showing with 50 additions and 17 deletions.
  1. +2 −1 TODO.txt
  2. +3 −2 lib/Sitemap/XML/Parser.pm6
  3. +2 −14 t/{main.t → 01-parse.t}
  4. +21 −0 t/02-parse-url.t
  5. +22 −0 t/03-parse-file.t
View
@@ -1,3 +1,4 @@
-* tests for parse-url() and parse-file()
+* more POD
* seperated module for stemap index parsing -- http://www.sitemaps.org/ru/protocol.html#index
* gzip support
+* ssl support
@@ -8,9 +8,10 @@ class Sitemap::XML::Parser;
has $!parser = XML::Parser::Tiny.new;
has $!w3cdtf = DateTime::Format::W3CDTF.new;
+has $.lwp = LWP::Simple.new;
method parse-url ( Str $url ) {
- my $data = LWP::Simple.get($url).decode('UTF-8');
+ my $data = $.lwp.get($url).decode('UTF-8');
return self.parse($data);
}
@@ -45,7 +46,7 @@ method parse ( Str $data ) {
@urls.push( $(%info) );
}
- return $( @urls );
+ return @urls;
}
method !check-loc ( %info is copy ) {
View
@@ -3,20 +3,6 @@ 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 />',
@@ -126,6 +112,8 @@ for @changefreq_list -> $changefreq {
];
}
+my $parser = Sitemap::XML::Parser.new;
+
for @invalid -> $sitemap {
dies_ok({ $parser.parse($sitemap) });
}
View
@@ -0,0 +1,21 @@
+use v6;
+use lib 'lib';
+use Test;
+use Test::Mock;
+use Sitemap::XML::Parser;
+
+my $lwp = mocked(LWP::Simple, returning => {
+ get => q{<urlset><url><loc>http://example.ru</loc></url></urlset>}.encode('ascii')
+ });
+
+my $parser = Sitemap::XML::Parser.new(lwp => $lwp);
+my $rslt = $parser.parse-url('http://eax.me/sitemap.xml');
+
+check-mock($lwp, *.called('get', times => 1));
+
+ok( $rslt[0]{'loc'}.isa('URI') );
+$rslt[0]{'loc'} = $rslt[0]{'loc'}.Str;
+
+ok($rslt eqv [{ loc => "http://example.ru" }] );
+
+done;
View
@@ -0,0 +1,22 @@
+use v6;
+use lib 'lib';
+use Test;
+use Sitemap::XML::Parser;
+
+try {
+ chdir('t');
+ CATCH { return; }
+}
+
+my $parser = Sitemap::XML::Parser.new;
+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}]);
+
+done;

0 comments on commit fc08e8c

Please sign in to comment.