|
Lines 269-275
subtest 'update_field' => sub {
Link Here
|
| 269 |
subtest 'copy_field' => sub { |
269 |
subtest 'copy_field' => sub { |
| 270 |
plan tests => 2; |
270 |
plan tests => 2; |
| 271 |
subtest 'copy subfield' => sub { |
271 |
subtest 'copy subfield' => sub { |
| 272 |
plan tests => 15; |
272 |
plan tests => 18; |
| 273 |
my $record = new_record; |
273 |
my $record = new_record; |
| 274 |
$record->append_fields( |
274 |
$record->append_fields( |
| 275 |
MARC::Field->new( |
275 |
MARC::Field->new( |
|
Lines 547-556
subtest 'copy_field' => sub {
Link Here
|
| 547 |
[ '2001-06-25', '2001-06-25' ], |
547 |
[ '2001-06-25', '2001-06-25' ], |
| 548 |
'copy 952$d into others 952 field' |
548 |
'copy 952$d into others 952 field' |
| 549 |
); |
549 |
); |
|
|
550 |
|
| 551 |
copy_field( |
| 552 |
{ |
| 553 |
record => $record, |
| 554 |
from_field => '111', |
| 555 |
from_subfield => '1', |
| 556 |
to_field => '999', |
| 557 |
to_subfield => '9' |
| 558 |
} |
| 559 |
); |
| 560 |
my @fields_9999 = |
| 561 |
read_field( { record => $record, field => '999', subfield => '9' } ); |
| 562 |
is_deeply( \@fields_9999, [], |
| 563 |
'copy a nonexistent subfield does not create a new one' ); |
| 564 |
|
| 565 |
$record = new_record; |
| 566 |
copy_field( |
| 567 |
{ |
| 568 |
record => $record, |
| 569 |
from_field => 245, |
| 570 |
from_subfield => 'a', |
| 571 |
to_field => 245, |
| 572 |
to_subfield => 'a', |
| 573 |
regex => { search => '^', replace => 'BEGIN ' } |
| 574 |
} |
| 575 |
); |
| 576 |
is_deeply( |
| 577 |
read_field( |
| 578 |
{ record => $record, field => '245', subfield => 'a' } |
| 579 |
), |
| 580 |
'BEGIN The art of computer programming', |
| 581 |
'Update a subfield: add a string at the beginning' |
| 582 |
); |
| 583 |
|
| 584 |
$record = new_record; |
| 585 |
copy_field( |
| 586 |
{ |
| 587 |
record => $record, |
| 588 |
from_field => 245, |
| 589 |
from_subfield => 'a', |
| 590 |
to_field => 245, |
| 591 |
to_subfield => 'a', |
| 592 |
regex => { search => '$', replace => ' END' } |
| 593 |
} |
| 594 |
); |
| 595 |
is_deeply( |
| 596 |
read_field( |
| 597 |
{ record => $record, field => '245', subfield => 'a' } |
| 598 |
), |
| 599 |
'The art of computer programming END', |
| 600 |
'Update a subfield: add a string at the end' |
| 601 |
); |
| 602 |
|
| 550 |
}; |
603 |
}; |
| 551 |
|
604 |
|
| 552 |
subtest 'copy field' => sub { |
605 |
subtest 'copy field' => sub { |
| 553 |
plan tests => 11; |
606 |
plan tests => 12; |
| 554 |
my $record = new_record; |
607 |
my $record = new_record; |
| 555 |
$record->append_fields( |
608 |
$record->append_fields( |
| 556 |
MARC::Field->new( |
609 |
MARC::Field->new( |
|
Lines 648-653
subtest 'copy_field' => sub {
Link Here
|
| 648 |
[ '4242423918', 'CD' ], |
701 |
[ '4242423918', 'CD' ], |
| 649 |
"copy all with regex: second original fields has been copied" |
702 |
"copy all with regex: second original fields has been copied" |
| 650 |
); |
703 |
); |
|
|
704 |
copy_field( |
| 705 |
{ |
| 706 |
record => $record, |
| 707 |
from_field => '111', |
| 708 |
to_field => '999', |
| 709 |
} |
| 710 |
); |
| 711 |
my @fields_9999 = |
| 712 |
read_field( { record => $record, field => '999', subfield => '9' } ); |
| 713 |
is_deeply( \@fields_9999, [], |
| 714 |
'copy a nonexistent field does not create a new one' ); |
| 651 |
}; |
715 |
}; |
| 652 |
}; |
716 |
}; |
| 653 |
|
717 |
|
|
Lines 655-661
subtest 'copy_field' => sub {
Link Here
|
| 655 |
subtest 'move_field' => sub { |
719 |
subtest 'move_field' => sub { |
| 656 |
plan tests => 2; |
720 |
plan tests => 2; |
| 657 |
subtest 'move subfield' => sub { |
721 |
subtest 'move subfield' => sub { |
| 658 |
plan tests => 6; |
722 |
plan tests => 7; |
| 659 |
my $record = new_record; |
723 |
my $record = new_record; |
| 660 |
my ( @fields_952d, @fields_952c, @fields_954c, @fields_954p ); |
724 |
my ( @fields_952d, @fields_952c, @fields_954c, @fields_954p ); |
| 661 |
$record->append_fields( |
725 |
$record->append_fields( |
|
Lines 726-735
subtest 'move_field' => sub {
Link Here
|
| 726 |
[ '3010023917', '3010023917' ], |
790 |
[ '3010023917', '3010023917' ], |
| 727 |
'Now 2 954$p exist' |
791 |
'Now 2 954$p exist' |
| 728 |
); |
792 |
); |
|
|
793 |
|
| 794 |
move_field( |
| 795 |
{ |
| 796 |
record => $record, |
| 797 |
from_field => '111', |
| 798 |
from_subfield => '1', |
| 799 |
to_field => '999', |
| 800 |
to_subfield => '9' |
| 801 |
} |
| 802 |
); |
| 803 |
my @fields_9999 = |
| 804 |
read_field( { record => $record, field => '999', subfield => '9' } ); |
| 805 |
is_deeply( \@fields_9999, [], |
| 806 |
'move a nonexistent subfield does not create a new one' ); |
| 729 |
}; |
807 |
}; |
| 730 |
|
808 |
|
| 731 |
subtest 'move field' => sub { |
809 |
subtest 'move field' => sub { |
| 732 |
plan tests => 8; |
810 |
plan tests => 9; |
| 733 |
|
811 |
|
| 734 |
# move_field - fields |
812 |
# move_field - fields |
| 735 |
my $record = new_record; |
813 |
my $record = new_record; |
|
Lines 807-812
subtest 'move_field' => sub {
Link Here
|
| 807 |
[ '3010023917', 'DVD' ], |
885 |
[ '3010023917', 'DVD' ], |
| 808 |
"use a regex, second original fields has been copied" |
886 |
"use a regex, second original fields has been copied" |
| 809 |
); |
887 |
); |
|
|
888 |
|
| 889 |
move_field( |
| 890 |
{ |
| 891 |
record => $record, |
| 892 |
from_field => '111', |
| 893 |
to_field => '999', |
| 894 |
} |
| 895 |
); |
| 896 |
my @fields_9999 = |
| 897 |
read_field( { record => $record, field => '999', subfield => '9' } ); |
| 898 |
is_deeply( \@fields_9999, [], |
| 899 |
'move a nonexistent field does not create a new one' ); |
| 900 |
|
| 810 |
}; |
901 |
}; |
| 811 |
}; |
902 |
}; |
| 812 |
|
903 |
|
| 813 |
- |
|
|