forked from phoedos/pmd
Add failing test case for #2438
This commit is contained in:
parent
390db62cba
commit
2f54938793
@ -0,0 +1,42 @@
|
||||
package net.sourceforge.pmd.lang.cpp.cpd;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.cpd.CPDConfiguration;
|
||||
import net.sourceforge.pmd.cpd.CpdAnalysis;
|
||||
import net.sourceforge.pmd.cpd.Match;
|
||||
import net.sourceforge.pmd.internal.util.IOUtil;
|
||||
import net.sourceforge.pmd.lang.cpp.CppLanguageModule;
|
||||
|
||||
public class CppCpdTest {
|
||||
private Path testdir;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
String path = IOUtil.normalizePath("src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata");
|
||||
testdir = Paths.get(path);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIssue2438() throws Exception {
|
||||
CPDConfiguration configuration = new CPDConfiguration();
|
||||
configuration.setMinimumTileSize(50);
|
||||
configuration.setOnlyRecognizeLanguage(CppLanguageModule.getInstance());
|
||||
try (CpdAnalysis cpd = CpdAnalysis.create(configuration)) {
|
||||
cpd.files().addFile(testdir.resolve("ctype.c"));
|
||||
|
||||
cpd.performAnalysis(matches -> {
|
||||
// There should only be 1 duplication, and it should be maximal
|
||||
assertEquals(1, matches.getMatches().size());
|
||||
assertEquals(128, matches.getMatches().get(0).getTokenCount());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
29
pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ctype.c
vendored
Normal file
29
pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ctype.c
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
#include <ctype.h>
|
||||
|
||||
char _ctmp;
|
||||
unsigned char _ctype[] = {0x00, /* EOF */
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
|
||||
_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
|
||||
_S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
|
||||
_P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
|
||||
_D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
|
||||
_D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
|
||||
_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
|
||||
_U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
|
||||
_U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
|
||||
_U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
|
||||
_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
|
||||
_L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
|
||||
_L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
|
||||
_L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 160-175 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 176-191 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 192-207 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 208-223 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 224-239 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* 240-255 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user