Skip to content

Commit

Permalink
fix: for using an empty character as label_suffix separator
Browse files Browse the repository at this point in the history
Closes #138
  • Loading branch information
mrossinek committed May 1, 2024
1 parent 4f382cc commit 23d32ca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- the ability to use an empty string as the separator in `config.database.format.label_suffix` (#138)


## [5.0.0] - 2024-04-28

Expand Down
7 changes: 6 additions & 1 deletion src/cobib/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,12 @@ def trim_label(label: str, separator: str, type_: LabelSuffix) -> tuple[str, int
suffix_value = 0

# try split the suffix from the label using the provided separator
*pieces, suffix = label.split(separator)
if separator:
*pieces, suffix = label.split(separator)
else:
# no character is used for separation, we simply fall back to using the last one
suffix = label[-1]
pieces = [label[:-1]]

if pieces:
# piece together the left-over raw label without its suffix
Expand Down
7 changes: 7 additions & 0 deletions tests/database/disambiguation_database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ Author2022:
title: Some entry
year: 2022
...
---
Author2022a:
ENTRYTYPE: book
author: Author
title: Some entry a
year: 2022
...
8 changes: 8 additions & 0 deletions tests/database/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def test_database_rename() -> None:
[(".", LabelSuffix.ALPHA), "test.a"],
[(".", LabelSuffix.CAPITAL), "test.A"],
[(".", LabelSuffix.NUMERIC), "test.1"],
[("", LabelSuffix.ALPHA), "testa"],
[("", LabelSuffix.CAPITAL), "testA"],
[("", LabelSuffix.NUMERIC), "test1"],
],
)
def test_database_disambiguate_label(label_suffix: tuple[str, LabelSuffix], expected: str) -> None:
Expand Down Expand Up @@ -181,6 +184,11 @@ def test_database_disambiguate_label(label_suffix: tuple[str, LabelSuffix], expe
("_", LabelSuffix.NUMERIC),
({"Author2021", "Author2021_2"}, set()),
],
[
"Author2022",
("", LabelSuffix.ALPHA),
({"Author2022", "Author2022a"}, set()),
],
],
)
def test_find_related_labels(
Expand Down

0 comments on commit 23d32ca

Please sign in to comment.