File: tiddlywiki_head.t

package info (click to toggle)
libpod-simple-wiki-perl 0.20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: perl: 3,665; makefile: 2
file content (91 lines) | stat: -rw-r--r-- 1,847 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w

###############################################################################
#
# A test for Pod::Simple::Wiki.
#
# Tests for =head pod directives.
#
# Copyright (c), August 2004, John McNamara, jmcnamara@cpan.org
#


use strict;

use Pod::Simple::Wiki;
use Test::More tests => 4;

my $style = 'tiddlywiki';

# Output the tests for visual testing in the wiki.
# END{output_tests()};

my @tests = (
    [ "=pod\n\n=head1 Head 1" => qq(!Head 1\n) ],
    [ "=pod\n\n=head2 Head 2" => qq(!!Head 2\n) ],
    [ "=pod\n\n=head3 Head 3" => qq(!!!Head 3\n) ],
    [ "=pod\n\n=head4 Head 4" => qq(!!!!Head 4\n) ],
);


###############################################################################
#
#  Run the tests.
#
for my $test_ref ( @tests ) {

    my $parser = Pod::Simple::Wiki->new( $style );
    my $pod    = $test_ref->[0];
    my $target = $test_ref->[1];
    my $wiki;

    $parser->output_string( \$wiki );
    $parser->parse_string_document( $pod );


    is( $wiki, $target, "\tTesting: " . encode_escapes( $pod ) );
}


###############################################################################
#
# Encode escapes to make them visible in the test output.
#
sub encode_escapes {
    my $data = $_[0];

    for ( $data ) {
        s/\t/\\t/g;
        s/\n/\\n/g;
    }

    return $data;
}


###############################################################################
#
# Output the tests for visual testing in the wiki.
#
sub output_tests {

    my $test = 1;

    for my $test_ref ( @tests ) {

        my $parser = Pod::Simple::Wiki->new( $style );
        my $pod    = $test_ref->[0];
        my $pod2   = encode_escapes( $pod );
        $pod2 =~ s/^=pod\\n\\n//;

        print "Test ", $test++, ":\t", $pod2, "\n";
        $parser->parse_string_document( $pod );

        print "\n";
    }
}

__END__