diff options
Diffstat (limited to 'src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/needbraces/InputNeedBraces.java')
-rw-r--r-- | src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/needbraces/InputNeedBraces.java | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/needbraces/InputNeedBraces.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/needbraces/InputNeedBraces.java new file mode 100644 index 000000000..5a04483f3 --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/blocks/needbraces/InputNeedBraces.java @@ -0,0 +1,119 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.checks.blocks.needbraces; + +/** + * Test case for correct use of braces. + * @author Oliver Burn + **/ +class InputNeedBraces +{ + /** @return helper func **/ + boolean condition() + { + return false; + } + + /** Test do/while loops **/ + void testDoWhile() + { + // Valid + do { + testDoWhile(); + } + while (condition()); + + // Invalid + do testDoWhile(); while (condition()); + } + + /** Test while loops **/ + void testWhile() + { + // Valid + while (condition()) { + testWhile(); + } + + // Invalid + while(condition()); + while (condition()) + testWhile(); + while (condition()) + if (condition()) + testWhile(); + } + + /** Test for loops **/ + void testFor() + { + // Valid + for (int i = 1; i < 5; i++) { + testFor(); + } + + // Invalid + for(int i = 1;i < 5;i++); + for (int i = 1; i < 5; i++) + testFor(); + for (int i = 1; i < 5; + i++) + if (i > 2) + testFor(); + } + + /** Test if constructs **/ + public void testIf() + { + // Valid + if (condition()) { + testIf(); + } + else if (condition()) { + testIf(); + } + else { + testIf(); + } + + // Invalid + if (condition()); + if (condition()) + testIf(); + if (condition()) + testIf(); + else + testIf(); + if (condition()) + testIf(); + else { + testIf(); + } + if (condition()) { + testIf(); + } + else + testIf(); + if (condition()) + if (condition()) + testIf(); + } + + void whitespaceAfterSemi() + { + //reject + int i = 1;int j = 2; + + //accept + for (;;) { + } + } + + /** Empty constructor block. **/ + public InputNeedBraces() {} + + /** Empty method block. **/ + public void emptyImplementation() {} +} |