File: 12_direct_attribute.t

package info (click to toggle)
libparse-bbcode-perl 0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 372 kB
  • sloc: perl: 1,652; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 995 bytes parent folder | download | duplicates (3)
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
use Test::More tests => 2;
use_ok('Parse::BBCode');
use strict;
use warnings;

my $p = Parse::BBCode->new({
        direct_attribute => 0,
        tags => {
            'a' => {
                parse => 1,
                code => sub {
                    my ($parser, $attr, $content, $attribute_fallback, $token) = @_;
                    my $at = $token->get_attr;
                    my $href = "";
                    for my $item (@$at) {
                        if ($item->[0] eq 'href') {
                            $href = $item->[1];
                            last;
                        }
                    }
                    return qq{<a href="$href">$$content</a>};
                },
            },
        },
});

my @tests = (
    [ q#[a href="foo"]link[/a]#,
        q#<a href="foo">link</a># ],
);

for (@tests) {
    my ($in, $exp) = @$_;
    my $parsed = $p->render($in);
    #warn __PACKAGE__.':'.__LINE__.": $parsed\n";
    cmp_ok($parsed, 'eq', $exp, "$in");
}