xref: /openbsd-src/gnu/usr.bin/perl/cpan/podlators/t/parselink/basic.t (revision e068048151d29f2562a32185e21a8ba885482260)
1#!/usr/bin/perl
2#
3# Tests for Pod::ParseLink.
4#
5# Copyright 2001, 2009, 2018, 2020, 2022 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
12use 5.008;
13use strict;
14use warnings;
15
16use Test::More tests => 28;
17
18BEGIN {
19    use_ok('Pod::ParseLink');
20}
21
22# The format of each entry in this array is the L<> text followed by the
23# five-element parse returned by parselink.
24#<<<
25our @TESTS = (
26    ['foo'           => (undef, 'foo',              'foo', undef,     'pod')],
27    ['foo|bar'       => ('foo', 'foo',              'bar', undef,     'pod')],
28    ['foo/bar'       => (undef, '"bar" in foo',     'foo', 'bar',     'pod')],
29    ['foo/"baz boo"' => (undef, '"baz boo" in foo', 'foo', 'baz boo', 'pod')],
30    ['/bar'          => (undef, '"bar"',            undef, 'bar',     'pod')],
31    ['/"baz boo"'    => (undef, '"baz boo"',        undef, 'baz boo', 'pod')],
32    ['/baz boo'      => (undef, '"baz boo"',        undef, 'baz boo', 'pod')],
33    [
34        'foo bar/baz boo' =>
35          (undef, '"baz boo" in foo bar', 'foo bar', 'baz boo', 'pod'),
36    ],
37    [
38        'foo bar  /  baz boo' =>
39          (undef, '"baz boo" in foo bar', 'foo bar', 'baz boo', 'pod'),
40    ],
41    [
42        "foo\nbar\nbaz\n/\nboo" =>
43          (undef, '"boo" in foo bar baz', 'foo bar baz', 'boo', 'pod'),
44    ],
45    ['anchor|name/section' => qw(anchor anchor name section pod)],
46    ['"boo var baz"' => (undef, '"boo var baz"', undef, 'boo var baz', 'pod')],
47    ['bar baz'       => (undef, '"bar baz"', undef, 'bar baz', 'pod')],
48    [
49        '"boo bar baz / baz boo"' => (
50            undef, '"boo bar baz / baz boo"',
51            undef, 'boo bar baz / baz boo',
52            'pod',
53        ),
54    ],
55    ['fooZ<>bar' => (undef, 'fooZ<>bar', 'fooZ<>bar', undef, 'pod')],
56    [
57        'Testing I<italics>|foo/bar' =>
58          ('Testing I<italics>', 'Testing I<italics>', 'foo', 'bar', 'pod'),
59    ],
60    [
61        'foo/I<Italic> text' =>
62          (undef, '"I<Italic> text" in foo', 'foo', 'I<Italic> text', 'pod'),
63    ],
64    [
65        'fooE<verbar>barZ<>/Section C<with> I<B<other> markup' => (
66            undef,
67            '"Section C<with> I<B<other> markup" in fooE<verbar>barZ<>',
68            'fooE<verbar>barZ<>',
69            'Section C<with> I<B<other> markup',
70            'pod',
71        ),
72    ],
73    [
74        'Nested L<http://www.perl.org/>|fooE<sol>bar' => (
75            'Nested L<http://www.perl.org/>',
76            'Nested L<http://www.perl.org/>',
77            'fooE<sol>bar', undef, 'pod',
78        ),
79    ],
80    ['ls(1)' => (undef, 'ls(1)', 'ls(1)', undef, 'man')],
81    [
82        '  perlfunc(1)/open  ' =>
83          (undef, '"open" in perlfunc(1)', 'perlfunc(1)', 'open', 'man'),
84    ],
85    [
86        'some manual page|perl(1)' =>
87          ('some manual page', 'some manual page', 'perl(1)', undef, 'man'),
88    ],
89    [
90        'http://www.perl.org/' => (
91            undef, 'http://www.perl.org/', 'http://www.perl.org/', undef,
92            'url',
93        ),
94    ],
95    [
96        'news:yld72axzc8.fsf@windlord.stanford.edu' => (
97            undef,
98            'news:yld72axzc8.fsf@windlord.stanford.edu',
99            'news:yld72axzc8.fsf@windlord.stanford.edu',
100            undef, 'url',
101        ),
102    ],
103    [
104        'link|http://www.perl.org/' =>
105          ('link', 'link', 'http://www.perl.org/', undef, 'url'),
106    ],
107    [
108        '0|http://www.perl.org/' =>
109          ('0', '0', 'http://www.perl.org/', undef, 'url'),
110    ],
111    ['0|Pod::Parser' => ('0', '0', 'Pod::Parser', undef, 'pod')],
112);
113#>>>
114
115# Run all of the tests.
116for my $test (@TESTS) {
117    my ($link, @expected) = @$test;
118    my @results = parselink($link);
119    my $pretty = $link;
120    $pretty =~ s{\n}{\\n}xmsg;
121    is_deeply(\@results, \@expected, $pretty);
122}
123