File: 09_setget.t

package info (click to toggle)
libxml-feedpp-perl 0.95-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 400 kB
  • sloc: perl: 1,877; sh: 28; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 2,535 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# ----------------------------------------------------------------
    use strict;
    use Test::More tests => 145;
    BEGIN { use_ok('XML::FeedPP') };
# ----------------------------------------------------------------
    my $ftitle = "Title of the site";
    my $fdesc  = "Description of the site";
    my $ilink  = "http://www.kawa.net/";
# ----------------------------------------------------------------
    my $hash = {
        'elem1'             =>  'ELEM01',
        'elem2@attr2'       =>  'ATTR02',
        'elem3'             =>  'ELEM03',
        'elem3@attr3'       =>  'ATTR03',
        'elem4'             =>  'ELEM03',
        'elem4@attr4'       =>  'ATTR04',
        'elem4@attr5'       =>  'ATTR05',
        'elem4/elem6'       =>  'ELEM06',
        'elem7/elem8'       =>  'ELEM08',
        'elem7/elem8@attr8' =>  'ATTR08',
        'elem7/elem8'       =>  'ELEM08',
        'elem9/elem10'      =>  'ATTR10',
        'elem9/elem11'          =>  'ELEM10',
	'elem9/elem12@attr12'   =>  'ELEM12',
        '@attr13'           =>  'ATTR13',
    };
# ----------------------------------------------------------------
    my $noexists = [
        'not:exist',
        'not@exist',
        'not/exist',
        'not/exist@attr',
        'elem1/not:exist',
        'elem1/not:exist@attr',
        'elem2/not:exist',
        'elem2/not:exist@attr',
        'elem4/not:exist',
        'elem4/not:exist@attr',
    ];
# ----------------------------------------------------------------
    my $feeds = [
        XML::FeedPP::RDF->new(),
        XML::FeedPP::RSS->new(),
        XML::FeedPP::RDF->new(),
    ];
# ----------------------------------------------------------------
    foreach my $feed1 ( @$feeds ) {
        my $type = ref $feed1;
        $feed1->title( $ftitle );
        $feed1->set( %$hash );
        foreach my $key ( sort keys %$hash ) {
            is( $feed1->get($key), $hash->{$key}, "$type channel $key" );
        }
        foreach my $key ( @$noexists ) {
            ok( ! defined $feed1->get($key), "$type channel $key" );
        }
        my $item1 = $feed1->add_item( $ilink );
        $item1->set( %$hash );
        foreach my $key ( sort keys %$hash ) {
            is( $item1->get($key), $hash->{$key}, "$type item $key" );
        }
        foreach my $key ( @$noexists ) {
            ok( ! defined $item1->get($key), "$type item $key" );
        }
    }
# ----------------------------------------------------------------
;1;
# ----------------------------------------------------------------