From d96138591c0c5fa1a23e191ca2db84df682a8130 Mon Sep 17 00:00:00 2001
From: Amit Kumar Deohoria
Date: Tue, 26 Nov 2024 15:06:02 +0530
Subject: [PATCH] Issue #13345: Enable examples tests for RegexpMultilineCheck
---
.../RegexpMultilineCheckExamplesTest.java | 49 ++---
.../regexp/regexpmultiline/Example1.java | 41 ++++
.../regexp/regexpmultiline/Example1.txt | 12 --
.../regexp/regexpmultiline/Example2.java | 43 ++++
.../regexp/regexpmultiline/Example2.txt | 26 ---
.../regexp/regexpmultiline/Example3.java | 44 ++++
.../regexp/regexpmultiline/Example3.txt | 27 ---
.../regexp/regexpmultiline/Example4.java | 45 ++++
.../regexp/regexpmultiline/Example4.txt | 21 --
.../regexp/regexpmultiline/Example5.java | 44 ++++
.../regexp/regexpmultiline/Example5.txt | 19 --
src/xdocs/checks/regexp/regexpmultiline.xml | 203 +++++++++++++-----
.../regexp/regexpmultiline.xml.template | 20 +-
13 files changed, 407 insertions(+), 187 deletions(-)
create mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.java
delete mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.txt
create mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.java
delete mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.txt
create mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.java
delete mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.txt
create mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.java
delete mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.txt
create mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.java
delete mode 100644 src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.txt
diff --git a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpMultilineCheckExamplesTest.java b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpMultilineCheckExamplesTest.java
index 085039db2b3..5d5d879a9c1 100644
--- a/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpMultilineCheckExamplesTest.java
+++ b/src/xdocs-examples/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpMultilineCheckExamplesTest.java
@@ -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() {
@@ -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);
}
}
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.java
new file mode 100644
index 00000000000..c3f198d8d5a
--- /dev/null
+++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.java
@@ -0,0 +1,41 @@
+/*xml
+
+
+
+*/
+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
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.txt
deleted file mode 100644
index 02991bb66dc..00000000000
--- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-/*xml
-
-
-
-*/
-
-// xdoc section -- start
-void method() {
- int i = 5; // OK
- System.out.println(i); // OK
-}
-// xdoc section -- end
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.java
new file mode 100644
index 00000000000..0765b4ecd22
--- /dev/null
+++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.java
@@ -0,0 +1,43 @@
+/*xml
+
+
+
+
+
+*/
+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
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.txt
deleted file mode 100644
index 1c4303ccd04..00000000000
--- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-/*xml
-
-
-
-
-
-*/
-
-// xdoc section -- start
-void method() {
- System.out.print("Example"); // violation
- System.err.println("Example"); // violation
- System.out.print
- ("Example"); // violation
- System.err.println
- ("Example"); // OK
- System
- .out.print("Example"); // OK
- System
- .err.println("Example"); // violation
- System.
- out.print("Example"); // OK
- System.
- err.println("Example"); // violation
-}
-// xdoc section -- end
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.java
new file mode 100644
index 00000000000..84d9f3b9343
--- /dev/null
+++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.java
@@ -0,0 +1,44 @@
+/*xml
+
+
+
+
+
+
+*/
+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
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.txt
deleted file mode 100644
index e97c95f74b1..00000000000
--- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-/*xml
-
-
-
-
-
-
-*/
-
-// xdoc section -- start
-void method() {
- System.out.print("Example"); // violation
- System.err.println("Example");
- System.out.print // violation
- ("Example");
- System.err.println
- ("Example");
- System
- .out.print("Example");
- System
- .err.println("Example");
- System.
- out.print("Example");
- System.
- err.println("Example");
-}
-// xdoc section -- end
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.java
new file mode 100644
index 00000000000..0c0c538d871
--- /dev/null
+++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.java
@@ -0,0 +1,45 @@
+/*xml
+
+
+
+
+
+
+
+*/
+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
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.txt
deleted file mode 100644
index c0b0868b31d..00000000000
--- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-/*xml
-
-
-
-
-
-
-
-*/
-
-// xdoc section -- start
-void method() {
- System.out.println("Test #1: this is a test string"); // OK
- System.out.println("TeSt #2: This is a test string"); // OK
- System.out.println("TEST #3: This is a test string"); // OK
- int i = 5;
- System.out.println("Value of i: " + i);
- System.out.println("Test #4: This is a test string"); // violation
- System.out.println("TEst #5: This is a test string"); // violation
-}
-// xdoc section -- end
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.java b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.java
new file mode 100644
index 00000000000..7c4d4923c96
--- /dev/null
+++ b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.java
@@ -0,0 +1,44 @@
+/*xml
+
+
+
+
+
+
+*/
+package com.puppycrawl.tools.checkstyle.checks.regexp.regexpmultiline;
+
+// xdoc section -- start
+class Example5 {
+ 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() {
+ // violation below, 'Line matches the illegal pattern'
+ 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 #3: This is a test string");
+ // violation below, 'Line matches the illegal pattern'
+ System.out.println("Test #4: This is a test string");
+ }
+}
+// xdoc section -- end
diff --git a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.txt b/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.txt
deleted file mode 100644
index 069f2caa532..00000000000
--- a/src/xdocs-examples/resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-/*xml
-
-
-
-
-
-
-*/
-
-// xdoc section -- start
-void method() {
- System.out.println("Test #1: this is a test string"); // violation
- System.out.println("TEST #2: This is a test string"); // OK, "ignoreCase" is false by default
- int i = 5;
- System.out.println("Value of i: " + i);
- System.out.println("Test #3: This is a test string"); // violation
- System.out.println("Test #4: This is a test string"); // violation
-}
-// xdoc section -- end
diff --git a/src/xdocs/checks/regexp/regexpmultiline.xml b/src/xdocs/checks/regexp/regexpmultiline.xml
index 78f83de0906..7b64ce881de 100644
--- a/src/xdocs/checks/regexp/regexpmultiline.xml
+++ b/src/xdocs/checks/regexp/regexpmultiline.xml
@@ -96,9 +96,37 @@
Example:
@@ -115,21 +143,37 @@ void method() {
Example:
@@ -148,21 +192,37 @@ void method() {
Example:
@@ -189,14 +249,37 @@ void method() {
Example:
@@ -214,13 +297,37 @@ void method() {
Example:
diff --git a/src/xdocs/checks/regexp/regexpmultiline.xml.template b/src/xdocs/checks/regexp/regexpmultiline.xml.template
index 908f5721e29..d03e3f2850d 100644
--- a/src/xdocs/checks/regexp/regexpmultiline.xml.template
+++ b/src/xdocs/checks/regexp/regexpmultiline.xml.template
@@ -35,7 +35,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.java"/>
@@ -43,7 +43,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example1.java"/>
@@ -51,7 +51,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.java"/>
@@ -59,7 +59,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example2.java"/>
@@ -68,7 +68,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.java"/>
@@ -76,7 +76,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example3.java"/>
@@ -92,7 +92,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.java"/>
@@ -100,7 +100,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example4.java"/>
@@ -108,7 +108,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.java"/>
@@ -116,7 +116,7 @@
+ value="resources/com/puppycrawl/tools/checkstyle/checks/regexp/regexpmultiline/Example5.java"/>