diff --git a/Changes b/Changes index a976e3f..775e5d5 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for PICA::Data {{$NEXT}} - Add explicit PICA Patch parser and writer - Fix parsing plain $$ (#136) + - Fix diff for multiple fields of same identifier - Avoid circular dependency 2.11 2023-08-18T05:19:26Z diff --git a/lib/PICA/Patch.pm b/lib/PICA/Patch.pm index 7f1221c..9b34d1e 100644 --- a/lib/PICA/Patch.pm +++ b/lib/PICA/Patch.pm @@ -30,6 +30,8 @@ sub sorted_fields { } } + $fields = [sort {cmp_fields($a, $b)} @$fields]; + return $fields; } diff --git a/t/90-patch.t b/t/90-patch.t index 23f63c7..0499b33 100644 --- a/t/90-patch.t +++ b/t/90-patch.t @@ -11,6 +11,8 @@ is_diff("001A \$x0\n002A \$x0", "001A \$x0\n002A \$y1", "- 002A \$x0\n+ 002A \$y1", 'changed field'); is_diff("001A \$x0\n002A \$x0", "002A \$x0\n001A \$x0", '', 'compare sorted'); +is_diff("045Q/01 \$aXX.XX\n045Q/01 \$a38.10", "045Q/01 \$a38.10", '- 045Q/01 $aXX.XX', "sort before diff"); + is_patch("001A \$x.", "+ 001A \$y.", "001A \$x.\n001A \$y.", 'add same field id'); is_patch("002A \$x.", "+ 001A \$y.", "001A \$y.\n002A \$x.", 'add before first field'); is_patch("001A \$x.", "- 001A \$x.\n+ 001A \$y.", "001A \$y.", 'replace field id');