From 0130a5610890bb5659c4617a7b14cae163ee7f16 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sun, 5 May 2019 12:41:43 -0500 Subject: [PATCH] Bug 22571: Add tests Signed-off-by: Mark Tompsett Signed-off-by: Nick Clemens --- t/SimpleMARC.t | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/t/SimpleMARC.t b/t/SimpleMARC.t index 5958508dcb..4812e315f8 100644 --- a/t/SimpleMARC.t +++ b/t/SimpleMARC.t @@ -1,6 +1,6 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use_ok("MARC::Field"); use_ok("MARC::Record"); @@ -11,6 +11,9 @@ sub new_record { $record->leader('03174nam a2200445 a 4500'); my @fields = ( MARC::Field->new( + '008', '120829t20132012nyu bk 001 0ceng', + ), + MARC::Field->new( 100, '1', ' ', a => 'Knuth, Donald Ervin', d => '1938', @@ -1693,3 +1696,47 @@ subtest 'delete_field' => sub { is_deeply( \@fields_952, [], 'Delete all 952, 2 deleted' ); }; }; + +subtest 'field_equals' => sub { + plan tests => 2; + my $record = new_record; + subtest 'standard MARC fields' => sub { + plan tests => 2; + my $match = Koha::SimpleMARC::field_equals({ + record => $record, + value => 'Donald', + field => '100', + subfield => 'a', + }); + is_deeply( $match, [], '100$a not equal to "Donald"' ); + + $match = Koha::SimpleMARC::field_equals({ + record => $record, + value => 'Donald', + field => '100', + subfield => 'a', + is_regex => 1, + }); + is_deeply( $match, [1], 'first 100$a matches "Donald"'); + }; + + subtest 'control fields' => sub { + plan tests => 2; + my $match = Koha::SimpleMARC::field_equals({ + record => $record, + value => 'eng', + field => '008', + subfield => '', + }); + is_deeply( $match, [], '008 control field not equal to "Donald"' ); + + $match = Koha::SimpleMARC::field_equals({ + record => $record, + value => 'eng', + field => '008', + subfield => '', + is_regex => 1, + }); + is_deeply( $match, [1], 'first 008 control field matches "Donald"' ); + }; +}; -- 2.11.0