diff --git a/standardize_test_format/__init__.py b/standardize_test_format/__init__.py index f3e1d5f..9b0d43f 100644 --- a/standardize_test_format/__init__.py +++ b/standardize_test_format/__init__.py @@ -9,7 +9,8 @@ TEST_PATTERN: re.Pattern = re.compile( r'(?:/\*\*(?P<comment>.*)\*/)?\s*' + r'@(?P<annotation>Test|BeforeEach|ParameterizedTest)\s*' + r'(?:@DisplayName\("(?P<display>.*)"\)\s*)?' - + r'(?P<visibility>public\s+|private\s+)?void\s+(?P<name>\w+)\(', re.IGNORECASE) + + r'(?P<visibility>public\s+|private\s+)?void\s+(?P<name>\w+)\(', + re.IGNORECASE | re.DOTALL) END_SYMBOLS = '.?!' @@ -43,8 +44,16 @@ def to_camel_case(description: str) -> str: def from_camel_case(name: str) -> str: return re.sub(r'(^|[A-Z])[a-z]*', lambda x: ' '+x.group(0).capitalize(), name).strip() +def parse_comment_to_description(text: str| None): + if text is None: + return '' + text = re.sub(r'^\s*\*', ' ', text.strip()).strip() + return text + def replace_test_pattern(match: re.Match, with_javadoc: bool, with_display_name: bool) -> str: - comment = (match.group('comment') or '').strip() + comment = parse_comment_to_description(match.group('comment')) + + annotation = match.group('annotation').strip() visibility = (match.group('visibility') or '').strip() name = match.group('name').strip() diff --git a/test/test_standardize.py b/test/test_standardize.py index 425432b..6b83ad9 100644 --- a/test/test_standardize.py +++ b/test/test_standardize.py @@ -37,14 +37,31 @@ OUTPUT_3 = """ public void helloWorldTest( """ +INPUT_4 = """ +/** +* Concat two produces a new array with the two input arrays joined together, with no separators. +*/ +@Test +public void concatTwo() +""" + +OUTPUT_4 = """ +@Test +@DisplayName("Concat two produces a new array with the two input arrays joined together, with no separators") +public void concatTwoProducesANewArrayWithTheTwoInputArraysJoinedTogetherWithNoSeparators() +""" + def test_1(): - assert standardize_java_text(INPUT_1.strip()) == OUTPUT_1.strip() + assert standardize_java_text(INPUT_1.strip(),False,True) == OUTPUT_1.strip() def test_2(): - assert standardize_java_text(INPUT_2.strip()) == OUTPUT_2.strip() + assert standardize_java_text(INPUT_2.strip(),False,True) == OUTPUT_2.strip() def test_3(): - assert standardize_java_text(INPUT_3.strip()) == OUTPUT_3.strip() + assert standardize_java_text(INPUT_3.strip(),False,True) == OUTPUT_3.strip() + +def test_4(): + assert standardize_java_text(INPUT_4.strip(),False,True) == OUTPUT_4.strip()