Skip to content

Commit

Permalink
Issue #13345: Enable examples tests for RegexpMultilineCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitKumarDeoghoria authored and romani committed Nov 26, 2024
1 parent 7868e65 commit d961385
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

package com.puppycrawl.tools.checkstyle.checks.regexp;

import org.junit.jupiter.api.Disabled;
import static com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck.MSG_ILLEGAL_REGEXP;

import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;

@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
public class RegexpMultilineCheckExamplesTest extends AbstractExamplesModuleTestSupport {
@Override
protected String getPackageLocation() {
Expand All @@ -33,55 +34,55 @@ protected String getPackageLocation() {

@Test
public void testExample1() throws Exception {
final String[] expected = {

};

verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verifyWithInlineConfigParser(getPath("Example1.java"), expected);
}

@Test
public void testExample2() throws Exception {
final String[] expected = {

"14: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"16: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"20: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"24: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"29: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"31: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"33: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"36: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"38: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
"40: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.(out)|(err)\\.print(ln)?\\("),
};

verifyWithInlineConfigParser(getPath("Example2.txt"), expected);
verifyWithInlineConfigParser(getPath("Example2.java"), expected);
}

@Test
public void testExample3() throws Exception {
final String[] expected = {

"15: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.out.*?print\\("),
};

verifyWithInlineConfigParser(getPath("Example3.txt"), expected);
verifyWithInlineConfigParser(getPath("Example3.java"), expected);
}

@Test
public void testExample4() throws Exception {
final String[] expected = {

"40: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "Test #[0-9]+:[A-Za-z ]+"),
"42: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "Test #[0-9]+:[A-Za-z ]+"),
};

verifyWithInlineConfigParser(getPath("Example4.txt"), expected);
verifyWithInlineConfigParser(getPath("Example4.java"), expected);
}

@Test
public void testExample5() throws Exception {
final String[] expected = {

};

verifyWithInlineConfigParser(getPath("Example5.txt"), expected);
}

@Test
public void testExample6() throws Exception {
final String[] expected = {

"30: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "Test #[0-9]+:[A-Za-z ]+"),
"39: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "Test #[0-9]+:[A-Za-z ]+"),
"41: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "Test #[0-9]+:[A-Za-z ]+"),
};

verifyWithInlineConfigParser(getPath("Example6.txt"), expected);
verifyWithInlineConfigParser(getPath("Example5.java"), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*xml
<module name="Checker">
<module name="RegexpMultiline"/>
</module>
*/
package com.puppycrawl.tools.checkstyle.checks.regexp.regexpmultiline;

// xdoc section -- start
class Example1 {
void testMethod1() {

System.out.print("Example");

System.err.println("Example");
System
.out.print("Example");
System
.err.println("Example");
System.
out.print("Example");
System.
err.println("Example");
}

void testMethod2() {

System.out.println("Test #1: this is a test string");

System.out.println("TeSt #2: This is a test string");

System.out.println("TEST #3: This is a test string");
int i = 5;

System.out.println("Value of i: " + i);

System.out.println("Test #4: This is a test string");

System.out.println("TEst #5: This is a test string");
}
}
// xdoc section -- end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*xml
<module name="Checker">
<module name="RegexpMultiline">
<property name="format" value="System\.(out)|(err)\.print(ln)?\("/>
</module>
</module>
*/
package com.puppycrawl.tools.checkstyle.checks.regexp.regexpmultiline;

// xdoc section -- start
class Example2 {
void testMethod1() {
// violation below, 'Line matches the illegal pattern'
System.out.print("Example");
// violation below, 'Line matches the illegal pattern'
System.err.println("Example");
System
.out.print("Example");
System
.err.println("Example"); // violation, 'Line matches the illegal pattern'
System.
out.print("Example");
System.
err.println("Example"); // violation, 'Line matches the illegal pattern'
}

void testMethod2() {
// violation below, 'Line matches the illegal pattern'
System.out.println("Test #1: this is a test string");
// violation below, 'Line matches the illegal pattern'
System.out.println("TeSt #2: This is a test string");
// violation below, 'Line matches the illegal pattern'
System.out.println("TEST #3: This is a test string");
int i = 5;
// violation below, 'Line matches the illegal pattern'
System.out.println("Value of i: " + i);
// violation below, 'Line matches the illegal pattern'
System.out.println("Test #4: This is a test string");
// violation below, 'Line matches the illegal pattern'
System.out.println("TEst #5: This is a test string");
}
}
// xdoc section -- end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*xml
<module name="Checker">
<module name="RegexpMultiline">
<property name="matchAcrossLines" value="true"/>
<property name="format" value="System\.out.*?print\("/>
</module>
</module>
*/
package com.puppycrawl.tools.checkstyle.checks.regexp.regexpmultiline;

// xdoc section -- start
class Example3 {
void testMethod1() {
// violation below, 'Line matches the illegal pattern'
System.out.print("Example");

System.err.println("Example");
System
.out.print("Example");
System
.err.println("Example");
System.
out.print("Example");
System.
err.println("Example");
}

void testMethod2() {

System.out.println("Test #1: this is a test string");

System.out.println("TeSt #2: This is a test string");

System.out.println("TEST #3: This is a test string");
int i = 5;

System.out.println("Value of i: " + i);

System.out.println("Test #4: This is a test string");

System.out.println("TEst #5: This is a test string");
}
}
// xdoc section -- end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*xml
<module name="Checker">
<module name="RegexpMultiline">
<property name="format" value="Test #[0-9]+:[A-Za-z ]+"/>
<property name="ignoreCase" value="true"/>
<property name="maximum" value="3"/>
</module>
</module>
*/
package com.puppycrawl.tools.checkstyle.checks.regexp.regexpmultiline;

// xdoc section -- start
class Example4 {
void testMethod1() {

System.out.print("Example");

System.err.println("Example");
System
.out.print("Example");
System
.err.println("Example");
System.
out.print("Example");
System.
err.println("Example");
}

void testMethod2() {

System.out.println("Test #1: this is a test string");

System.out.println("TeSt #2: This is a test string");

System.out.println("TEST #3: This is a test string");
int i = 5;

System.out.println("Value of i: " + i);
// violation below, 'Line matches the illegal pattern'
System.out.println("Test #4: This is a test string");
// violation below, 'Line matches the illegal pattern'
System.out.println("TEst #5: This is a test string");
}
}
// xdoc section -- end

This file was deleted.

Loading

0 comments on commit d961385

Please sign in to comment.