Skip to content

Commit

Permalink
Fix diff for multiple fields of same identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Aug 28, 2023
1 parent 810ba9c commit 7121fe0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/PICA/Patch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ sub sorted_fields {
}
}

$fields = [sort {cmp_fields($a, $b)} @$fields];

return $fields;
}

Expand Down
2 changes: 2 additions & 0 deletions t/90-patch.t
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 7121fe0

Please sign in to comment.