Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beveradb committed Dec 4, 2024
1 parent c70187a commit b519c98
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions karaoke_lyrics_processor/karaoke_lyrics_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 45 additions & 0 deletions tests/test_karaoke_lyrics_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit b519c98

Please sign in to comment.