From b519c988074a4b96d1b4b50592d1be204325d169 Mon Sep 17 00:00:00 2001 From: Andrew Beveridge Date: Wed, 4 Dec 2024 11:54:31 -0500 Subject: [PATCH] Added tests --- .../karaoke_lyrics_processor.py | 4 +- tests/test_karaoke_lyrics_processor.py | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/karaoke_lyrics_processor/karaoke_lyrics_processor.py b/karaoke_lyrics_processor/karaoke_lyrics_processor.py index 192db65..2e5ec49 100644 --- a/karaoke_lyrics_processor/karaoke_lyrics_processor.py +++ b/karaoke_lyrics_processor/karaoke_lyrics_processor.py @@ -151,8 +151,8 @@ def replace_non_printable_spaces(self, text): self.logger.debug(f"Replacing non-printable spaces in: {repr(text)}") # Log each character and its Unicode code point - for i, char in enumerate(text): - self.logger.debug(f"Character at position {i}: {repr(char)} (Unicode: U+{ord(char):04X})") + # for i, char in enumerate(text): + # self.logger.debug(f"Character at position {i}: {repr(char)} (Unicode: U+{ord(char):04X})") # Define a pattern for space-like characters, including tabs and other whitespace, but excluding newlines space_pattern = r"[^\S\n\r]|\u00A0|\u1680|\u2000-\u200A|\u202F|\u205F|\u3000" diff --git a/tests/test_karaoke_lyrics_processor.py b/tests/test_karaoke_lyrics_processor.py index 760d8b2..b8fdf31 100644 --- a/tests/test_karaoke_lyrics_processor.py +++ b/tests/test_karaoke_lyrics_processor.py @@ -15,6 +15,51 @@ def test_simple_processing(self): self.assertEqual(result, expected_output) + def test_non_printable_spaces(self): + input_lyrics = "This is a test line with\u2005non-printable spaces." + expected_output = "This is a test\nline with non-printable spaces." + + self.processor.input_lyrics_lines = [input_lyrics] + result = self.processor.process() + + self.assertEqual(result, expected_output) + + def test_long_line_with_commas(self): + input_lyrics = "This line, which is quite long, should be split at a comma." + expected_output = "This line, which is quite long,\nshould be split at a comma." + + self.processor.input_lyrics_lines = [input_lyrics] + result = self.processor.process() + + self.assertEqual(result, expected_output) + + def test_long_line_with_and(self): + input_lyrics = "This line is long and should be split at 'and'." + expected_output = "This line is long and\nshould be split at 'and'." + + self.processor.input_lyrics_lines = [input_lyrics] + result = self.processor.process() + + self.assertEqual(result, expected_output) + + def test_line_with_parentheses(self): + input_lyrics = "This line (with parentheses) should be split correctly." + expected_output = "This line\n(with parentheses)\nshould be split correctly." + + self.processor.input_lyrics_lines = [input_lyrics] + result = self.processor.process() + + self.assertEqual(result, expected_output) + + def test_multiple_lines(self): + input_lyrics = "First line.\nSecond line with\u2005non-printable space." + expected_output = "First line.\nSecond line\nwith non-printable space." + + self.processor.input_lyrics_lines = input_lyrics.splitlines() + result = self.processor.process() + + self.assertEqual(result, expected_output) + if __name__ == "__main__": unittest.main()