Skip to content

Commit

Permalink
Issue checkstyle#14937: Migrated section 2.3.1 Whitespace Characters …
Browse files Browse the repository at this point in the history
…to follow Chapter Wise Testing
  • Loading branch information
Zopsss authored and rdiachenko committed Jun 20, 2024
1 parent c01a15b commit 11dcd18
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
4 changes: 3 additions & 1 deletion config/checkstyle-resources-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
files="src[\\/]test[\\/]resources[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]checks[\\/]indentation[\\/]indentation[\\/]Input.*\.java"/>
<suppress checks="FileTabCharacter"
files="src[\\/]test[\\/]resources[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]filters[\\/]suppresswithplaintextcommentfilter[\\/]Input.*"/>
<suppress checks="FileTabCharacter"
files="[\\/]it[\\/]resources[\\/]com[\\/]google[\\/]checkstyle[\\/]test[\\/]chapter2filebasic[\\/]rule231filetab[\\/]InputWhitespaceCharacters\.java"/>
<suppress checks="FileTabCharacter"
files="[\\/]InputRegressionJavaClass1\.java"/>
<suppress checks="FileTabCharacter"
Expand Down Expand Up @@ -803,7 +805,7 @@
<suppress checks="FileLength"
files="[\\/]test[\\/]resources-noncompilable[\\/]com[\\/]puppycrawl[\\/]tools[\\/]checkstyle[\\/]javaparser[\\/]InputJavaParserFullJavaIdentifierSupport\.java"/>
<suppress checks="FileLength"
files="[\\/]it[\\/]resources[\\/]com[\\/]google[\\/]checkstyle[\\/]test[\\/]chapter2filebasic[\\/]rule231filetab[\\/]InputFileTabCharacter\.java"/>
files="[\\/]it[\\/]resources[\\/]com[\\/]google[\\/]checkstyle[\\/]test[\\/]chapter2filebasic[\\/]rule231filetab[\\/]InputWhitespaceCharacters\.java"/>
<suppress checks="FileLength"
files="[\\/]it[\\/]resources[\\/]com[\\/]google[\\/]checkstyle[\\/]test[\\/]chapter2filebasic[\\/]rule232specialescape[\\/]InputIllegalTokenText\.java"/>
<suppress checks="FileLength"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
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.FileTabCharacterCheck;

public class FileTabCharacterTest extends AbstractGoogleModuleTestSupport {
public class WhitespaceCharactersTest extends AbstractGoogleModuleTestSupport {

@Override
protected String getPackageLocation() {
Expand All @@ -34,23 +32,12 @@ protected String getPackageLocation() {

@Test
public void testFileTab() throws Exception {
final String[] expected = {
"8:25: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
"51:5: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
"121:35: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
"122:64: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
"130:9: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
"131:10: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
"132:1: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
"133:3: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
"134:3: " + getCheckMessage(FileTabCharacterCheck.class, "containsTab"),
final String filePath = getPath("InputWhitespaceCharacters.java");
final String[] modules = {
"FileTabCharacter",
};

final Configuration checkConfig = getModuleConfig("FileTabCharacter");
final String filePath = getPath("InputFileTabCharacter.java");

final Integer[] warnList = getLinesWithWarn(filePath);
verify(checkConfig, filePath, expected, warnList);
verifyWithGoogleConfigParser(modules, filePath);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.google.checkstyle.test.chapter2filebasic.rule231filetab;

import java.io.*;

final class InputFileTabCharacter
final class InputWhitespaceCharacters
{
// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warn
// Contains a tab -> <- // violation 'Line contains a tab character.'
// Contains trailing whitespace ->

/** Invalid format **/
Expand Down Expand Up @@ -48,7 +46,7 @@ final class InputFileTabCharacter
* @throws java.lang.Exception abc
**/
int test1(int badFormat1,int badFormat2,
final int badFormat3) //warn
final int badFormat3) // violation 'Line contains a tab character.'
throws java.lang.Exception
{
return 0;
Expand Down Expand Up @@ -78,7 +76,7 @@ private void longMethod()
}

/** constructor that is 10 lines long **/
private InputFileTabCharacter()
private InputWhitespaceCharacters()
{
// a line
// a line
Expand Down Expand Up @@ -118,20 +116,22 @@ void ALL_UPPERCASE_METHOD()
private static final int BAD__NAME = 3;

// A very, very long line that is OK because it matches the regexp "^.*is OK.*regexp.*$"
// long line that has a tab -> <- and would be OK if tab counted as 1 char //warn
// tabs that count as one char because of their position -> <- -> <- //warn
// long line that has a tab -> <- and would be OK if tab counted as 1 char
// violation above 'Line contains a tab character.'
// tabs that count as one char because of their position -> <- -> <-
// violation above 'Line contains a tab character.'

/** some lines to test the column after tabs */
void violateColumnAfterTabs()
{
// with tab-width 8 all statements below start at the same column,
// with different combinations of ' ' and '\t' before the statement
int tab0 =1;
int tab1 =1; //warn
int tab2 =1; //warn
int tab3 =1; //warn
int tab4 =1; //warn
int tab5 =1; //warn
int tab1 =1; // violation 'Line contains a tab character.'
int tab2 =1; // violation 'Line contains a tab character.'
int tab3 =1; // violation 'Line contains a tab character.'
int tab4 =1; // violation 'Line contains a tab character.'
int tab5 =1; // violation 'Line contains a tab character.'
}

// MEMME:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ public class XdocsPagesTest {
// until https://github.com/checkstyle/checkstyle/issues/14937
private static final Set<String> PER_MODULE_TESTS_RULES_LIST = Set.of(
"2.1 File name",
"2.3.1 Whitespace characters",
"2.3.2 Special escape sequences",
"2.3.3 Non-ASCII characters",
"3 Source file structure",
Expand Down
6 changes: 3 additions & 3 deletions src/xdocs/google_style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@
</a>
</td>
<td>
<a href="styleguides/google-java-style-20180523/javaguide.html#s2.3.1-whitespace-characters">
2.3.1 Whitespace characters</a>
<a href="styleguides/google-java-style-20220203/javaguide.html#s2.3.1-whitespace-characters">
2.3.1 Whitespace Characters</a>
</td>
<td>
<span class="wrapper inline">
Expand All @@ -224,7 +224,7 @@
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+FileTabCharacter">
config</a>
<br />
<a href="https://github.com/checkstyle/checkstyle/blob/master/src/it/java/com/google/checkstyle/test/chapter2filebasic/rule231filetab/FileTabCharacterTest.java">
<a href="https://github.com/checkstyle/checkstyle/blob/master/src/it/java/com/google/checkstyle/test/chapter2filebasic/rule231filetab/WhitespaceCharactersTest.java">
test</a>
</td>
</tr>
Expand Down

0 comments on commit 11dcd18

Please sign in to comment.