diff --git a/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdTest.java b/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdTest.java index 635613908e..7285c35e2d 100644 --- a/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdTest.java +++ b/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdTest.java @@ -39,4 +39,21 @@ public class CppCpdTest { }); } } + + @Test + void testMultipleExactMatches() throws Exception { + CPDConfiguration configuration = new CPDConfiguration(); + configuration.setMinimumTileSize(40); + configuration.setOnlyRecognizeLanguage(CppLanguageModule.getInstance()); + try (CpdAnalysis cpd = CpdAnalysis.create(configuration)) { + cpd.files().addFile(testdir.resolve("multipleExactMatches.c")); + + cpd.performAnalysis(matches -> { + // There should only be 1 duplication, and it should be maximal + assertEquals(1, matches.getMatches().size()); + assertEquals(3, matches.getMatches().get(0).getMarkCount()); + assertEquals(41, matches.getMatches().get(0).getTokenCount()); + }); + } + } } diff --git a/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/multipleExactMatches.c b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/multipleExactMatches.c new file mode 100644 index 0000000000..853655957e --- /dev/null +++ b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/multipleExactMatches.c @@ -0,0 +1,12 @@ + +unsigned char _ctype[] = { 3, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +4 +}; \ No newline at end of file