From 50a949aad1d4b409d4e3603a79ee3ede6357ab6e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 23 Sep 2025 10:08:15 +0100 Subject: [PATCH] Bug 32950: Add unit test for move_field with repeatable fields This test reproduces the issue where moving subfields between repeatable MARC fields can lose or duplicate values. The test verifies that when moving 020$z to 024$a fields, the values are correctly transferred in the proper order without duplication. Signed-off-by: Bernard Scaife --- t/SimpleMARC.t | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/t/SimpleMARC.t b/t/SimpleMARC.t index 9c8c1dbba50..4da903d3702 100755 --- a/t/SimpleMARC.t +++ b/t/SimpleMARC.t @@ -1334,7 +1334,7 @@ subtest 'copy_and_replace_field' => sub { subtest 'move_field' => sub { plan tests => 2; subtest 'move subfield' => sub { - plan tests => 7; + plan tests => 9; my $record = new_record; my ( @fields_952d, @fields_952c, @fields_954c, @fields_954p ); $record->append_fields( @@ -1414,6 +1414,54 @@ subtest 'move_field' => sub { \@fields_9999, [], 'move a nonexistent subfield does not create a new one' ); + + # Test for bug 32950: Moving subfield can lose values for repeatable fields + $record = new_record; + $record->append_fields( + MARC::Field->new( + '020', ' ', ' ', + a => '123456789', + z => '987654321', + ), + MARC::Field->new( + '020', ' ', ' ', + a => '111111111', + z => '222222222', + ), + MARC::Field->new( + '020', ' ', ' ', + a => '333333333', + z => '444444444', + ), + MARC::Field->new( + '024', ' ', ' ', + a => 'existing1', + ), + MARC::Field->new( + '024', ' ', ' ', + a => 'existing2', + ), + ); + + # Test moving to a different field to reproduce the bug more clearly + move_field( + { + record => $record, + from_field => '020', + from_subfield => 'z', + to_field => '024', + to_subfield => 'a' + } + ); + + my @fields_020z = read_field( { record => $record, field => '020', subfield => 'z' } ); + my @fields_024a = read_field( { record => $record, field => '024', subfield => 'a' } ); + is_deeply( \@fields_020z, [], 'All 020$z subfields have been moved' ); + is_deeply( + \@fields_024a, + [ '987654321', '222222222', '444444444' ], + 'Bug 32950: Move preserves values correctly in repeatable fields' + ); }; subtest 'move field' => sub { -- 2.51.0