Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #5624: Google Style Should Enforce Spaces after Commas
- Loading branch information
1 parent
f2e45f8
commit deea241
Showing
7 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...e/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAfterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// checkstyle: Checks Java source code for adherence to a set of rules. | ||
// Copyright (C) 2001-2020 the original author or authors. | ||
// | ||
// This library is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU Lesser General Public | ||
// License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// | ||
// This library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
// Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public | ||
// License along with this library; if not, write to the Free Software | ||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport; | ||
import com.puppycrawl.tools.checkstyle.api.Configuration; | ||
import com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck; | ||
|
||
public class WhitespaceAfterTest extends AbstractGoogleModuleTestSupport { | ||
|
||
@Override | ||
protected String getPackageLocation() { | ||
return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; | ||
} | ||
|
||
@Test | ||
public void testWhitespaceAfterBad() throws Exception { | ||
final Class<WhitespaceAfterCheck> clazz = WhitespaceAfterCheck.class; | ||
final String message = "ws.notFollowed"; | ||
|
||
final String[] expected = { | ||
"4:29: " + getCheckMessage(clazz, message, ","), | ||
"5:9: " + getCheckMessage(clazz, message, "for"), | ||
"5:20: " + getCheckMessage(clazz, message, ","), | ||
"5:24: " + getCheckMessage(clazz, message, ";"), | ||
"5:28: " + getCheckMessage(clazz, message, ";"), | ||
"5:32: " + getCheckMessage(clazz, message, ","), | ||
"6:9: " + getCheckMessage(clazz, message, "while"), | ||
"7:20: " + getCheckMessage(clazz, message, ","), | ||
"9:9: " + getCheckMessage(clazz, message, "do"), | ||
"11:10: " + getCheckMessage(clazz, message, "while"), | ||
"13:35: " + getCheckMessage(clazz, message, ","), | ||
"14:9: " + getCheckMessage(clazz, message, "if"), | ||
"14:18: " + getCheckMessage(clazz, message, "typecast"), | ||
"17:9: " + getCheckMessage(clazz, message, "else"), | ||
}; | ||
final Configuration checkConfig = getModuleConfig("WhitespaceAfter"); | ||
final String filePath = getPath("InputWhitespaceAfterBad.java"); | ||
|
||
final Integer[] warnList = getLinesWithWarn(filePath); | ||
verify(checkConfig, filePath, expected, warnList); | ||
} | ||
|
||
@Test | ||
public void testWhitespaceAfterGood() throws Exception { | ||
final String[] expected = { | ||
}; | ||
final Configuration checkConfig = getModuleConfig("WhitespaceAfter"); | ||
final String filePath = getPath("InputWhitespaceAfterGood.java"); | ||
|
||
final Integer[] warnList = getLinesWithWarn(filePath); | ||
verify(checkConfig, filePath, expected, warnList); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...eckstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; | ||
|
||
public class InputWhitespaceAfterBad { | ||
public void check1(int x,int y){ //warn | ||
for(int a=1,b=2;a<5;a++,b--); // warn | ||
while(x==0){ // warn | ||
int a=0,b=1; // warn | ||
} | ||
do{ // warn | ||
System.out.println("Testing"); | ||
}while(x==0||y==2); // warn | ||
} | ||
public void check2(final int a,final int b){ // warn | ||
if((float)a==0.0){ // warn | ||
System.out.println("true"); | ||
} | ||
else{ //warn | ||
System.out.println("false"); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ckstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; | ||
|
||
public class InputWhitespaceAfterGood { | ||
public void check1(int x, int y){ | ||
for (int a=1, b=2; a<5; a++, b--); | ||
while (x==0){ | ||
int a=0, b=1; | ||
} | ||
do { | ||
System.out.println("Testing"); | ||
}while (x==0||y==2); | ||
} | ||
public void check2(final int a, final int b){ | ||
if ((float) a==0.0){ | ||
System.out.println("true"); | ||
} | ||
else { | ||
System.out.println("false"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters