File: add-item-insert-vs-append.t

package info (click to toggle)
libxml-rss-libxml-perl 0.3004-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 500 kB
  • ctags: 236
  • sloc: perl: 6,679; xml: 41; makefile: 15
file content (89 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download | duplicates (7)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl

# Test the add_item(mode => "insert")

use strict;
use warnings;

use Test::More tests => 3;

use XML::RSS::LibXML;

sub contains
{
    local $Test::Builder::Level = $Test::Builder::Level + 1;
    my ($rss, $pattern, $msg) = @_;
    my $rss_output = $rss->as_string();
    my $ok = like ($rss_output, $pattern, $msg);
    if (! $ok)
    {
        diag("Could not find the substring [$pattern] in:{{{{\n$rss_output\n}}}}\n");
    }
}

sub create_rss
{
    my $rss = XML::RSS::LibXML->new(version => "2.0");

    $rss->channel(
        title => "freshmeat.net",
        link  => "http://freshmeat.net",
        description => "the one-stop-shop for all your Linux software needs",
        );

    $rss->add_item(
        title => "GTKeyboard 0.85",
        link  => "http://freshmeat.net/news/1999/06/21/930003829.html"
        );
    
    return $rss;
}

{
    my $rss = create_rss();

    $rss->add_item(
        title => "gcc 10.0.10",
        link => "http://gcc-compiler.tld/",
    );

    # TEST
    contains($rss,
        qr{(?sm)<title>GTKeyboard 0.85</title>.+<title>gcc 10.0.10</title>},
        "Checking for second item after first item when add_item without mode."
    );
}

{
    my $rss = create_rss();

    $rss->add_item(
        mode => "append",
        title => "gcc 10.0.10",
        link => "http://gcc-compiler.tld/",
    );

    # TEST
    contains($rss,
        qr{(?sm)<title>GTKeyboard 0.85</title>.+<title>gcc 10.0.10</title>},
        "Checking for second item after first item when add_item with mode == append."
    );
}

{
    my $rss = create_rss();

    $rss->add_item(
        mode => "insert",
        title => "gcc 10.0.10",
        link => "http://gcc-compiler.tld/",
    );

    # TEST
    contains($rss,
        qr{(?sm)<title>gcc 10.0.10</title>.+<title>GTKeyboard 0.85</title>},
        "Checking for second item before first item when add_item with mode == insert."
    );
}