From 84feb9161e1b8a6a1c127a224d3da7e08ff37de0 Mon Sep 17 00:00:00 2001 From: Hannes Krumbiegel Date: Tue, 9 May 2023 19:24:59 +0200 Subject: [PATCH] Fix serious bug + add new test against it --- russian_text_stresser/russian_dictionary.py | 4 ++-- russian_text_stresser/word_stress_tests.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/russian_text_stresser/russian_dictionary.py b/russian_text_stresser/russian_dictionary.py index cdb6d13..474ab98 100644 --- a/russian_text_stresser/russian_dictionary.py +++ b/russian_text_stresser/russian_dictionary.py @@ -287,9 +287,9 @@ def write_stressed_word(word: str, stressed_dict_word: str): # This is needed because some canonical words are incorrect in the database if char == "ё" or char == "Ё": yo_in_wrd = word[index] - if yo_in_wrd == "е": + if yo_in_wrd == "е" or yo_in_wrd == "ё": result_word += "ё" - elif yo_in_wrd == "Е": + elif yo_in_wrd == "Е" or yo_in_wrd == "Ё": result_word += "Ё" index += 1 elif char != "\u0301": diff --git a/russian_text_stresser/word_stress_tests.py b/russian_text_stresser/word_stress_tests.py index 2228e42..e6d85b3 100644 --- a/russian_text_stresser/word_stress_tests.py +++ b/russian_text_stresser/word_stress_tests.py @@ -59,6 +59,12 @@ def test_bylo(self): self.assertEqual( self.stresser.stress_text("Это было давно."), "Э́то бы́ло давно́." ) + + def test_yo_retaining(self): + self.assertEqual( + self.stresser.stress_text("Значит, спорить по этому поводу совершенно ни к чему, — твёрдо заключил Гарри."), + "Зна́чит, спо́рить по э́тому по́воду соверше́нно ни к чему́, — твёрдо заключи́л Га́рри.", + ) # SO FAR FAILING TESTS def test_vselennaya(self):