Skip to content

Commit

Permalink
Issue checkstyle#13345: Enable examples tests for RecordComponentName…
Browse files Browse the repository at this point in the history
…Check
  • Loading branch information
AmitKumarDeoghoria authored and romani committed Nov 15, 2024
1 parent 866552a commit 943163d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

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

import org.junit.jupiter.api.Disabled;
import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN;

import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;

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

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

final String pattern = "^[a-z][a-zA-Z0-9]*$";

final String[] expected = {
"15:22: " + getCheckMessage(MSG_INVALID_PATTERN, "Values", pattern),
};

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

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

final String pattern = "^[a-z]+$";

final String[] expected = {
"17:22: " + getCheckMessage(MSG_INVALID_PATTERN, "Values", pattern),
"19:22: " + getCheckMessage(MSG_INVALID_PATTERN, "myNumber", pattern),
};

verifyWithInlineConfigParser(getPath("Example2.txt"), expected);
verifyWithInlineConfigParser(
getNonCompilablePath("Example2.java"), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*xml
<module name="Checker">
<module name="TreeWalker">
<module name="RecordComponentName"/>
</module>
</module>
*/
//non-compiled with javac: Compilable with Java17
package com.puppycrawl.tools.checkstyle.checks.naming.recordcomponentname;

// xdoc section -- start
class Example1 {
record Rec1(int other) {}

record Rec2(String Values) {} // violation, Name must match '^[a-z][a-zA-Z0-9]*$'

record Rec3(double myNumber) {}
}
// xdoc section -- end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*xml
<module name="Checker">
<module name="TreeWalker">
<module name="RecordComponentName">
<property name="format" value="^[a-z]+$"/>
</module>
</module>
</module>
*/
//non-compiled with javac: Compilable with Java17
package com.puppycrawl.tools.checkstyle.checks.naming.recordcomponentname;

// xdoc section -- start
class Example2 {
record Rec1(int other) {}

record Rec2(String Values) {} // violation, Name must match '^[a-z]+$'

record Rec3(double myNumber) {} // violation, Name must match '^[a-z]+$'
}
// xdoc section -- end

This file was deleted.

This file was deleted.

23 changes: 14 additions & 9 deletions src/xdocs/checks/naming/recordcomponentname.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
</source>
<p id="Example1-code">Example:</p>
<source>
record MyRecord1(String value, int otherComponentName) {} // OK
record MyRecord2(String... Values) {} // violation, the record component name
// should match the regular expression &quot;^[a-z][a-zA-Z0-9]*$&quot;
record MyRecord3(double my_number) {} // violation, the record component name
// should match the regular expression &quot;^[a-z][a-zA-Z0-9]*$&quot;
class Example1 {
record Rec1(int other) {}

record Rec2(String Values) {} // violation, Name must match '^[a-z][a-zA-Z0-9]*$'

record Rec3(double myNumber) {}
}
</source>
<p>
An example of how to configure the check for names that are only letters in lowercase:
Expand All @@ -67,10 +69,13 @@ record MyRecord3(double my_number) {} // violation, the record component name
</source>
<p id="Example2-code">Example:</p>
<source>
record MyRecord1(String value, int other) {} // OK
record MyRecord2(String... strings) {} // OK
record MyRecord3(double myNumber) {} // violation, the record component name
// should match the regular expression &quot;^[a-z]+$&quot;
class Example2 {
record Rec1(int other) {}

record Rec2(String Values) {} // violation, Name must match '^[a-z]+$'

record Rec3(double myNumber) {} // violation, Name must match '^[a-z]+$'
}
</source>
</subsection>

Expand Down
8 changes: 4 additions & 4 deletions src/xdocs/checks/naming/recordcomponentname.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/Example1.txt"/>
value="resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/Example1.java"/>
<param name="type" value="config"/>
</macro>
<p id="Example1-code">Example:</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/Example1.txt"/>
value="resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/Example1.java"/>
<param name="type" value="code"/>
</macro>
<p>
Expand All @@ -42,13 +42,13 @@
<p id="Example2-config">Configuration:</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/Example2.txt"/>
value="resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/Example2.java"/>
<param name="type" value="config"/>
</macro>
<p id="Example2-code">Example:</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/Example2.txt"/>
value="resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname/Example2.java"/>
<param name="type" value="code"/>
</macro>
</subsection>
Expand Down

0 comments on commit 943163d

Please sign in to comment.