File: 06_unbalanced.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 (53 lines) | stat: -rw-r--r-- 1,291 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use Test::More tests => 9;
use Test::NoWarnings;
use Parse::BBCode;
use strict;
use warnings;

my %tag_def_html = (

    code   => {
        parse => 0,
        code => sub {
            my ($self, $attr, $content) = @_;
            "<code>$$content</code>"
        },
    },
    pre   => {
        code => sub {
            "<code></code>"
        },
    },
    a => '<a>%{parse}s</a>',
    b => '<b>%{parse}s</b>',
    c => '<c>%{parse}s</c>',
);
my $bbc2html = Parse::BBCode->new({                                                              
        tags => {
            %tag_def_html,
        },
    }
);

sub contains_untranslated {
    my $str = shift;
    return $str =~ m{\[/?\w+\]} ? 1 : 0;
}

my @tests = (
        [ q#[c][a][/b]test#, q#[c][a][/b]test# ],
        [ q#[a][/b]#, q#[a][/b]# ],
        [ q#[a][b][/a][/b]#, q#<a>[b]</a>[/b]# ],
        [ q#[code]foo#, q#[code]foo# ],
        [ q#[code#, q#[code# ],
        [ q#[code foo bar#, q#[code foo bar# ],
        [ q#[a][code][/a][/code]#, q#[a]<code>[/a]</code># ],
        [ q#[b][a][code][/a][/code]#, q#[b][a]<code>[/a]</code># ],
);

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