Skip to content

Commit

Permalink
supplemental: test cases added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin222004 authored and romani committed Mar 14, 2023
1 parent 93ab0e7 commit 6b77f06
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck;
import com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck;
import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
import com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck;
import com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck;
import com.puppycrawl.tools.checkstyle.checks.whitespace.TypecastParenPadCheck;
import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
Expand Down Expand Up @@ -479,4 +480,31 @@ public void testWithAndWithoutCheckSuffixDifferentCases() throws Exception {
expected);
}

@Test
public void testAliasList() throws Exception {
final String[] expected = {
"16:17: " + getCheckMessage(ParameterNumberCheck.class,
ParameterNumberCheck.MSG_KEY, 7, 8),
"28:17: " + getCheckMessage(ParameterNumberCheck.class,
ParameterNumberCheck.MSG_KEY, 7, 8),
};
verifyWithInlineConfigParser(
getPath("InputSuppressWarningsHolderAlias.java"),
expected);
}

@Test
public void testAliasList2() throws Exception {
final String pattern = "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$";
final String[] expected = {
"16:29: " + getCheckMessage(ConstantNameCheck.class,
AbstractNameCheck.MSG_INVALID_PATTERN, "a", pattern),
"19:30: " + getCheckMessage(ConstantNameCheck.class,
AbstractNameCheck.MSG_INVALID_PATTERN, "b", pattern),
};

verifyWithInlineConfigParser(
getPath("InputSuppressWarningsHolderAlias2.java"),
expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder
aliasList = com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck=paramnum
com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilter
com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck
max = (default)7
*/

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

public class InputSuppressWarningsHolderAlias {

public void needsLotsOfParameters0(int a, // violation 'More than 7 parameters (found 8)'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("paramnum")
public void needsLotsOfParameters(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("ParamnumUnknown")
public void needsLotsOfParameters2(int a, // violation 'More than 7 parameters (found 8)'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("PAramnuM")
public void needsLotsOfParameters3(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("PARAMNUM")
public void needsLotsOfParameters4(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("paRAMnum")
public void needsLotsOfParameters5(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("pAramNUm")
public void needsLotsOfParameters6(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder
aliasList = com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck=constant
com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilter
com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck
format = (default)^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$
*/

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

public class InputSuppressWarningsHolderAlias2 {
private static final int a = 0; // violation 'Name 'a' must match pattern'

@SuppressWarnings("Notconstant")
private static final int b = 0; // violation 'Name 'b' must match pattern'

@SuppressWarnings("CONSTANT") // filtered violation 'invalid pattern'
private static final int c = 0;

@SuppressWarnings("CONstant") // filtered violation 'invalid pattern'
private static final int d = 0;

@SuppressWarnings("consTant") // filtered violation 'invalid pattern'
private static final int e = 0;

@SuppressWarnings("cOnStAnT") // filtered violation 'invalid pattern'
private static final int f = 0;

@SuppressWarnings("cOnStAnT") // filtered violation 'invalid pattern'
private static final int g = 0;
}

0 comments on commit 6b77f06

Please sign in to comment.