Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #92: Add Non-Treewalker filter tests to cover more cases(FileTabCharacter) #95

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,114 @@ public void testFileTabCharacter() throws Exception {
testByConfig(zeroContextConfigPathTwo, inputFile, expectedTwo);
}

@Test
public void testFileTabCharacterMoveCodeInSameFileWithoutChanges() throws Exception {
final String inputFile =
"strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges/Test.java";

final String defaultContextConfigPathOne =
"strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges/"
+ "newline/defaultContextConfig.xml";
final String zeroContextConfigPathOne =
"strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges/"
+ "newline/zeroContextConfig.xml";
final String[] expectedOne = {
"19:25: Line contains a tab character.",
};
testByConfig(defaultContextConfigPathOne, inputFile, expectedOne);
testByConfig(zeroContextConfigPathOne, inputFile, expectedOne);

final String defaultContextConfigPathTwo =
"strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges"
+ "/patchedline/defaultContextConfig.xml";
final String zeroContextConfigPathTwo =
"strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges/"
+ "patchedline/zeroContextConfig.xml";
final String[] expectedTwo = {
"19:25: Line contains a tab character.",
};
testByConfig(defaultContextConfigPathTwo, inputFile, expectedTwo);
testByConfig(zeroContextConfigPathTwo, inputFile, expectedTwo);
}

@Test
public void testFileTabCharacterMoveCodeInSameFileWithMinorChanges() throws Exception {
final String inputFile =
"strategy/FileTabCharacter/MoveCodeInSameFileWithMinorChanges/Test.java";

final String defaultContextConfigPathOne =
"strategy/FileTabCharacter/"
+ "MoveCodeInSameFileWithMinorChanges/newline/defaultContextConfig.xml";
final String zeroContextConfigPathOne =
"strategy/FileTabCharacter/"
+ "MoveCodeInSameFileWithMinorChanges/newline/zeroContextConfig.xml";
final String[] expectedOne = {
"19:25: Line contains a tab character.",
};
testByConfig(defaultContextConfigPathOne, inputFile, expectedOne);
testByConfig(zeroContextConfigPathOne, inputFile, expectedOne);

final String defaultContextConfigPathTwo =
"strategy/FileTabCharacter/MoveCodeInSameFileWithMinorChanges"
+ "/patchedline/defaultContextConfig.xml";
final String zeroContextConfigPathTwo =
"strategy/FileTabCharacter/MoveCodeInSameFileWithMinorChanges"
+ "/patchedline/zeroContextConfig.xml";
final String[] expectedTwo = {
"19:25: Line contains a tab character.",
};
testByConfig(defaultContextConfigPathTwo, inputFile, expectedTwo);
testByConfig(zeroContextConfigPathTwo, inputFile, expectedTwo);
}

@Test
public void testFileTabCharacterSingleChangedLine() throws Exception {
final String inputFile = "strategy/FileTabCharacter/SingleChangedLine/Test.java";

final String defaultContextConfigPathOne =
"strategy/FileTabCharacter/SingleChangedLine/newline/defaultContextConfig.xml";
final String zeroContextConfigPathOne =
"strategy/FileTabCharacter/SingleChangedLine/newline/zeroContextConfig.xml";
final String[] expectedOne = {};
testByConfig(defaultContextConfigPathOne, inputFile, expectedOne);
testByConfig(zeroContextConfigPathOne, inputFile, expectedOne);

final String defaultContextConfigPathTwo =
"strategy/FileTabCharacter/SingleChangedLine/patchedline/defaultContextConfig.xml";
final String zeroContextConfigPathTwo =
"strategy/FileTabCharacter/SingleChangedLine/patchedline/zeroContextConfig.xml";
final String[] expectedTwo = {
"19:25: Line contains a tab character.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why this is a violation, moved to #103

};
testByConfig(defaultContextConfigPathTwo, inputFile, expectedTwo);
testByConfig(zeroContextConfigPathTwo, inputFile, expectedTwo);
}

@Test
public void testFileTabCharacterSingleNewLine() throws Exception {
final String inputFile = "strategy/FileTabCharacter/SingleNewLine/Test.java";

final String defaultContextConfigPathOne =
"strategy/FileTabCharacter/SingleNewLine/newline/defaultContextConfig.xml";
final String zeroContextConfigPathOne =
"strategy/FileTabCharacter/SingleNewLine/newline/zeroContextConfig.xml";
final String[] expectedOne = {
"20:25: Line contains a tab character.",
};
testByConfig(defaultContextConfigPathOne, inputFile, expectedOne);
testByConfig(zeroContextConfigPathOne, inputFile, expectedOne);

final String defaultContextConfigPathTwo =
"strategy/FileTabCharacter/SingleNewLine/patchedline/defaultContextConfig.xml";
final String zeroContextConfigPathTwo =
"strategy/FileTabCharacter/SingleNewLine/patchedline/zeroContextConfig.xml";
final String[] expectedTwo = {
"20:25: Line contains a tab character.",
};
testByConfig(defaultContextConfigPathTwo, inputFile, expectedTwo);
testByConfig(zeroContextConfigPathTwo, inputFile, expectedTwo);
}

@Test
@Ignore("until https://github.com/checkstyle/patch-filters/issues/88 "
+ "when testByConfig can process a directory contains more than one file")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Checker.FileTabCharacter;

public class Test {
// Long line ----------------------------------------------------------------













// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warns // violation newline/patchedline
// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warns


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/Test.java b/Test.java
index aea01e2..5982414 100644
--- a/Test.java
+++ b/Test.java
@@ -2,7 +2,6 @@ package Checker.FileTabCharacter;

public class Test {
// Long line ----------------------------------------------------------------
- // Contains a tab -> <- //warn



@@ -17,6 +16,7 @@ public class Test {


// Long line ----------------------------------------------------------------
+ // Contains a tab -> <- //warns
// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warns

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/MoveCodeInSameFileWithMinorChanges/defaultContext.patch" />
<property name="strategy" value="newline" />
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/MoveCodeInSameFileWithMinorChanges/zeroContext.patch" />
<property name="strategy" value="newline" />
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/MoveCodeInSameFileWithMinorChanges/defaultContext.patch" />
<property name="strategy" value="patchedline" />
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/MoveCodeInSameFileWithMinorChanges/zeroContext.patch" />
<property name="strategy" value="patchedline" />
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
diff --git a/Test.java b/Test.java
index aea01e2..5982414 100644
--- a/Test.java
+++ b/Test.java
@@ -5 +4,0 @@ public class Test {
- // Contains a tab -> <- //warn
@@ -19,0 +19 @@ public class Test {
+ // Contains a tab -> <- //warns
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Checker.FileTabCharacter;

public class Test {
// Long line ----------------------------------------------------------------













// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warn // violation newline/patchedline
// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warns


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/Test.java b/Test.java
index aea01e2..5982414 100644
--- a/Test.java
+++ b/Test.java
@@ -2,7 +2,6 @@ package Checker.FileTabCharacter;

public class Test {
// Long line ----------------------------------------------------------------
- // Contains a tab -> <- //warn



@@ -17,6 +16,7 @@ public class Test {


// Long line ----------------------------------------------------------------
+ // Contains a tab -> <- //warn
// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warns

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges/defaultContext.patch" />
<property name="strategy" value="newline" />
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges/zeroContext.patch" />
<property name="strategy" value="newline" />
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges/defaultContext.patch" />
<property name="strategy" value="patchedline" />
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/MoveCodeInSameFileWithoutChanges/zeroContext.patch" />
<property name="strategy" value="patchedline" />
</module>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
diff --git a/Test.java b/Test.java
index aea01e2..5982414 100644
--- a/Test.java
+++ b/Test.java
@@ -5 +4,0 @@ public class Test {
- // Contains a tab -> <- //warn
@@ -19,0 +19 @@ public class Test {
+ // Contains a tab -> <- //warn
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Checker.FileTabCharacter;

public class Test {
// Long line ----------------------------------------------------------------













// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warn // violation patchedline
// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warns


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/Test.java b/Test.java
index 404df53..5982414 100644
--- a/Test.java
+++ b/Test.java
@@ -16,7 +16,7 @@ public class Test {


// Long line ----------------------------------------------------------------
- // Contains a tab -> <- //warns
+ // Contains a tab -> <- //warn
// Long line ----------------------------------------------------------------
// Contains a tab -> <- //warns

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="com.puppycrawl.tools.checkstyle.filters.SuppressionPatchFilter">
<property name="file" value="src/test/resources/com/puppycrawl/tools/checkstyle/filters/strategy/FileTabCharacter/SingleChangedLine/defaultContext.patch" />
<property name="strategy" value="newline" />
</module>
</module>