File: bugs.t

package info (click to toggle)
libtext-mediawikiformat-perl 1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 236 kB
  • ctags: 46
  • sloc: perl: 1,848; makefile: 2
file content (115 lines) | stat: -rw-r--r-- 2,525 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!perl

BEGIN { chdir 't' if -d 't' }

use strict;
use warnings;

use Test::More tests => 16;
use Test::NoWarnings;

use_ok 'Text::MediawikiFormat', as => 'wf', process_html => 0;

my $wikitext =<<WIKI;


* unordered

Final paragraph.

WIKI

my $htmltext = eval { wf ($wikitext) };

is $@, '',
   'format() should throw no warnings for text starting with newlines';

like $htmltext, qr!<li>unordered</li>!, 
     'ensure that lists followed by paragraphs are included correctly'; 

package Baz;
use Text::MediawikiFormat as => 'wf', process_html => 0;

::can_ok( 'Baz', 'wf' );

package main;

##
## make sure tag overrides work for Kake
##

$wikitext = <<WIKI;

* foo
** bar

WIKI

my %format_tags = (
	indent   => qr/^(?:\t+|\s{4,}|(?=\*+))/,
	blocks   => { unordered => qr/^\s*\*+\s*/ },
	nests    => { unordered => 1 },
);

$htmltext = wf ($wikitext, \%format_tags);

like $htmltext, qr/<li>foo<\/li>/, "first level of unordered list";
like $htmltext, qr/<li>bar<\/li>/, "nested unordered lists OK";

##
## Check that blocks not in blockorder are not fatal
##
%format_tags = (
	blocks     => {
		definition => qr/^:\s*/
	},
	definition => [ "<dl>\n", "</dl>\n", '<dt><dd>', "\n" ],
	blockorder => [ 'definition' ],
);

my $warning;
local $SIG{__WARN__} = sub { $warning = shift };
eval { wf ($wikitext, \%format_tags) };
is $@, '', 'format() should not die if a block is missing from blockorder';
like $warning, qr/No order specified/, '... warning instead';

my $foo = 'x';
$foo .= '' unless $foo =~ /x/;
my $html  = wf ('test');
is $html, "<p>test</p>\n", 'successful prior match should not whomp format()';

$wikitext =<<'WIKI';
Here is some example code:

	sub example_code
	{
		my ($foo) = @_;
		my $this = call_that $foo;
	}

Isn't it nice?
WIKI

$htmltext = wf ($wikitext, {blocks => {code => qr/^\t/}});

like $htmltext, qr!<pre>sub example_code[^<]+}\s*</pre>!m,
     'pre tags should work'; 

like $htmltext, qr!^\tmy \(\$foo\)!m, '... not removing further indents'; 

$wikitext =<<WIKI;
CamelCase
CamooseCase
NOTCAMELCASE
WIKI

$htmltext = wf ($wikitext, {}, {implicit_links => 1});

like $htmltext, qr!<a href='CamelCase'>CamelCase</a>!, 
     'parse actual CamelCase words into links'; 
like $htmltext, qr!<a href='CamooseCase'>CamooseCase</a>!, 
     '... not repeating if using link as title'; 
like $htmltext, qr!^NOTCAMELCASE!m, '... but not words in all uppercase'; 

my @processed = Text::MediawikiFormat::_nest_blocks ([]);
is @processed, 0, '_nest_blocks() should not autovivify empty blocks array';