Lines 20-30
use Modern::Perl;
Link Here
|
20 |
use Test::More; |
20 |
use Test::More; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
|
22 |
|
|
|
23 |
use MARC::Record; |
24 |
|
23 |
use Module::Load::Conditional qw/check_install/; |
25 |
use Module::Load::Conditional qw/check_install/; |
24 |
|
26 |
|
25 |
BEGIN { |
27 |
BEGIN { |
26 |
if ( check_install( module => 'Test::DBIx::Class' ) ) { |
28 |
if ( check_install( module => 'Test::DBIx::Class' ) ) { |
27 |
plan tests => 11; |
29 |
plan tests => 12; |
28 |
} else { |
30 |
} else { |
29 |
plan skip_all => "Need Test::DBIx::Class" |
31 |
plan skip_all => "Need Test::DBIx::Class" |
30 |
} |
32 |
} |
Lines 82-85
$testmatcher->description('match on ISSN');
Link Here
|
82 |
|
84 |
|
83 |
is( $testmatcher->description(), 'match on ISSN', 'testing code accessor' ); |
85 |
is( $testmatcher->description(), 'match on ISSN', 'testing code accessor' ); |
84 |
|
86 |
|
|
|
87 |
subtest '_get_match_keys() tests' => sub { |
88 |
|
89 |
plan tests => 8; |
90 |
|
91 |
my $matchpoint = get_title_matchpoint({ |
92 |
length => 0, |
93 |
norms => [], |
94 |
offset => 0 |
95 |
}); |
96 |
|
97 |
my $record = MARC::Record->new(); |
98 |
$record->append_fields( |
99 |
MARC::Field->new('100', '1', ' ', |
100 |
a => 'King, Stephen', |
101 |
d => 'd1947-'), |
102 |
MARC::Field->new('245', ' ', ' ', |
103 |
a => ' .; thE t[]:,aliS(m)/An\'"', |
104 |
c => 'Stephen King, Peter Straub.' ), |
105 |
MARC::Field->new('700', ' ', ' ', |
106 |
a => 'Straub, Peter', |
107 |
d => '1943-') |
108 |
); |
109 |
|
110 |
my @keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); |
111 |
|
112 |
is( $keys[0], 'THE TALISMAN STEPHEN KING PETER STRAUB', |
113 |
'Match key correctly calculated with no $norms'); |
114 |
|
115 |
$matchpoint = get_title_matchpoint({ |
116 |
length => 9, |
117 |
norms => [], |
118 |
offset => 0 |
119 |
}); |
120 |
@keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); |
121 |
is( $keys[0], 'THE', |
122 |
'Match key correctly calculated with length 9'); |
123 |
|
124 |
$matchpoint = get_title_matchpoint({ |
125 |
length => 9, |
126 |
norms => [], |
127 |
offset => 1 |
128 |
}); |
129 |
@keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); |
130 |
is( $keys[0], 'THE', |
131 |
'Match key correctly calculated with length 9 and offset 1'); |
132 |
|
133 |
$matchpoint = get_title_matchpoint({ |
134 |
length => 9, |
135 |
norms => [], |
136 |
offset => 2 |
137 |
}); |
138 |
@keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); |
139 |
is( $keys[0], 'THE T', |
140 |
'Match key correctly calculated with length 9 and offset 2, should not remove space'); |
141 |
|
142 |
$matchpoint = get_authors_matchpoint({ |
143 |
length => 0, |
144 |
norms => [], |
145 |
offset => 0 |
146 |
}); |
147 |
@keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); |
148 |
is( $keys[0], 'STRAUB PETER KING STEPHEN', |
149 |
'Match key correctly calculated with multiple components'); |
150 |
|
151 |
$matchpoint = get_authors_matchpoint({ |
152 |
length => 9, |
153 |
norms => [], |
154 |
offset => 0 |
155 |
}); |
156 |
@keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); |
157 |
is( $keys[0], 'STRAUB KING ST', |
158 |
'Match key correctly calculated with multiple components, length 9'); |
159 |
|
160 |
$matchpoint = get_authors_matchpoint({ |
161 |
length => 10, |
162 |
norms => [], |
163 |
offset => 0 |
164 |
}); |
165 |
@keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); |
166 |
is( $keys[0], 'STRAUB P KING STE', |
167 |
'Match key correctly calculated with multiple components, length 10'); |
168 |
|
169 |
$matchpoint = get_authors_matchpoint({ |
170 |
length => 10, |
171 |
norms => [], |
172 |
offset => 2 |
173 |
}); |
174 |
@keys = C4::Matcher::_get_match_keys( $record, $matchpoint ); |
175 |
is( $keys[0], 'TRAUB PET ING STEPH', |
176 |
'Match key correctly calculated with multiple components, length 10, offset 1'); |
177 |
}; |
178 |
|
179 |
sub get_title_matchpoint { |
180 |
|
181 |
my $params = shift; |
182 |
|
183 |
my $length = $params->{length} // 0; |
184 |
my $norms = $params->{norms} // []; |
185 |
my $offset = $params->{offset} // 0; |
186 |
|
187 |
my $matchpoint = { |
188 |
components => [ |
189 |
{ |
190 |
length => $length, |
191 |
norms => $norms, |
192 |
offset => $offset, |
193 |
subfields => |
194 |
{ |
195 |
a => 1, |
196 |
c => 1 |
197 |
}, |
198 |
tag => '245' |
199 |
} |
200 |
], |
201 |
index => "title", |
202 |
score => 1000 |
203 |
}; |
204 |
|
205 |
return $matchpoint; |
206 |
} |
207 |
|
208 |
sub get_authors_matchpoint { |
209 |
|
210 |
my $params = shift; |
211 |
|
212 |
my $length = $params->{length} // 0; |
213 |
my $norms = $params->{norms} // []; |
214 |
my $offset = $params->{offset} // 0; |
215 |
|
216 |
my $matchpoint = { |
217 |
components => [ |
218 |
{ |
219 |
length => $length, |
220 |
norms => $norms, |
221 |
offset => $offset, |
222 |
subfields => |
223 |
{ |
224 |
a => 1 |
225 |
}, |
226 |
tag => '700' |
227 |
}, |
228 |
{ |
229 |
length => $length, |
230 |
norms => $norms, |
231 |
offset => $offset, |
232 |
subfields => |
233 |
{ |
234 |
a => 1 |
235 |
}, |
236 |
tag => '100' |
237 |
} |
238 |
], |
239 |
index => "author", |
240 |
score => 1000 |
241 |
}; |
242 |
|
243 |
return $matchpoint; |
244 |
} |
245 |
|
85 |
1; |
246 |
1; |
86 |
- |
|
|