From 7dbbc74baa7a56a3e398ec282c19ba7e25c3d940 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 13 Dec 2021 10:20:54 +0000 Subject: [PATCH] Bug 23873: Unit tests This patch adds a unit test for capture groups support in Koha::SimpleMARC. Test plan 1) Run the test prior to applying the capture groups fix, note it fails. 2) Apply teh capture groups fix patch 3) Run the test again, it should now pass Signed-off-by: Andrew Fuerste-Henry --- t/SimpleMARC.t | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/t/SimpleMARC.t b/t/SimpleMARC.t index 91b77432e5..04e9a7eabb 100755 --- a/t/SimpleMARC.t +++ b/t/SimpleMARC.t @@ -326,7 +326,7 @@ subtest 'update_field' => sub { subtest 'copy_field' => sub { plan tests => 2; subtest 'copy subfield' => sub { - plan tests => 20; + plan tests => 21; my $record = new_record; $record->append_fields( MARC::Field->new( @@ -672,6 +672,27 @@ subtest 'copy_field' => sub { 'Update a subfield: add a string at the end' ); + $record = new_record; + copy_field( + { + record => $record, + from_field => 245, + from_subfield => 'a', + to_field => 245, + to_subfield => 'a', + regex => { search => '(art)', replace => 'sm$1 $1' } + } + ); + is_deeply( + [ + read_field( + { record => $record, field => '245', subfield => 'a' } + ) + ], + ['The art of computer programming', 'The smart art of computer programming'], + 'Update a subfield: use capture groups' + ); + $record = new_record; copy_field( { @@ -900,7 +921,7 @@ subtest 'copy_field' => sub { subtest 'copy_and_replace_field' => sub { plan tests => 2; subtest 'copy and replace subfield' => sub { - plan tests => 19; + plan tests => 20; my $record = new_record; $record->append_fields( MARC::Field->new( @@ -1246,6 +1267,28 @@ subtest 'copy_and_replace_field' => sub { 'Copy and replace - Update a subfield: add a string at the end' ); + $record = new_record; + copy_and_replace_field( + { + record => $record, + from_field => 245, + from_subfield => 'a', + to_field => 245, + to_subfield => 'a', + regex => { search => '(art)', replace => 'sm$1 $1' } + } + ); + # This is the same as update the subfield + is_deeply( + [ + read_field( + { record => $record, field => '245', subfield => 'a' } + ) + ], + ['The smart art of computer programming'], + 'Copy and replace - Update a subfield: use capture groups' + ); + $record = new_record; copy_and_replace_field( { -- 2.30.2