xref: /openbsd-src/gnu/usr.bin/perl/cpan/podlators/t/parselink/basic.t (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1#!/usr/bin/perl -w
2#
3# parselink.t -- Tests for Pod::ParseLink.
4#
5# Copyright 2001, 2009, 2018 by Russ Allbery <rra@cpan.org>
6#
7# This program is free software; you may redistribute it and/or modify it
8# under the same terms as Perl itself.
9#
10# SPDX-License-Identifier: GPL-1.0-or-later OR Artistic-1.0-Perl
11
12# The format of each entry in this array is the L<> text followed by the
13# five-element parse returned by parselink.
14our @TESTS = (
15    [ 'foo',
16      undef, 'foo', 'foo', undef, 'pod' ],
17
18    [ 'foo|bar',
19      'foo', 'foo', 'bar', undef, 'pod' ],
20
21    [ 'foo/bar',
22      undef, '"bar" in foo', 'foo', 'bar', 'pod' ],
23
24    [ 'foo/"baz boo"',
25      undef, '"baz boo" in foo', 'foo', 'baz boo', 'pod' ],
26
27    [ '/bar',
28      undef, '"bar"', undef, 'bar', 'pod' ],
29
30    [ '/"baz boo"',
31      undef, '"baz boo"', undef, 'baz boo', 'pod' ],
32
33    [ '/baz boo',
34      undef, '"baz boo"', undef, 'baz boo', 'pod' ],
35
36    [ 'foo bar/baz boo',
37      undef, '"baz boo" in foo bar', 'foo bar', 'baz boo', 'pod' ],
38
39    [ 'foo bar  /  baz boo',
40      undef, '"baz boo" in foo bar', 'foo bar', 'baz boo', 'pod' ],
41
42    [ "foo\nbar\nbaz\n/\nboo",
43      undef, '"boo" in foo bar baz', 'foo bar baz', 'boo', 'pod' ],
44
45    [ 'anchor|name/section',
46      'anchor', 'anchor', 'name', 'section', 'pod' ],
47
48    [ '"boo var baz"',
49      undef, '"boo var baz"', undef, 'boo var baz', 'pod' ],
50
51    [ 'bar baz',
52      undef, '"bar baz"', undef, 'bar baz', 'pod' ],
53
54    [ '"boo bar baz / baz boo"',
55      undef, '"boo bar baz / baz boo"', undef, 'boo bar baz / baz boo',
56      'pod' ],
57
58    [ 'fooZ<>bar',
59      undef, 'fooZ<>bar', 'fooZ<>bar', undef, 'pod' ],
60
61    [ 'Testing I<italics>|foo/bar',
62      'Testing I<italics>', 'Testing I<italics>', 'foo', 'bar', 'pod' ],
63
64    [ 'foo/I<Italic> text',
65      undef, '"I<Italic> text" in foo', 'foo', 'I<Italic> text', 'pod' ],
66
67    [ 'fooE<verbar>barZ<>/Section C<with> I<B<other> markup',
68      undef, '"Section C<with> I<B<other> markup" in fooE<verbar>barZ<>',
69      'fooE<verbar>barZ<>', 'Section C<with> I<B<other> markup', 'pod' ],
70
71    [ 'Nested L<http://www.perl.org/>|fooE<sol>bar',
72      'Nested L<http://www.perl.org/>', 'Nested L<http://www.perl.org/>',
73      'fooE<sol>bar', undef, 'pod' ],
74
75    [ 'ls(1)',
76      undef, 'ls(1)', 'ls(1)', undef, 'man' ],
77
78    [ '  perlfunc(1)/open  ',
79      undef, '"open" in perlfunc(1)', 'perlfunc(1)', 'open', 'man' ],
80
81    [ 'some manual page|perl(1)',
82      'some manual page', 'some manual page', 'perl(1)', undef, 'man' ],
83
84    [ 'http://www.perl.org/',
85      undef, 'http://www.perl.org/', 'http://www.perl.org/', undef, 'url' ],
86
87    [ 'news:yld72axzc8.fsf@windlord.stanford.edu',
88      undef, 'news:yld72axzc8.fsf@windlord.stanford.edu',
89      'news:yld72axzc8.fsf@windlord.stanford.edu', undef, 'url' ],
90
91    [ 'link|http://www.perl.org/',
92      'link', 'link', 'http://www.perl.org/', undef, 'url' ],
93
94    [ '0|http://www.perl.org/',
95      '0', '0', 'http://www.perl.org/', undef, 'url' ],
96
97    [ '0|Pod::Parser',
98      '0', '0', 'Pod::Parser', undef, 'pod' ],
99);
100
101BEGIN {
102    chdir 't' if -d 't';
103    unshift (@INC, '../blib/lib');
104    $| = 1;
105}
106
107use strict;
108
109use Test::More tests => 28;
110BEGIN { use_ok ('Pod::ParseLink') }
111
112# Used for reporting test failures.
113my @names = qw(text inferred name section type);
114
115for (@TESTS) {
116    my @expected = @$_;
117    my $link = shift @expected;
118    my @results = parselink ($link);
119    my $pretty = $link;
120    $pretty =~ s/\n/\\n/g;
121    is_deeply (\@results, \@expected, $pretty);
122}
123