-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip test parsing brackets in thread name
- Loading branch information
1 parent
fca45db
commit 527296c
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |