File: lists-no-indent.t

package info (click to toggle)
libtext-wikiformat-perl 0.81-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: perl: 1,218; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,946 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
69
70
71
72
73
74
75
#!perl

use strict;
use warnings;

use Test::More tests => 7;
use Text::WikiFormat;

my $wikitext =<<WIKI;

    * This should be a list.

    1. This should be an ordered list.

* This is like the default unordered list
* But not indented

    ! This is like the default unordered list
    ! But marked differently

1. This is like the default ordered list
2. But not indented

WIKI

my $htmltext = Text::WikiFormat::format($wikitext);
like( $htmltext, qr!<li>This should be a list.</li>!m,
	'unordered lists should render correctly' );
like( $htmltext, qr!<li value="1">This should be an ordered list.</li>!m,
	'...ordered lists too' );

# Redefine all the list regexps to what they were to start with.
my %tags = (
	lists => {
		ordered   => qr/([\dA-Za-z]+)\.\s*/,
		unordered => qr/\*\s*/,
		code	  => qr//,
	},
);

$htmltext = Text::WikiFormat::format($wikitext, \%tags, {} );
like( $htmltext, qr!<li>This should be a list.</li>!m,
	'unordered should remain okay when we redefine all list regexps' );
like( $htmltext, qr!<li value="1">This should be an ordered list.</li>!m,
	'...ordered lists too' );

# Redefine again, set one of them to something different.
%tags = (
	blocks => {
		ordered   => qr/([\dA-Za-z]+)\.\s*/,
		unordered => qr/^\s*!\s*/,
		code	  => qr//,
	},
);

$htmltext = Text::WikiFormat::format($wikitext, \%tags, {} );
like( $htmltext, qr!<li>But marked differently</li>!m,
	'unordered should still work when redefined' );
like( $htmltext, qr!<li value="1">This should be an ordered list.</li>!m,
	'...ordered should be unaffected' );

# Now try it without requiring an indent.
%tags = (
	indent => qr/^\s*/,
    blocks => {
		ordered   => qr/^([\dA-Za-z]+)\.\s*/,
		unordered => qr/\*\s*/,
		code	  => qr/^ /,
	},
	indented => { unordered => 0 },
);

$htmltext = Text::WikiFormat::format($wikitext, \%tags, {} );
like( $htmltext, qr!<li>But not indented!m,
	'redefining a list type to require no indent should work' );