1 |
#!/usr/bin/perl -w |
2 |
|
3 |
############################################################################### |
4 |
# |
5 |
# A test for Pod::Simple::Wiki. |
6 |
# |
7 |
# Tests for I<>, B<>, C<> etc., formatting codes. |
8 |
# |
9 |
# reverse('©'), March 2005, Sam Tregar, sam@tregar.com |
10 |
# |
11 |
|
12 |
|
13 |
use strict; |
14 |
|
15 |
use Pod::Simple::Wiki; |
16 |
use Test::More tests => 6; |
17 |
|
18 |
my $style = 'twiki'; |
19 |
|
20 |
# Output the tests for visual testing in the wiki. |
21 |
# END{output_tests()}; |
22 |
|
23 |
my @tests = ( |
24 |
# Simple formatting tests |
25 |
[ "=pod\n\nI<Foo>" => qq(_Foo_\n\n) ], |
26 |
[ "=pod\n\nB<Foo>" => qq(*Foo*\n\n) ], |
27 |
[ "=pod\n\nC<Foo>" => qq(=Foo=\n\n) ], |
28 |
[ "=pod\n\nF<Foo>" => qq(_Foo_\n\n) ], |
29 |
|
30 |
# Nested formatting tests |
31 |
[ "=pod\n\nB<I<Foo>>" => qq(*_Foo_*\n\n) ], |
32 |
[ "=pod\n\nI<B<Foo>>" => qq(__Foo__\n\n), |
33 |
'Fix this later.' ], |
34 |
); |
35 |
|
36 |
|
37 |
############################################################################### |
38 |
# |
39 |
# Run the tests. |
40 |
# |
41 |
for my $test_ref (@tests) { |
42 |
|
43 |
my $parser = Pod::Simple::Wiki->new($style); |
44 |
my $pod = $test_ref->[0]; |
45 |
my $target = $test_ref->[1]; |
46 |
my $todo = $test_ref->[2]; |
47 |
my $wiki; |
48 |
|
49 |
$parser->output_string(\$wiki); |
50 |
$parser->parse_string_document($pod); |
51 |
|
52 |
local $TODO = $todo; |
53 |
is($wiki, $target, "\tTesting: " . encode_escapes($pod)); |
54 |
} |
55 |
|
56 |
|
57 |
############################################################################### |
58 |
# |
59 |
# Encode escapes to make them visible in the test output. |
60 |
# |
61 |
sub encode_escapes { |
62 |
my $data = $_[0]; |
63 |
|
64 |
for ($data) { |
65 |
s/\t/\\t/g; |
66 |
s/\n/\\n/g; |
67 |
} |
68 |
|
69 |
return $data; |
70 |
} |
71 |
|
72 |
|
73 |
############################################################################### |
74 |
# |
75 |
# Output the tests for visual testing in the wiki. |
76 |
# |
77 |
sub output_tests { |
78 |
|
79 |
my $test = 1; |
80 |
|
81 |
print "\n----\n\n"; |
82 |
|
83 |
for my $test_ref (@tests) { |
84 |
|
85 |
my $parser = Pod::Simple::Wiki->new($style); |
86 |
my $pod = $test_ref->[0]; |
87 |
my $pod2 = encode_escapes($pod); |
88 |
$pod2 =~ s/^=pod\\n\\n//; |
89 |
$pod2 =~ s/</</g; |
90 |
$pod2 =~ s/>/>/g; |
91 |
|
92 |
print "Test ", $test++, ":\t", $pod2, "\n"; |
93 |
$parser->parse_string_document($pod); |
94 |
print "\n----\n\n"; |
95 |
} |
96 |
} |
97 |
|
98 |
__END__ |
99 |
|
100 |
|
101 |
|