Skip to content

Commit

Permalink
wip test parsing brackets in thread name
Browse files Browse the repository at this point in the history
  • Loading branch information
dariagrudzien committed Aug 14, 2023
1 parent fca45db commit 527296c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
37 changes: 37 additions & 0 deletions juniorguru_chick/lib/thread_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import re

def name_thread(message: str) -> str | None:
"""Returns a name for a thread created from a given message. Example messages include: [eslint, nextjs], [eslint,nextjs], [ Java ], [:css:], [:css: CSS], [eslint,nextjs, :css: CSS]. Expected output includes: eslint, nextjs, eslint,nextjs, Java, css, CSS, eslint,nextjs, CSS."""

"""
1. Check if the message includes text in brackets, if yes:
a. Remove brackets
b. Remove spaces
c. Check if the message includes text between colons
- if yes, and there is other text in the message, then remove the colons and text between them
- if yes, and there is no other text in the message, then remove the colons
d. Insert spaces after commas if there are any
e. Capitalize the first letter of the message
d. Return the message
2. If the message does not include text in brackets, then return string "xyz"
"""


if message.startswith("[") :
content = message[1:-1]
content = content.replace(" ", "")

emoji_regex = re.compile(r":\w+:")

if re.search(emoji_regex, content) is not None:
# if there is other text in the message, then remove the colons and text between them
emoji = re.search(emoji_regex, content).group()
if content != emoji:
content = content.replace(emoji, "")
# if there is no other text in the message, then remove the colons
else:
content = content.replace(":", "")
content = content.replace(",", ", ")
return content
else:
return "xyz"
6 changes: 6 additions & 0 deletions tests/test_lib_thread_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest
from juniorguru_chick.lib.thread_names import name_thread

@pytest.mark.parametrize('message, expected_name', [("[eslint, nextjs]", "eslint, nextjs"), ("[eslint,nextjs]", "eslint,nextjs"), ("[ Java ]", "Java"), ("[:css: CSS]", "CSS"), ("[eslint,nextjs, :css: CSS, ruby]", "eslint, nextjs, CSS, ruby")])
def parse_message_brackets(message, expected_name):
assert name_thread(message) == expected_name

0 comments on commit 527296c

Please sign in to comment.