diff options
author | Subbu Dantu <subbudantu@Subbus-MacBook-Pro.local> | 2017-04-04 11:07:21 +0530 |
---|---|---|
committer | Roman Ivanov <romani@users.noreply.github.com> | 2017-04-06 05:54:48 -0700 |
commit | 3435698b28a678413a3c75cf360e2b77c6a4ccb3 (patch) | |
tree | 91ed80fba03e21436258b5bbec8142f365fb1196 /src/test | |
parent | 66e3774f258652aab21a4d4346b3ba818c574c78 (diff) | |
download | checkstyle-3435698b28a678413a3c75cf360e2b77c6a4ccb3.tar.gz |
Issue #3930: Modified NoWhitespaceBeforeCheckTest.java and moved its input files to a nowhitespacebefore subdirectory
Diffstat (limited to 'src/test')
4 files changed, 871 insertions, 4 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/NoWhitespaceBeforeCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/NoWhitespaceBeforeCheckTest.java index b972637da..cffe88892 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/NoWhitespaceBeforeCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/NoWhitespaceBeforeCheckTest.java @@ -42,7 +42,7 @@ public class NoWhitespaceBeforeCheckTest @Override protected String getPath(String filename) throws IOException { return super.getPath("checks" + File.separator - + "whitespace" + File.separator + filename); + + "whitespace" + File.separator + "nowhitespacebefore" + File.separator + filename); } @Test @@ -61,7 +61,7 @@ public class NoWhitespaceBeforeCheckTest "284:1: " + getCheckMessage(MSG_KEY, ";"), "287:61: " + getCheckMessage(MSG_KEY, "..."), }; - verify(checkConfig, getPath("InputWhitespace.java"), expected); + verify(checkConfig, getPath("InputNoWhitespaceBeforeDefault.java"), expected); } @Test @@ -75,7 +75,7 @@ public class NoWhitespaceBeforeCheckTest "136:10: " + getCheckMessage(MSG_KEY, "."), "264:1: " + getCheckMessage(MSG_KEY, "."), }; - verify(checkConfig, getPath("InputWhitespace.java"), expected); + verify(checkConfig, getPath("InputNoWhitespaceBeforeDot.java"), expected); } @Test @@ -87,6 +87,6 @@ public class NoWhitespaceBeforeCheckTest "129:17: " + getCheckMessage(MSG_KEY, "."), "136:10: " + getCheckMessage(MSG_KEY, "."), }; - verify(checkConfig, getPath("InputWhitespace.java"), expected); + verify(checkConfig, getPath("InputNoWhitespaceBeforeDotAllowLineBreaks.java"), expected); } } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDefault.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDefault.java new file mode 100644 index 000000000..4b12e66a3 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDefault.java @@ -0,0 +1,289 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com . puppycrawl + .tools. + checkstyle.checks.whitespace.nowhitespacebefore; + +/** + * Class for testing whitespace issues. + * error missing author tag + **/ +class InputNoWhitespaceBeforeDefault +{ + /** ignore assignment **/ + private int mVar1=1; + /** ignore assignment **/ + private int mVar2 =1; + /** Should be ok **/ + private int mVar3 = 1; + + /** method **/ + void method1() + { + final int a = 1; + int b= 1; // Ignore 1 + b=1; // Ignore 1 + b+=1; // Ignore 1 + b -=- 1 + (+ b); // Ignore 2 + b = b ++ + b --; // Ignore 1 + b = ++ b - -- b; // Ignore 1 + } + + /** method **/ + void method2() + { + synchronized(this) { + } + try{ + } + catch(RuntimeException e){ + } + } + + /** + skip blank lines between comment and code, + should be ok + **/ + + + private int mVar4 = 1; + + + /** test WS after void return */ + private void fastExit() + { + boolean complicatedStuffNeeded = true; + if( !complicatedStuffNeeded ) + { + return; // should not complain about missing WS after return + } + else + { + // do complicated stuff + } + } + + + /** test WS after non void return + @return 2 + */ + private int nonVoid() + { + if ( true ) + { + return(2); // should complain about missing WS after return + } + else + { + return 2; // this is ok + } + } + + /** test casts **/ + private void testCasts() + { + Object o = (Object) new Object(); // ok + o = (Object)o; // error + o = ( Object ) o; // ok + o = (Object) + o; // ok + } + + /** test questions **/ + private void testQuestions() + { + boolean b = (1 == 2)?true:false; + b = (1==2) ? false : true; + } + + /** star test **/ + private void starTest() + { + int x = 2 *3* 4; + } + + /** boolean test **/ + private void boolTest() + { + boolean a = true; + boolean x = ! a; + int z = ~1 + ~ 2; + } + + /** division test **/ + private void divTest() + { + int a = 4 % 2; + int b = 4% 2; + int c = 4 %2; + int d = 4%2; + int e = 4 / 2; + int f = 4/ 2; + int g = 4 /2; + int h = 4/2; + } + + /** @return dot test **/ + private java .lang. String dotTest() + { + Object o = new java.lang.Object(); + o. + toString(); + o + .toString(); + o . toString(); + return o.toString(); + } + + /** assert statement test */ + public void assertTest() + { + // OK + assert true; + + // OK + assert true : "Whups"; + + // evil colons, should be OK + assert "OK".equals(null) ? false : true : "Whups"; + + // missing WS around assert + assert(true); + + // missing WS around colon + assert true:"Whups"; + } + + /** another check */ + void donBradman(Runnable aRun) + { + donBradman(new Runnable() { + public void run() { + } + }); + + final Runnable r = new Runnable() { + public void run() { + } + }; + } + + /** rfe 521323, detect whitespace before ';' */ + void rfe521323() + { + doStuff() ; + // ^ whitespace + for (int i = 0 ; i < 5; i++) { + // ^ whitespace + } + } + + + /** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */ + private int i ; + // ^ whitespace + private int i1, i2, i3 ; + // ^ whitespace + private int i4, i5, i6; + + /** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */ + void bug806243() + { + Object o = new InputNoWhitespaceBeforeDefault() { + private int j ; + // ^ whitespace + }; + } + + void doStuff() { + } +} + +/** + * Bug 806242 (NoWhitespaceBeforeCheck error with an interface). + * @author o_sukhodolsky + * @version 1.0 + */ +interface IFoo_NoWhitespaceBeforeDefault +{ + void foo() ; + // ^ whitespace +} + +/** + * Avoid Whitespace errors in for loop. + * @author lkuehne + * @version 1.0 + */ +class SpecialCasesInForLoop_NoWhitespaceBeforeDefault +{ + void forIterator() + { + // avoid conflict between WhiteSpaceAfter ';' and ParenPad(nospace) + for (int i = 0; i++ < 5;) { + // ^ no whitespace + } + + // bug 895072 + // avoid confilct between ParenPad(space) and NoWhiteSpace before ';' + int i = 0; + for ( ; i < 5; i++ ) { + // ^ whitespace + } + for (int anInt : getSomeInts()) { + //Should be ignored + } + } + + int[] getSomeInts() { + int i = (int) ( 2 / 3 ); + return null; + } + + public void myMethod() { + new Thread() { + public void run() { + } + }.start(); + } + + public void foo(java.util.List<? extends String[]> bar, Comparable<? super Object[]> baz) { } + + public void mySuperMethod() { + Runnable[] runs = new Runnable[] {new Runnable() { + public void run() { + } + }, + new Runnable() { + public void run() { + } + }}; + runs[0] +. + run() +; + } + + public void testNullSemi() { + return ; + } + + public void register(Object obj) { } + + public void doSomething(String args[]) { + register(boolean[].class); + register( args ); + } + + public void parentheses() { + testNullSemi +( +) +; + } + + public static void testNoWhitespaceBeforeEllipses(String ... args) { + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDot.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDot.java new file mode 100644 index 000000000..81a84c464 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDot.java @@ -0,0 +1,289 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com . puppycrawl + .tools. + checkstyle.checks.whitespace.nowhitespacebefore; + +/** + * Class for testing whitespace issues. + * error missing author tag + **/ +class InputNoWhitespaceBeforeDot +{ + /** ignore assignment **/ + private int mVar1=1; + /** ignore assignment **/ + private int mVar2 =1; + /** Should be ok **/ + private int mVar3 = 1; + + /** method **/ + void method1() + { + final int a = 1; + int b= 1; // Ignore 1 + b=1; // Ignore 1 + b+=1; // Ignore 1 + b -=- 1 + (+ b); // Ignore 2 + b = b ++ + b --; // Ignore 1 + b = ++ b - -- b; // Ignore 1 + } + + /** method **/ + void method2() + { + synchronized(this) { + } + try{ + } + catch(RuntimeException e){ + } + } + + /** + skip blank lines between comment and code, + should be ok + **/ + + + private int mVar4 = 1; + + + /** test WS after void return */ + private void fastExit() + { + boolean complicatedStuffNeeded = true; + if( !complicatedStuffNeeded ) + { + return; // should not complain about missing WS after return + } + else + { + // do complicated stuff + } + } + + + /** test WS after non void return + @return 2 + */ + private int nonVoid() + { + if ( true ) + { + return(2); // should complain about missing WS after return + } + else + { + return 2; // this is ok + } + } + + /** test casts **/ + private void testCasts() + { + Object o = (Object) new Object(); // ok + o = (Object)o; // error + o = ( Object ) o; // ok + o = (Object) + o; // ok + } + + /** test questions **/ + private void testQuestions() + { + boolean b = (1 == 2)?true:false; + b = (1==2) ? false : true; + } + + /** star test **/ + private void starTest() + { + int x = 2 *3* 4; + } + + /** boolean test **/ + private void boolTest() + { + boolean a = true; + boolean x = ! a; + int z = ~1 + ~ 2; + } + + /** division test **/ + private void divTest() + { + int a = 4 % 2; + int b = 4% 2; + int c = 4 %2; + int d = 4%2; + int e = 4 / 2; + int f = 4/ 2; + int g = 4 /2; + int h = 4/2; + } + + /** @return dot test **/ + private java .lang. String dotTest() + { + Object o = new java.lang.Object(); + o. + toString(); + o + .toString(); + o . toString(); + return o.toString(); + } + + /** assert statement test */ + public void assertTest() + { + // OK + assert true; + + // OK + assert true : "Whups"; + + // evil colons, should be OK + assert "OK".equals(null) ? false : true : "Whups"; + + // missing WS around assert + assert(true); + + // missing WS around colon + assert true:"Whups"; + } + + /** another check */ + void donBradman(Runnable aRun) + { + donBradman(new Runnable() { + public void run() { + } + }); + + final Runnable r = new Runnable() { + public void run() { + } + }; + } + + /** rfe 521323, detect whitespace before ';' */ + void rfe521323() + { + doStuff() ; + // ^ whitespace + for (int i = 0 ; i < 5; i++) { + // ^ whitespace + } + } + + + /** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */ + private int i ; + // ^ whitespace + private int i1, i2, i3 ; + // ^ whitespace + private int i4, i5, i6; + + /** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */ + void bug806243() + { + Object o = new InputNoWhitespaceBeforeDot() { + private int j ; + // ^ whitespace + }; + } + + void doStuff() { + } +} + +/** + * Bug 806242 (NoWhitespaceBeforeCheck error with an interface). + * @author o_sukhodolsky + * @version 1.0 + */ +interface IFoo_NoWhitespaceBeforeDot +{ + void foo() ; + // ^ whitespace +} + +/** + * Avoid Whitespace errors in for loop. + * @author lkuehne + * @version 1.0 + */ +class SpecialCasesInForLoop_NoWhitespaceBeforeDot +{ + void forIterator() + { + // avoid conflict between WhiteSpaceAfter ';' and ParenPad(nospace) + for (int i = 0; i++ < 5;) { + // ^ no whitespace + } + + // bug 895072 + // avoid confilct between ParenPad(space) and NoWhiteSpace before ';' + int i = 0; + for ( ; i < 5; i++ ) { + // ^ whitespace + } + for (int anInt : getSomeInts()) { + //Should be ignored + } + } + + int[] getSomeInts() { + int i = (int) ( 2 / 3 ); + return null; + } + + public void myMethod() { + new Thread() { + public void run() { + } + }.start(); + } + + public void foo(java.util.List<? extends String[]> bar, Comparable<? super Object[]> baz) { } + + public void mySuperMethod() { + Runnable[] runs = new Runnable[] {new Runnable() { + public void run() { + } + }, + new Runnable() { + public void run() { + } + }}; + runs[0] +. + run() +; + } + + public void testNullSemi() { + return ; + } + + public void register(Object obj) { } + + public void doSomething(String args[]) { + register(boolean[].class); + register( args ); + } + + public void parentheses() { + testNullSemi +( +) +; + } + + public static void testNoWhitespaceBeforeEllipses(String ... args) { + } +} diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDotAllowLineBreaks.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDotAllowLineBreaks.java new file mode 100644 index 000000000..88cb4556d --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/nowhitespacebefore/InputNoWhitespaceBeforeDotAllowLineBreaks.java @@ -0,0 +1,289 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com . puppycrawl + .tools. + checkstyle.checks.whitespace.nowhitespacebefore; + +/** + * Class for testing whitespace issues. + * error missing author tag + **/ +class InputNoWhitespaceBeforeDotAllowLineBreaks +{ + /** ignore assignment **/ + private int mVar1=1; + /** ignore assignment **/ + private int mVar2 =1; + /** Should be ok **/ + private int mVar3 = 1; + + /** method **/ + void method1() + { + final int a = 1; + int b= 1; // Ignore 1 + b=1; // Ignore 1 + b+=1; // Ignore 1 + b -=- 1 + (+ b); // Ignore 2 + b = b ++ + b --; // Ignore 1 + b = ++ b - -- b; // Ignore 1 + } + + /** method **/ + void method2() + { + synchronized(this) { + } + try{ + } + catch(RuntimeException e){ + } + } + + /** + skip blank lines between comment and code, + should be ok + **/ + + + private int mVar4 = 1; + + + /** test WS after void return */ + private void fastExit() + { + boolean complicatedStuffNeeded = true; + if( !complicatedStuffNeeded ) + { + return; // should not complain about missing WS after return + } + else + { + // do complicated stuff + } + } + + + /** test WS after non void return + @return 2 + */ + private int nonVoid() + { + if ( true ) + { + return(2); // should complain about missing WS after return + } + else + { + return 2; // this is ok + } + } + + /** test casts **/ + private void testCasts() + { + Object o = (Object) new Object(); // ok + o = (Object)o; // error + o = ( Object ) o; // ok + o = (Object) + o; // ok + } + + /** test questions **/ + private void testQuestions() + { + boolean b = (1 == 2)?true:false; + b = (1==2) ? false : true; + } + + /** star test **/ + private void starTest() + { + int x = 2 *3* 4; + } + + /** boolean test **/ + private void boolTest() + { + boolean a = true; + boolean x = ! a; + int z = ~1 + ~ 2; + } + + /** division test **/ + private void divTest() + { + int a = 4 % 2; + int b = 4% 2; + int c = 4 %2; + int d = 4%2; + int e = 4 / 2; + int f = 4/ 2; + int g = 4 /2; + int h = 4/2; + } + + /** @return dot test **/ + private java .lang. String dotTest() + { + Object o = new java.lang.Object(); + o. + toString(); + o + .toString(); + o . toString(); + return o.toString(); + } + + /** assert statement test */ + public void assertTest() + { + // OK + assert true; + + // OK + assert true : "Whups"; + + // evil colons, should be OK + assert "OK".equals(null) ? false : true : "Whups"; + + // missing WS around assert + assert(true); + + // missing WS around colon + assert true:"Whups"; + } + + /** another check */ + void donBradman(Runnable aRun) + { + donBradman(new Runnable() { + public void run() { + } + }); + + final Runnable r = new Runnable() { + public void run() { + } + }; + } + + /** rfe 521323, detect whitespace before ';' */ + void rfe521323() + { + doStuff() ; + // ^ whitespace + for (int i = 0 ; i < 5; i++) { + // ^ whitespace + } + } + + + /** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */ + private int i ; + // ^ whitespace + private int i1, i2, i3 ; + // ^ whitespace + private int i4, i5, i6; + + /** bug 806243 (NoWhitespaceBeforeCheck error for anonymous inner class) */ + void bug806243() + { + Object o = new InputNoWhitespaceBeforeDotAllowLineBreaks() { + private int j ; + // ^ whitespace + }; + } + + void doStuff() { + } +} + +/** + * Bug 806242 (NoWhitespaceBeforeCheck error with an interface). + * @author o_sukhodolsky + * @version 1.0 + */ +interface IFoo_NoWhitespaceBeforeDotAllowLineBreaks +{ + void foo() ; + // ^ whitespace +} + +/** + * Avoid Whitespace errors in for loop. + * @author lkuehne + * @version 1.0 + */ +class SpecialCasesInForLoop_NoWhitespaceBeforeDotAllowLineBreaks +{ + void forIterator() + { + // avoid conflict between WhiteSpaceAfter ';' and ParenPad(nospace) + for (int i = 0; i++ < 5;) { + // ^ no whitespace + } + + // bug 895072 + // avoid confilct between ParenPad(space) and NoWhiteSpace before ';' + int i = 0; + for ( ; i < 5; i++ ) { + // ^ whitespace + } + for (int anInt : getSomeInts()) { + //Should be ignored + } + } + + int[] getSomeInts() { + int i = (int) ( 2 / 3 ); + return null; + } + + public void myMethod() { + new Thread() { + public void run() { + } + }.start(); + } + + public void foo(java.util.List<? extends String[]> bar, Comparable<? super Object[]> baz) { } + + public void mySuperMethod() { + Runnable[] runs = new Runnable[] {new Runnable() { + public void run() { + } + }, + new Runnable() { + public void run() { + } + }}; + runs[0] +. + run() +; + } + + public void testNullSemi() { + return ; + } + + public void register(Object obj) { } + + public void doSomething(String args[]) { + register(boolean[].class); + register( args ); + } + + public void parentheses() { + testNullSemi +( +) +; + } + + public static void testNoWhitespaceBeforeEllipses(String ... args) { + } +} |