1 |
dpavlin |
3 |
#!/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('©'), August 2004, John McNamara, jmcnamara@cpan.org |
10 |
|
|
# |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
use strict; |
14 |
|
|
|
15 |
|
|
use Pod::Simple::Wiki; |
16 |
|
|
use Test::More tests => 6; |
17 |
|
|
|
18 |
|
|
my $style = 'kwiki'; |
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 |
|
|
); |
34 |
|
|
|
35 |
|
|
|
36 |
|
|
############################################################################### |
37 |
|
|
# |
38 |
|
|
# Run the tests. |
39 |
|
|
# |
40 |
|
|
for my $test_ref (@tests) { |
41 |
|
|
|
42 |
|
|
my $parser = Pod::Simple::Wiki->new($style); |
43 |
|
|
my $pod = $test_ref->[0]; |
44 |
|
|
my $target = $test_ref->[1]; |
45 |
|
|
my $wiki; |
46 |
|
|
|
47 |
|
|
$parser->output_string(\$wiki); |
48 |
|
|
$parser->parse_string_document($pod); |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
is($wiki, $target, "\tTesting: " . encode_escapes($pod)); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
|
55 |
|
|
############################################################################### |
56 |
|
|
# |
57 |
|
|
# Encode escapes to make them visible in the test output. |
58 |
|
|
# |
59 |
|
|
sub encode_escapes { |
60 |
|
|
my $data = $_[0]; |
61 |
|
|
|
62 |
|
|
for ($data) { |
63 |
|
|
s/\t/\\t/g; |
64 |
|
|
s/\n/\\n/g; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
return $data; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
############################################################################### |
72 |
|
|
# |
73 |
|
|
# Output the tests for visual testing in the wiki. |
74 |
|
|
# |
75 |
|
|
sub output_tests { |
76 |
|
|
|
77 |
|
|
my $test = 1; |
78 |
|
|
|
79 |
|
|
print "\n----\n\n"; |
80 |
|
|
|
81 |
|
|
for my $test_ref (@tests) { |
82 |
|
|
|
83 |
|
|
my $parser = Pod::Simple::Wiki->new($style); |
84 |
|
|
my $pod = $test_ref->[0]; |
85 |
|
|
my $pod2 = encode_escapes($pod); |
86 |
|
|
$pod2 =~ s/^=pod\\n\\n//; |
87 |
|
|
|
88 |
|
|
print "Test ", $test++, ":\t", $pod2, "\n"; |
89 |
|
|
$parser->parse_string_document($pod); |
90 |
|
|
print "\n----\n\n"; |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
__END__ |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|