@@ -, +, @@ --- t/SimpleMARC.t | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) --- a/t/SimpleMARC.t +++ a/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( { --