Compare commits
2 Commits
e803f21f6e
...
ba387a0aa0
Author | SHA1 | Date | |
---|---|---|---|
ba387a0aa0 | |||
7c8523136a |
|
@ -6,7 +6,8 @@ Tool for standardizing Java tests.
|
|||
import re
|
||||
|
||||
PATTERN_JAVADOC = r'/\*\*(?P<javadoc>.*(\n\s*\*.*)*?)\s*\*/'
|
||||
PATTERN_DISPLAY_NAME = r'@DisplayName\(\s*"(?P<display>[^"]*?)"\s*\)'
|
||||
PATTERN_DISPLAY_NAME_EXPRESSION = r'\s*(?:"[^"]*?")(?:\s*\+\s*"[^"]*?")*\s*'
|
||||
PATTERN_DISPLAY_NAME = r'@DisplayName\((?P<display>'+PATTERN_DISPLAY_NAME_EXPRESSION+r')\)'
|
||||
|
||||
TEST_PATTERN: re.Pattern = re.compile(
|
||||
r''
|
||||
|
@ -23,7 +24,7 @@ IGNORABLE_WORDS_IN_NAME = frozenset({
|
|||
'a',
|
||||
'the',
|
||||
'is',
|
||||
'are'
|
||||
'are',
|
||||
})
|
||||
|
||||
def format_test_prefix(name: str, description: str, annotation:
|
||||
|
@ -52,7 +53,7 @@ def to_camel_case_word(word: str, first: bool = False) -> str | None:
|
|||
return (word[0].lower() if first else word[0].upper()) + word[1:]
|
||||
|
||||
def to_camel_case(description: str) -> str:
|
||||
description = description.strip(' \t.').replace(',',' ')
|
||||
description = description.replace(',',' ').replace('.',' ').replace('"', ' ').replace('+', ' ').strip(' \t.')
|
||||
words = description.split(' ')
|
||||
|
||||
words[0] = to_camel_case_word(words[0], first=True)
|
||||
|
@ -75,6 +76,18 @@ def parse_javadoc_to_description(text: str| None):
|
|||
text = re.sub(r'\{@link\s+(\w+)\}', r'\1', text)
|
||||
return text
|
||||
|
||||
|
||||
def parse_display_name_to_description(text: str|None):
|
||||
if text is None:
|
||||
return ''
|
||||
|
||||
text = text.strip()
|
||||
text = re.sub(r'"\s*\+\s*"', '', text)
|
||||
text = text.strip('"')
|
||||
text = text.strip()
|
||||
return text
|
||||
|
||||
|
||||
def replace_test_pattern(match: re.Match, with_javadoc: bool, with_display_name: bool) -> str:
|
||||
javadoc = parse_javadoc_to_description(match.group('javadoc'))
|
||||
|
||||
|
@ -82,7 +95,7 @@ def replace_test_pattern(match: re.Match, with_javadoc: bool, with_display_name:
|
|||
annotation = match.group('annotation').strip()
|
||||
visibility = (match.group('visibility') or '').strip()
|
||||
name = match.group('name').strip()
|
||||
display = (match.group('display') or '').strip()
|
||||
display = parse_display_name_to_description(match.group('display'))
|
||||
|
||||
|
||||
description = display or javadoc or from_camel_case(name)
|
||||
|
|
|
@ -92,6 +92,18 @@ package test;
|
|||
public void zkBinderContextImplPropagatesLotOfFieldsDirectlyFromTheUnderlyingZkBinderContext()
|
||||
"""
|
||||
|
||||
INPUT_5C = """
|
||||
package test;
|
||||
|
||||
@Test
|
||||
@DisplayName(
|
||||
"ZkBinderContextImpl propagates a lot of "
|
||||
+ "fields directly from "
|
||||
+ "the underlying ZkBinderContext"
|
||||
)
|
||||
public void zkBinderContextImplPropagatesLotOfFieldsDirectlyFromTheUnderlyingZkBinderContext()
|
||||
"""
|
||||
|
||||
OUTPUT_5 = """
|
||||
package test;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
@ -119,3 +131,6 @@ def test_5():
|
|||
|
||||
def test_5b():
|
||||
assert standardize_java_text(INPUT_5B.strip(),False,True) == OUTPUT_5.strip()
|
||||
|
||||
def test_5c():
|
||||
assert standardize_java_text(INPUT_5C.strip(),False,True) == OUTPUT_5.strip()
|
||||
|
|
Loading…
Reference in New Issue
Block a user