103 lines
2.0 KiB
Java
103 lines
2.0 KiB
Java
////////////////////////////////////////////////////////////////////////////////
|
|
// Test case file for checkstyle.
|
|
// Created: 2001
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
package com.puppycrawl.tools.checkstyle;
|
|
|
|
/**
|
|
* Test case for correct use of braces.
|
|
* @author Oliver Burn
|
|
**/
|
|
class InputBraces
|
|
{
|
|
/** @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();
|
|
}
|
|
}
|