File: Wiki.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 (173 lines) | stat: -rw-r--r-- 4,649 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!perl

use strict;
use warnings;

# for testing 'rootdir' in links
my %constants = (
	rootdir => 'rootdir',
);

local *Text::WikiFormat::getCurrentStatic;
*Text::WikiFormat::getCurrentStatic = sub {
	return \%constants;
};

use Test::More tests => 32;

use_ok( 'Text::WikiFormat' );

my $wikitext =<<WIKI;
'''hello'''
''hi''
-----
woo
-----
LinkMeSomewhere
[LinkMeElsewhere|BYE]

	* unordered one
	* unordered two

	1. ordered one
	2. ordered two

	code one
	code two

WIKI

ok( %Text::WikiFormat::tags, 
	'%tags should be available from Text::WikiFormat');

my %tags = %Text::WikiFormat::tags;
my %opts = ( 
	prefix => 'rootdir/wiki.pl?page=',
);

my $htmltext = Text::WikiFormat::format_line($wikitext, \%tags, \%opts);

like( $htmltext, qr!\[<a href="rootdir/wiki\.pl\?page=LinkMeElsewhere">!, 
	'format_line () should link StudlyCaps where found)' );
like( $htmltext, qr!<strong>hello</strong>!, 'three ticks should mark strong');
like( $htmltext, qr!<em>hi</em>!, 'two ticks should mark emphasized' );
like( $htmltext, qr!LinkMeSomewhere</a>\n!m, 'should catch StudlyCaps' );
like( $htmltext, qr!\[!, 'should not handle extended links without flag' );

$opts{extended} = 1;
$htmltext = Text::WikiFormat::format_line($wikitext, \%tags, \%opts);
like( $htmltext, qr!^<a href="rootdir/wiki\.pl\?page=LinkMeElsewhere">!m,
	'should handle extended links with flag' );

$htmltext = Text::WikiFormat::format($wikitext);
like( $htmltext, qr!<strong>hello</strong>!, 'three ticks should mark strong');
like( $htmltext, qr!<em>hi</em>!, 'two ticks should mark emphasized' );

is( scalar @{ $tags{ordered} }, 3, 
	'... default ordered entry should have three items' );
is( ref( $tags{ordered}->[2] ), 'CODE', '... and should have subref' );

# make sure this starts a paragraph (buglet)
$htmltext = Text::WikiFormat::format("nothing to see here\nmoveAlong\n", {}, 
	{ prefix => 'foo=' });
like( $htmltext, qr!^<p>nothing!, '... should start new text with paragraph' );

# another buglet had the wrong tag pairs when ending a list
my $wikiexample =<<WIKIEXAMPLE;
I am modifying this because ItIsFun.  There is:
    1. MuchJoy
    2. MuchFun
    3. MuchToDo

Here is a paragraph.
There are newlines in my paragraph.

Here is another paragraph.

	  here is some code that should have ''literal'' double single quotes
	  how amusing

WIKIEXAMPLE

$htmltext = Text::WikiFormat::format($wikiexample, {}, { prefix => 'foo=' });

like( $htmltext, qr!^<p>I am modifying this!,
	'... should use correct tags when ending lists' );
like( $htmltext, qr!<p>Here is a paragraph.<br />!,
	'... should add no newline before paragraph, but at newline in paragraph ');
like( $htmltext, qr!<p>Here is another paragraph.</p>!,
	'... should add no newline at end of paragraph' );
like( $htmltext, qr|''literal'' double single|,
	'... should treat code sections literally' );
unlike( $htmltext, qr!<(\w+)></\1>!, '... but should not create empty lists' );

$wikitext =<<WIKI;
[escape spaces in links]

WIKI

%opts = (
	prefix   => 'rootdir/wiki.pl?page=',
	extended => 1,
);

$htmltext = Text::WikiFormat::format($wikitext, {}, \%opts);
like( $htmltext,
	qr!<a href="rootdir/wiki\.pl\?page=escape%20spaces%20in%20links">!m,
	'... should escape spaces in extended links' );
like( $htmltext, qr!escape spaces in links</a>!m,
	'... should leave spaces alone in titles of extended links' );

$wikitext =<<'WIKI';
= heading =
== sub heading ==

some text

=== sub sub heading ===

more text

WIKI

$htmltext = Text::WikiFormat::format($wikitext, \%tags, \%opts);
like( $htmltext, qr!<h1>heading</h1>!,
	'headings should be marked' );
like( $htmltext, qr!<h2>sub heading</h2>!,
	'... and numbered appropriately' );

# test overridable tags

ok( ! main->can( 'wikiformat' ), 'Module should import nothing by default' );

can_ok( 'Text::WikiFormat', 'import' );

# given an argument, export wikiformat() somehow
package Foo;

Text::WikiFormat->import('wikiformat');
::can_ok( 'Foo', 'wikiformat' );

package Bar;
Text::WikiFormat->import( as => 'wf', prefix => 'foo', tag => 'bar' );
::can_ok( 'Bar', 'wf' );
::isnt( \&wf, \&Text::WikiFormat::format,
	'... and should be a wrapper around format()' );

my @args;
local *Text::WikiFormat::format;
*Text::WikiFormat::format = sub {
	@args = @_;
};

wf();
::is( $args[2]{prefix}, 'foo', 
	'imported sub should pass through default option' );
::is( $args[1]{tag}, 'bar', '... and default tag' );

wf('text', { tag2 => 1 }, { prefix => 'baz' });
::is( $args[0], 'text', '... passing through text unharmed' );
::is( $args[1]{tag2}, 1, '... along with new tags' );
::is( $args[2]{prefix}, 'baz', '... overriding default args as needed' );

1;