6
use lib '../lib', '../blib/lib';
11
use Test::More tests => 26;
13
my $module = 'Text::WikiFormat';
14
use_ok( $module ) or exit;
16
can_ok( $module, 'start_block' );
31
return $module->can( $_[0] );
34
my $tags = \%Text::WikiFormat::tags;
35
local *Text::WikiFormat::tags = $tags;
37
my $sb = fetchsub( 'start_block' );
38
my ($result) = $sb->( '= heading =', $tags );
41
{ type => 'header', args => [ '=', 'heading' ],
42
text => '', level => 0 },
43
'start_block() should find headings' );
45
($result) = $sb->( ' * unordered item', $tags );
47
{ type => 'unordered', args => [], text => 'unordered item', level => 2 },
48
'... and unordered list' );
50
($result) = $sb->( ' 6. ordered item', $tags );
52
{ type => 'ordered', args => [ 6 ], text => 'ordered item', level => 2 },
53
'... and ordered list' );
55
($result) = $sb->( ' some code', $tags );
57
{ type => 'code', args => [], text => 'some code', level => 0 },
60
($result) = $sb->( 'paragraph', $tags );
62
{ type => 'paragraph', args => [], text => 'paragraph', level => 0 },
63
'... and paragraph' );
65
can_ok( $module, 'merge_blocks' );
66
my $mb = fetchsub( 'merge_blocks' );
68
[{ type => 'code', text => 'a', level => 1 },
69
{ type => 'code', text => 'b', level => 1 },
72
is( @result, 1, 'merge_blocks() should merge identical blocks together' );
73
is_deeply( $result[0]{text}, [qw( a b )], '... merging their text' );
76
{ type => 'unordered', text => 'foo', level => 1 },
77
{ type => 'unordered', text => 'bar', level => 1 },
79
is( @result, 1, '... merging unordered blocks' );
80
is_deeply( $result[0]{text}, [qw( foo bar)], '... and their text' );
83
{ type => 'ordered', text => 'foo', level => 2 },
84
{ type => 'ordered', text => 'bar', level => 3 },
86
is( @result, 2, '... not merging blocks at different levels' );
88
can_ok( $module, 'process_blocks' );
89
my $pb = fetchsub( 'process_blocks' );
91
[{ type => 'header', text => [ '' ], level => 0,
92
args => [[ '==', 'my header' ]] },
93
{ type => 'paragraph', text => [qw( my lines of text )], level => 0 },
94
{ type => 'ordered', text => [qw( my ordered lines ),
95
{ type => 'unordered', text => [qw( my unordered lines )], level => 2 },
96
], level => 1, args => [[ 2 ], [ 3 ], [ 5 ]] },
100
is( @result, 1, 'process_blocks() should return processed text' );
101
$result = $result[0];
102
like( $result, qr!<h2>my header</h2>!, '... marking header' );
103
like( $result, qr!<p>my<br />.+text</p>\n!s, '... paragraph' );
104
like( $result, qr!<li value="2">my</li>.+5">lines!s, '... ordered list' );
105
like( $result, qr!<ul>\n<li>my</li>!m, '... and unordered list' );
106
like( $result, qr!</li>\n</ul>\n</li>\n</ol>!, '... nesting properly' );
108
my $f = fetchsub( 'format' );
109
my $fullresult = $f->(<<END_WIKI, $tags);
125
is( $fullresult, $result, 'format() should give same results' );
127
$fullresult = $f->(<<END_WIKI, $tags);
131
* use the Expires directive
132
* no messages sent after the expiration date
133
* aliases can be closed
134
* use the Closed directive
135
* messages allowed only from people on the list
136
* aliases can auto-add people
137
* use the Auto-add directive
138
* anyone in the Cc line is added to the alias
139
* they won't get duplicates
140
* makes "just reply to alias" easier
144
like( $fullresult, qr!expire<ul>!, 'nested list should start immediately' );
145
like( $fullresult, qr!date</li>\n</ul>!, '... ending after last nested item' );
147
can_ok( $module, 'check_blocks' );
150
local $SIG{__WARN__} = sub {
151
push @warnings, shift;
154
my $cb = \&Text::WikiFormat::check_blocks;
156
blocks => { foo => 1, bar => 1, baz => 1 },
157
blockorder => [qw( bar baz )],
160
my $warning = shift @warnings;
161
like( $warning, qr/No order specified for blocks 'foo'/,
162
'check_blocks() should warn if block is not ordered' );
164
$newtags->{blockorder} = [ 'baz' ];
166
$warning = shift @warnings;
167
ok( $warning =~ /foo/ && $warning =~ /bar/, '... for all missing blocks' )