File: macros.t

package info (click to toggle)
libwiki-toolkit-formatter-usemod-perl 0.25-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 258; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download | duplicates (6)
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
use strict;

use Test::More tests => 7;
use Wiki::Toolkit::Formatter::UseMod;

my $wikitext = <<WIKITEXT;

\@PLAIN_STRING

\@TEST_TEXT

\@INDEX_ALL

\@INDEX [Category Foo]

\@PAIR one two

\@LOTS 1 2 3 4 5 6 7 8 9

WIKITEXT

my $formatter = Wiki::Toolkit::Formatter::UseMod->new(
    macros => {
        '@PLAIN_STRING' => "{plain string}",
        qr/\@TEST_TEXT(\b|$)/ => "{test text}",
        qr/\@INDEX_ALL(\b|$)/ => sub { return "{an index of all nodes}"; },
        qr/\@INDEX\s+\[Category\s+([^\]]+)]/ =>
            sub { return "{an index of things in category $_[0]}" },
        qr/\@PAIR\s+(\S*)\s+(\S*)(\b|$)/ =>
            sub { return "{" . join(" ", @_[0, 1]) . "}" },
        qr/\@LOTS (\d) (\d) (\d) (\d) (\d) (\d) (\d) (\d) (\d)/ =>
            sub { return join("", @_) }
    }
);
isa_ok( $formatter, "Wiki::Toolkit::Formatter::UseMod" );
my $html = $formatter->format($wikitext);

like( $html, qr|{plain string}|, "plain string macros work" );

like( $html, qr|{test text}|, "regex macros work" );

like( $html, qr|{an index of all nodes}|, "no-arg sub macros work" );

like( $html, qr|{an index of things in category Foo}|,
      "subs with a single arg work" );

like( $html, qr|{one two}|, "subs with two args work" );

like( $html, qr|123456789|, "subs with nine args work" );