Skip to content

Commit

Permalink
Issue #4585: Moved resources for RegexpSingleline
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Kytsmen authored and romani committed Jul 20, 2017
1 parent aba766e commit 4f270c9
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public void setUp() {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "regexp" + File.separator + filename);
+ "regexp" + File.separator
+ "regexpsingleline" + File.separator
+ filename);
}

@Test
Expand All @@ -53,7 +55,7 @@ public void testIt() throws Exception {
final String[] expected = {
"69: " + getCheckMessage(MSG_REGEXP_EXCEEDED, illegal),
};
verify(checkConfig, getPath("InputSemantic.java"), expected);
verify(checkConfig, getPath("InputRegexpSinglelineSemantic.java"), expected);
}

@Test
Expand All @@ -66,7 +68,7 @@ public void testMessageProperty()
final String[] expected = {
"69: " + message,
};
verify(checkConfig, getPath("InputSemantic.java"), expected);
verify(checkConfig, getPath("InputRegexpSinglelineSemantic.java"), expected);
}

@Test
Expand All @@ -79,7 +81,7 @@ public void testIgnoreCaseTrue() throws Exception {
final String[] expected = {
"69: " + getCheckMessage(MSG_REGEXP_EXCEEDED, illegal),
};
verify(checkConfig, getPath("InputSemantic.java"), expected);
verify(checkConfig, getPath("InputRegexpSinglelineSemantic.java"), expected);
}

@Test
Expand All @@ -88,7 +90,7 @@ public void testIgnoreCaseFalse() throws Exception {
checkConfig.addAttribute("format", illegal);
checkConfig.addAttribute("ignoreCase", "false");
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputSemantic.java"), expected);
verify(checkConfig, getPath("InputRegexpSinglelineSemantic.java"), expected);
}

@Test
Expand All @@ -100,7 +102,7 @@ public void testMinimum() throws Exception {
"0: " + getCheckMessage(MSG_REGEXP_MINIMUM, "500", illegal),
};

verify(checkConfig, getPath("InputSemantic.java"), expected);
verify(checkConfig, getPath("InputRegexpSinglelineSemantic.java"), expected);
}

@Test
Expand All @@ -113,6 +115,6 @@ public void testSetMessage() throws Exception {
"0: someMessage",
};

verify(checkConfig, getPath("InputSemantic.java"), expected);
verify(checkConfig, getPath("InputRegexpSinglelineSemantic.java"), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
////////////////////////////////////////////////////////////////////////////////
// Test case file for checkstyle.
// Created: 2001
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.regexp.regexpsingleline;

import java.awt.*;
import java.io.ByteArrayOutputStream;
import java.io.File;

/**
* Test case for detecting simple semantic errors.
* @author Lars Kühne
**/
class InputRegexpSinglelineSemantic
{
/* Boolean instantiation in a static initializer */
static {
Boolean x = new Boolean(true);
}

/* Boolean instantiation in a non-static initializer */
{
Boolean x = new Boolean(true);
Boolean[] y = new Boolean[]{Boolean.TRUE, Boolean.FALSE};
}

/** fully qualified Boolean instantiation in a method. **/
Boolean getBoolean()
{
return new Boolean(true);
}

void otherInstantiations()
{
// instantiation of classes in the same package
Object o1 = new InputBraces();
Object o2 = new InputModifier();
// classes in another package with .* import
ByteArrayOutputStream s = new ByteArrayOutputStream();
File f = new File("/tmp");
// classes in another package with explicit import
Dimension dim = new Dimension();
Color col = new Color(0, 0, 0);
}

void exHandlerTest()
{
try {
; // do stuff and don't handle exceptions in some cases
}
catch (IllegalStateException emptyCatchIsAlwaysAnError) {
}
catch (NullPointerException ex) {
// can never happen, but only commentig this is currently an error
// Possible future enhancement: allowEmptyCatch="commented"
}
catch (ArrayIndexOutOfBoundsException ex) {
;
// can never happen, semicolon makes checkstyle happy
// this is a workaround for above problem
}
catch (NegativeArraySizeException ex) {
{
}
// can never happen, empty compound statement is another workaround
}
catch (UnsupportedOperationException handledException) {
System.out.println(handledException.getMessage());
}
catch (SecurityException ex) { /* hello */ }
catch (StringIndexOutOfBoundsException ex) {}
catch (IllegalArgumentException ex) { }

try {
}
finally {
}
try {
// something
}
finally {
// something
}
try {
; // something
}
finally {
; // statement
}
}

/** test **/
private static final long IGNORE = 666l + 666L;





















public class EqualsVsHashCode1
{
public boolean equals(int a) // wrong arg type, don't flag
{
return a == 1;
}
}

public class EqualsVsHashCode2
{
public boolean equals(String a) // flag
{
return true;
}
}

public class EqualsVsHashCode3
{
public boolean equals(Object a) // don't flag
{
return true;
}

public int hashCode()
{
return 0;
}
}

public class EqualsVsHashCode4
{
// in anon inner class
ByteArrayOutputStream bos1 = new ByteArrayOutputStream()
{
public boolean equals(Object a) // don't flag
{
return true;
}

public int hashCode()
{
return 0;
}
};

ByteArrayOutputStream bos2 = new ByteArrayOutputStream()
{
public boolean equals(Object a) // flag
{
return true;
}
};
}

public void triggerEmptyBlockWithoutBlock()
{
// an if statement without a block to increase test coverage
if (true)
return;
}

// empty instance initializer
{
}

public class EqualsVsHashCode5
{
public <A> boolean equals(int a) // wrong arg type, don't flag even with generics
{
return a == 1;
}
}

public class EqualsVsHashCode6
{
public <A> boolean equals(Comparable<A> a) // flag, weven with generics
{
return true;
}
}

private class InputBraces {

}

private class InputModifier {

}

synchronized void foo() {
synchronized (this) {} // not OK
synchronized (Class.class) { // OK
synchronized (new Object()) {
// not OK if checking statements
}
}
}


static {

int a = 0;}

static {

}
}

0 comments on commit 4f270c9

Please sign in to comment.