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