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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
use strict;
use warnings;
use Test::More;
# preamble to make it work portably regardless of where the test is run
use File::Spec::Functions;
my ($volume, $dirstring, $file) = File::Spec->splitpath($0);
my @DIRS = File::Spec->splitdir($dirstring);
pop @DIRS while (@DIRS and $DIRS[-1] =~ /^(t|)$/);
unshift @INC, catdir(@DIRS);
#plan 'no_plan';
plan tests => 27;
use_ok('Pod::Index::Search');
my $q = Pod::Index::Search->new(
filename => catfile(@DIRS, qw(t test.txt)),
);
isa_ok($q, 'Pod::Index::Search');
my @results = $q->search('random');
is (scalar @results, 2, 'got 2 results for random');
push @results, $q->search('deuterium');
push @results, $q->search('head2');
push @results, $q->search('verbatim');
push @results, $q->search('synopsis');
my @expected = expected();
for my $res (@results) {
isa_ok($res, 'Pod::Index::Entry');
my $exp = shift @expected;
is($res->line, $exp->{line}, "line=$exp->{line}");
is($res->filename, $exp->{podname}, "podname=$exp->{podname}");
is($res->pod, $exp->{pod}, "pod ok");
}
################## EXPECTED ################
sub expected {
my $podfile = catfile(@DIRS, 't', 'test.pod');
return (
###############################
{ line => 14, podname => $podfile, pod => <<POD },
This is a random paragraph.
X<random>
POD
###############################
{ line => 50, podname => $podfile, pod => <<POD },
=over
=item helium
X<helium>
X<balloon, floating>
X<balloon, light>
X<balloon, gas-filled, helium>
X<random>
Helium is used for filling balloons.
=back
POD
###############################
{ line => 26, podname => $podfile, pod => <<POD },
=over
=item hydrogen
X<hydrogen>
X<protium>
X<deuterium>
X<tritium>
=item deuterium
=item tritium
These are the isotopes of element 1. Let's add some nested items:
=over
=item H20
water
=item D2O
heavy water
=back
=back
POD
###############################
{ line => 61, podname => $podfile, pod => <<POD },
=head2 HEAD2
X<head2>
X<balloon>
This is to see if the head2 block is selected correctly.
for example,
this paragraph should be included.
POD
###############################
{ line => 17, podname => $podfile, pod => <<POD },
This is another paragraph, followed by a verbatim block or two:
X<verbatim>
this is an example
this is another example
POD
###############################
{ line => 5, podname => $podfile, pod => <<POD },
=head1 SYNOPSIS
X<synopsis>
blah blah blah
POD
);
}
|