diff --git a/standardize_test_format/__init__.py b/standardize_test_format/__init__.py index 41490fa..fb5dd69 100644 --- a/standardize_test_format/__init__.py +++ b/standardize_test_format/__init__.py @@ -47,8 +47,11 @@ class Config: PATTERN_JAVADOC = r'/\*\*(?P.*(\n\s*\*.*)*?)\s*\*/' PATTERN_DISPLAY_NAME_EXPRESSION = r'\s*(?:"[^"]*?")(?:\s*\+\s*"[^"]*?")*\s*' -PATTERN_DISPLAY_NAME = ( - r'@DisplayName\((?P' + PATTERN_DISPLAY_NAME_EXPRESSION + r')\)' +PATTERN_DISPLAY_NAME_1 = ( + r'@DisplayName\((?P' + PATTERN_DISPLAY_NAME_EXPRESSION + r')\)' +) +PATTERN_DISPLAY_NAME_2 = ( + r'@DisplayName\((?P' + PATTERN_DISPLAY_NAME_EXPRESSION + r')\)' ) TEST_PATTERN: re.Pattern = re.compile( @@ -56,9 +59,12 @@ TEST_PATTERN: re.Pattern = re.compile( + r'(?:' + PATTERN_JAVADOC + r'\s*)?' + + r'(?:' + + PATTERN_DISPLAY_NAME_1 + + r'\s*)?' + r'@(?PTest|BeforeEach|ParameterizedTest)\s*' + r'(?:' - + PATTERN_DISPLAY_NAME + + PATTERN_DISPLAY_NAME_2 + r'\s*)?' + r'(?Ppublic\s+|private\s+)?void\s+(?P\w+)\(', re.IGNORECASE, @@ -183,7 +189,9 @@ def replace_test_pattern( annotation = match.group('annotation').strip() visibility = (match.group('visibility') or '').strip() name = match.group('name').strip() - displayname = parse_display_name_to_description(match.group('displayname')) + displayname1 = parse_display_name_to_description(match.group('displayname1')) + displayname2 = parse_display_name_to_description(match.group('displayname2')) + displayname = displayname1 or displayname2 # Filtering if config.only_for_javadoc and not javadoc: diff --git a/test/test_parsing.py b/test/test_parsing.py index 9aa4f98..0d3f722 100644 --- a/test/test_parsing.py +++ b/test/test_parsing.py @@ -3,7 +3,7 @@ import re import pytest from standardize_test_format import ( - PATTERN_DISPLAY_NAME, + PATTERN_DISPLAY_NAME_1, PATTERN_DISPLAY_NAME_EXPRESSION, PATTERN_JAVADOC, ) @@ -38,7 +38,7 @@ def test_javadoc_parsing(text: str): @pytest.mark.parametrize('text', VALID_DISPLAY_NAMES) def test_display_name_parsing(text: str): - assert re.match(PATTERN_DISPLAY_NAME, text) is not None + assert re.match(PATTERN_DISPLAY_NAME_1, text) is not None @pytest.mark.parametrize('text', VALID_DISPLAY_NAME_EXPRESSIONS) diff --git a/test/test_standardize.py b/test/test_standardize.py index efbeba0..331a17b 100644 --- a/test/test_standardize.py +++ b/test/test_standardize.py @@ -1,6 +1,6 @@ import pytest -from standardize_test_format import NamingScheme, standardize_java_text +from standardize_test_format import NamingScheme, standardize_java_text, Config INPUT_1 = """ package test; @@ -103,13 +103,25 @@ package test; public void zkBinderContextImplPropagatesLotOfFieldsDirectlyFromTheUnderlyingZkBinderContext() """ +INPUT_5D = """ +package test; + +@DisplayName( + "ZkBinderContextImpl propagates a lot of " + + "fields directly from " + + "the underlying ZkBinderContext" +) +@Test +public void zkBinderContextImplPropagatesLotOfFieldsDirectlyFromTheUnderlyingZkBinderContext() +""" + OUTPUT_5 = """ package test; import org.junit.jupiter.api.DisplayName; @Test @DisplayName("ZkBinderContextImpl propagates a lot of fields directly from the underlying ZkBinderContext") -public void zkBinderContextImplPropagatesLotOfFieldsDirectlyFromUnderlyingZkBinderContext() +public void zkBinderContextImplPropagatesLotFieldsDirectlyFromUnderlyingZkBinderContext() """ JAVADOC_TO_DISPLAYNAME = [ @@ -120,15 +132,18 @@ JAVADOC_TO_DISPLAYNAME = [ (INPUT_5, OUTPUT_5), (INPUT_5B, OUTPUT_5), (INPUT_5C, OUTPUT_5), + (INPUT_5D, OUTPUT_5), ] -@pytest.mark.parametrize('inp,output', JAVADOC_TO_DISPLAYNAME) +@pytest.mark.parametrize(('inp','output'), JAVADOC_TO_DISPLAYNAME) def test_javadoc_to_displayname(inp: str, output: str): - converted = standardize_java_text( - inp.strip(), + config = Config( with_javadoc=False, with_display_name=True, + only_for_javadoc = False, + only_for_display_name = False, naming_scheme=NamingScheme.FROM_DESC, ) + converted = standardize_java_text(inp.strip(), config) assert converted == output.strip()