From 23d32cad43bdfbf5531f5e27a4586a26a3651ee1 Mon Sep 17 00:00:00 2001 From: Max Rossmannek Date: Wed, 1 May 2024 15:42:44 +0200 Subject: [PATCH] fix: for using an empty character as label_suffix separator Closes #138 --- CHANGELOG.md | 3 +++ src/cobib/config/config.py | 7 ++++++- tests/database/disambiguation_database.yaml | 7 +++++++ tests/database/test_database.py | 8 ++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 111759f..e355695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/cobib/config/config.py b/src/cobib/config/config.py index d7e4c8f..bd2a6ec 100644 --- a/src/cobib/config/config.py +++ b/src/cobib/config/config.py @@ -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 diff --git a/tests/database/disambiguation_database.yaml b/tests/database/disambiguation_database.yaml index cfd3b9e..94e3e36 100644 --- a/tests/database/disambiguation_database.yaml +++ b/tests/database/disambiguation_database.yaml @@ -40,3 +40,10 @@ Author2022: title: Some entry year: 2022 ... +--- +Author2022a: + ENTRYTYPE: book + author: Author + title: Some entry a + year: 2022 +... diff --git a/tests/database/test_database.py b/tests/database/test_database.py index e869165..70c63bf 100644 --- a/tests/database/test_database.py +++ b/tests/database/test_database.py @@ -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: @@ -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(