PageRenderTime 22ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/XML-FeedPP/t/20_limit_item.t

http://xml-treepp.googlecode.com/
Unknown | 51 lines | 45 code | 6 blank | 0 comment | 0 complexity | 88eb9f5a7edbbc78b51a44e22827c291 MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More tests => 40;
 4    BEGIN { use_ok('XML::FeedPP') };
 5# ----------------------------------------------------------------
 6    my $link1 = "http://www.kawa.net/";
 7    my $link2 = "http://www.youtube.com/user/YusukeKawasaki";
 8    my $link3 = "http://picasaweb.google.com/www.kawa.net/";
 9    my $link4 = "http://kawanet.blogspot.com/";
10    my $link5 = "http://del.icio.us/kawa.net";
11# ----------------------------------------------------------------
12    my $feed1 = XML::FeedPP::RSS->new();
13    my $feed2 = XML::FeedPP::RDF->new();
14    my $feed3 = XML::FeedPP::Atom->new();
15# ----------------------------------------------------------------
16    my $links = [ $link1, $link2, $link3, $link4, $link5 ];
17# ----------------------------------------------------------------
18    foreach my $f ( $feed1, $feed2, $feed3 ) {
19        my $mode = ( (ref $f) =~ /([^:]+)$/ )[0];
20        foreach my $u ( @$links ) {
21            $f->add_item( $u );
22        }
23
24        $f->limit_item( 4 );
25        is( scalar $f->get_item(), 4, "$mode limit_item 4 count" );
26        is( $f->get_item(0)->link(), $link1, "$mode limit_item 4 link 0" );
27        is( $f->get_item(3)->link(), $link4, "$mode limit_item 4 link 3" );
28
29        $f->limit_item( -3 );
30        is( scalar $f->get_item(), 3, "$mode limit_recent_item 3 count" );
31        is( $f->get_item(0)->link(), $link2, "$mode limit_recent_item 3 link 0" );
32        is( $f->get_item(2)->link(), $link4, "$mode limit_recent_item 3 link 2" );
33
34        $f->limit_item( 2 );
35        is( scalar $f->get_item(), 2, "$mode limit_item 2 count" );
36        is( $f->get_item(0)->link(), $link2, "$mode limit_item 2 link 0" );
37        is( $f->get_item(1)->link(), $link3, "$mode limit_item 2 link 1" );
38
39        $f->limit_item( -1 );
40        is( scalar $f->get_item(), 1, "$mode limit_recent_item 1 count" );
41        is( $f->get_item(0)->link(), $link3, "$mode limit_recent_item 1 link 0" );
42
43        $f->limit_item( 10 );
44        is( scalar $f->get_item(), 1, "$mode limit_item 10 count" );
45
46        $f->limit_item( -10 );
47        is( scalar $f->get_item(), 1, "$mode limit_recent_item 10 count" );
48    }
49# ----------------------------------------------------------------
50;1;
51# ----------------------------------------------------------------