xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Pod/t/parselink.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!/usr/bin/perl -w
2*0Sstevel@tonic-gate# $Id: parselink.t,v 1.1 2001/11/23 10:09:06 eagle Exp $
3*0Sstevel@tonic-gate#
4*0Sstevel@tonic-gate# parselink.t -- Tests for Pod::ParseLink.
5*0Sstevel@tonic-gate#
6*0Sstevel@tonic-gate# Copyright 2001 by Russ Allbery <rra@stanford.edu>
7*0Sstevel@tonic-gate#
8*0Sstevel@tonic-gate# This program is free software; you may redistribute it and/or modify it
9*0Sstevel@tonic-gate# under the same terms as Perl itself.
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gate# The format of each entry in this array is the L<> text followed by the
12*0Sstevel@tonic-gate# five-element parse returned by parselink.  When adding a new test, also
13*0Sstevel@tonic-gate# increment the test count in the BEGIN block below.  We don't use any of the
14*0Sstevel@tonic-gate# fancy test modules intentionally for backward compatibility to older
15*0Sstevel@tonic-gate# versions of Perl.
16*0Sstevel@tonic-gate@TESTS = (
17*0Sstevel@tonic-gate    [ 'foo',
18*0Sstevel@tonic-gate      undef, 'foo', 'foo', undef, 'pod' ],
19*0Sstevel@tonic-gate
20*0Sstevel@tonic-gate    [ 'foo|bar',
21*0Sstevel@tonic-gate      'foo', 'foo', 'bar', undef, 'pod' ],
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gate    [ 'foo/bar',
24*0Sstevel@tonic-gate      undef, '"bar" in foo', 'foo', 'bar', 'pod' ],
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate    [ 'foo/"baz boo"',
27*0Sstevel@tonic-gate      undef, '"baz boo" in foo', 'foo', 'baz boo', 'pod' ],
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate    [ '/bar',
30*0Sstevel@tonic-gate      undef, '"bar"', undef, 'bar', 'pod' ],
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate    [ '/"baz boo"',
33*0Sstevel@tonic-gate      undef, '"baz boo"', undef, 'baz boo', 'pod' ],
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate    [ '/baz boo',
36*0Sstevel@tonic-gate      undef, '"baz boo"', undef, 'baz boo', 'pod' ],
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gate    [ 'foo bar/baz boo',
39*0Sstevel@tonic-gate      undef, '"baz boo" in foo bar', 'foo bar', 'baz boo', 'pod' ],
40*0Sstevel@tonic-gate
41*0Sstevel@tonic-gate    [ 'foo bar  /  baz boo',
42*0Sstevel@tonic-gate      undef, '"baz boo" in foo bar', 'foo bar', 'baz boo', 'pod' ],
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate    [ "foo\nbar\nbaz\n/\nboo",
45*0Sstevel@tonic-gate      undef, '"boo" in foo bar baz', 'foo bar baz', 'boo', 'pod' ],
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate    [ 'anchor|name/section',
48*0Sstevel@tonic-gate      'anchor', 'anchor', 'name', 'section', 'pod' ],
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate    [ '"boo var baz"',
51*0Sstevel@tonic-gate      undef, '"boo var baz"', undef, 'boo var baz', 'pod' ],
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate    [ 'bar baz',
54*0Sstevel@tonic-gate      undef, '"bar baz"', undef, 'bar baz', 'pod' ],
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate    [ '"boo bar baz / baz boo"',
57*0Sstevel@tonic-gate      undef, '"boo bar baz / baz boo"', undef, 'boo bar baz / baz boo',
58*0Sstevel@tonic-gate      'pod' ],
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate    [ 'fooZ<>bar',
61*0Sstevel@tonic-gate      undef, 'fooZ<>bar', 'fooZ<>bar', undef, 'pod' ],
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate    [ 'Testing I<italics>|foo/bar',
64*0Sstevel@tonic-gate      'Testing I<italics>', 'Testing I<italics>', 'foo', 'bar', 'pod' ],
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate    [ 'foo/I<Italic> text',
67*0Sstevel@tonic-gate      undef, '"I<Italic> text" in foo', 'foo', 'I<Italic> text', 'pod' ],
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate    [ 'fooE<verbar>barZ<>/Section C<with> I<B<other> markup',
70*0Sstevel@tonic-gate      undef, '"Section C<with> I<B<other> markup" in fooE<verbar>barZ<>',
71*0Sstevel@tonic-gate      'fooE<verbar>barZ<>', 'Section C<with> I<B<other> markup', 'pod' ],
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate    [ 'Nested L<http://www.perl.org/>|fooE<sol>bar',
74*0Sstevel@tonic-gate      'Nested L<http://www.perl.org/>', 'Nested L<http://www.perl.org/>',
75*0Sstevel@tonic-gate      'fooE<sol>bar', undef, 'pod' ],
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate    [ 'ls(1)',
78*0Sstevel@tonic-gate      undef, 'ls(1)', 'ls(1)', undef, 'man' ],
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate    [ '  perlfunc(1)/open  ',
81*0Sstevel@tonic-gate      undef, '"open" in perlfunc(1)', 'perlfunc(1)', 'open', 'man' ],
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate    [ 'some manual page|perl(1)',
84*0Sstevel@tonic-gate      'some manual page', 'some manual page', 'perl(1)', undef, 'man' ],
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate    [ 'http://www.perl.org/',
87*0Sstevel@tonic-gate      undef, 'http://www.perl.org/', 'http://www.perl.org/', undef, 'url' ],
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate    [ 'news:yld72axzc8.fsf@windlord.stanford.edu',
90*0Sstevel@tonic-gate      undef, 'news:yld72axzc8.fsf@windlord.stanford.edu',
91*0Sstevel@tonic-gate      'news:yld72axzc8.fsf@windlord.stanford.edu', undef, 'url' ]
92*0Sstevel@tonic-gate);
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gateBEGIN {
95*0Sstevel@tonic-gate    chdir 't' if -d 't';
96*0Sstevel@tonic-gate    unshift (@INC, '../blib/lib');
97*0Sstevel@tonic-gate    $| = 1;
98*0Sstevel@tonic-gate    print "1..25\n";
99*0Sstevel@tonic-gate}
100*0Sstevel@tonic-gate
101*0Sstevel@tonic-gateEND {
102*0Sstevel@tonic-gate    print "not ok 1\n" unless $loaded;
103*0Sstevel@tonic-gate}
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gateuse Pod::ParseLink;
106*0Sstevel@tonic-gate$loaded = 1;
107*0Sstevel@tonic-gateprint "ok 1\n";
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate# Used for reporting test failures.
110*0Sstevel@tonic-gatemy @names = qw(text inferred name section type);
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gatemy $n = 2;
113*0Sstevel@tonic-gatefor (@TESTS) {
114*0Sstevel@tonic-gate    my @expected = @$_;
115*0Sstevel@tonic-gate    my $link = shift @expected;
116*0Sstevel@tonic-gate    my @results = parselink ($link);
117*0Sstevel@tonic-gate    my $okay = 1;
118*0Sstevel@tonic-gate    for (0..4) {
119*0Sstevel@tonic-gate        # Make sure to check undef explicitly; we don't want undef to match
120*0Sstevel@tonic-gate        # the empty string because they're semantically different.
121*0Sstevel@tonic-gate        unless ((!defined ($results[$_]) && !defined ($expected[$_]))
122*0Sstevel@tonic-gate                || (defined ($results[$_]) && defined ($expected[$_])
123*0Sstevel@tonic-gate                    && $results[$_] eq $expected[$_])) {
124*0Sstevel@tonic-gate            print "not ok $n\n" if $okay;
125*0Sstevel@tonic-gate            print "# Incorrect $names[$_]:\n";
126*0Sstevel@tonic-gate            print "#   expected: $expected[$_]\n";
127*0Sstevel@tonic-gate            print "#       seen: $results[$_]\n";
128*0Sstevel@tonic-gate            $okay = 0;
129*0Sstevel@tonic-gate        }
130*0Sstevel@tonic-gate    }
131*0Sstevel@tonic-gate    print "ok $n\n" if $okay;
132*0Sstevel@tonic-gate    $n++;
133*0Sstevel@tonic-gate}
134