PageRenderTime 41ms CodeModel.GetById 30ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/XML-FeedPP/t/23_match_item.t

http://xml-treepp.googlecode.com/
Unknown | 77 lines | 77 code | 0 blank | 0 comment | 0 complexity | f3a6cc95bd7c82f2bad15fb3018e6d5e MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More tests => 22;
 4    BEGIN { use_ok('XML::FeedPP') };
 5# ----------------------------------------------------------------
 6    my $flink  = 'http://www.kawa.net/';
 7    my $ftitle = 'Kawa.net XP';
 8    my $ilink1  = 'http://kawa.at.webry.info/';
 9    my $ilink2  = 'http://kawanet.blogspot.com/';
10    my $ilink3  = 'http://picasaweb.google.com/www.kawa.net/';
11    my $ititle1 = 'Kawa.net Blog (ja)';
12    my $ititle2 = 'Kawa.net Blog (en)';
13    my $ititle3 = 'Kawa.net Albums';
14    my $iorgkey = 'foo:bar';
15    my $iorgv1  = 'test #1';
16    my $iorgv2  = 'testing #2';
17    my $iorgv3  = 'tested #3';
18# ----------------------------------------------------------------
19    my $initfeed = {
20        link        =>  $flink,
21        title       =>  $ftitle,
22    };
23# ----------------------------------------------------------------
24    my $initem1 = {
25        link        =>  $ilink1,
26        title       =>  $ititle1,
27        $iorgkey    =>  $iorgv1,
28    };
29# ----------------------------------------------------------------
30    my $initem2 = {
31        link        =>  $ilink2,
32        title       =>  $ititle2,
33        $iorgkey    =>  $iorgv2,
34    };
35# ----------------------------------------------------------------
36    my $initem3 = {
37        link        =>  $ilink3,
38        title       =>  $ititle3,
39        $iorgkey    =>  $iorgv3,
40    };
41# ----------------------------------------------------------------
42    my $feeds = [
43        XML::FeedPP::RSS->new( %$initfeed ),
44        XML::FeedPP::RDF->new( %$initfeed ),
45        XML::FeedPP::Atom->new( %$initfeed ),
46    ];
47    foreach my $feed1 ( @$feeds ) {
48        my $type = ref $feed1;
49        my $item1 = $feed1->add_item( %$initem1 );
50        my $item2 = $feed1->add_item( %$initem2 );
51        my $item3 = $feed1->add_item( %$initem3 );
52# ----------------------------------------------------------------
53        my @item8 = $feed1->get_item();
54        is( scalar @item8, 3, "$type feed has 3 items" );
55# ----------------------------------------------------------------
56        my @item4 = $feed1->match_item( link => qr/google.com/i );
57        is( scalar @item4, 1, "$type match 1 item by title" );
58        is( $item4[0]->link(), $ilink3, "$type match google.com by link" );
59# ----------------------------------------------------------------
60        my @item5 = $feed1->match_item( title => qr/blog/i );
61        is( scalar @item5, 2, "$type match 2 items by title" );
62# ----------------------------------------------------------------
63        my @item6 = $feed1->match_item( $iorgkey => qr/^test/i );
64        is( scalar @item6, 3, "$type match 3 items by $iorgkey" );
65# ----------------------------------------------------------------
66        my @item7 = $feed1->match_item(
67            link     => $ilink2,
68            title    => qr/blog/i,
69            $iorgkey => qr/testing/i
70        );
71        is( scalar @item7, 1, "$type match 1 item by 3 args" );
72        is( $item7[0]->link(), $ilink2, "$type match blogspot.com by 3 args" );
73# ----------------------------------------------------------------
74    }
75# ----------------------------------------------------------------
76;1;
77# ----------------------------------------------------------------