diff --git a/pmd-groovy/pom.xml b/pmd-groovy/pom.xml
index cbc765b1b4..b5de7e75de 100644
--- a/pmd-groovy/pom.xml
+++ b/pmd-groovy/pom.xml
@@ -45,10 +45,20 @@
junit
test
+
+ org.junit.vintage
+ junit-vintage-engine
+ test
+
net.sourceforge.pmd
pmd-test
test
+
+ net.sourceforge.pmd
+ pmd-lang-test
+ test
+
diff --git a/pmd-groovy/src/main/java/net/sourceforge/pmd/cpd/GroovyTokenizer.java b/pmd-groovy/src/main/java/net/sourceforge/pmd/cpd/GroovyTokenizer.java
index 860e8b0b0f..f0cb3e1ef9 100644
--- a/pmd-groovy/src/main/java/net/sourceforge/pmd/cpd/GroovyTokenizer.java
+++ b/pmd-groovy/src/main/java/net/sourceforge/pmd/cpd/GroovyTokenizer.java
@@ -36,7 +36,11 @@ public class GroovyTokenizer implements Tokenizer {
int lastCol;
if (token instanceof SourceInfo) {
- lastCol = ((SourceInfo) token).getColumnLast();
+ lastCol = ((SourceInfo) token).getColumnLast() - 1;
+ if (lastCol == 0) {
+ // newline
+ lastCol = token.getColumn() + 1;
+ }
} else {
// fallback
lastCol = token.getColumn() + tokenText.length();
diff --git a/pmd-groovy/src/test/java/net/sourceforge/pmd/cpd/GroovyTokenizerTest.java b/pmd-groovy/src/test/java/net/sourceforge/pmd/cpd/GroovyTokenizerTest.java
index 200fecfb80..ba6e2d1d65 100644
--- a/pmd-groovy/src/test/java/net/sourceforge/pmd/cpd/GroovyTokenizerTest.java
+++ b/pmd-groovy/src/test/java/net/sourceforge/pmd/cpd/GroovyTokenizerTest.java
@@ -4,34 +4,30 @@
package net.sourceforge.pmd.cpd;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
+import java.util.Properties;
-import org.apache.commons.io.IOUtils;
-import org.junit.Before;
import org.junit.Test;
-import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
+import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
-public class GroovyTokenizerTest extends AbstractTokenizerTest {
+public class GroovyTokenizerTest extends CpdTextComparisonTest {
- private static final String FILENAME = "BTree.groovy";
-
- @Before
- @Override
- public void buildTokenizer() throws IOException {
- this.tokenizer = new GroovyTokenizer();
- this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
+ public GroovyTokenizerTest() {
+ super(".groovy");
}
@Override
- public String getSampleCode() throws IOException {
- return IOUtils.toString(GroovyTokenizer.class.getResourceAsStream(FILENAME), StandardCharsets.UTF_8);
+ protected String getResourcePrefix() {
+ return "../lang/groovy/cpd/testdata";
+ }
+
+ @Override
+ public Tokenizer newTokenizer(Properties properties) {
+ return new GroovyTokenizer();
}
@Test
- public void tokenizeTest() throws IOException {
- this.expectedTokenCount = 369;
- super.tokenizeTest();
+ public void testSample() {
+ doTest("sample");
}
}
diff --git a/pmd-groovy/src/test/resources/net/sourceforge/pmd/cpd/BTree.groovy b/pmd-groovy/src/test/resources/net/sourceforge/pmd/lang/groovy/cpd/testdata/sample.groovy
similarity index 100%
rename from pmd-groovy/src/test/resources/net/sourceforge/pmd/cpd/BTree.groovy
rename to pmd-groovy/src/test/resources/net/sourceforge/pmd/lang/groovy/cpd/testdata/sample.groovy
diff --git a/pmd-groovy/src/test/resources/net/sourceforge/pmd/lang/groovy/cpd/testdata/sample.txt b/pmd-groovy/src/test/resources/net/sourceforge/pmd/lang/groovy/cpd/testdata/sample.txt
new file mode 100644
index 0000000000..40134ae20e
--- /dev/null
+++ b/pmd-groovy/src/test/resources/net/sourceforge/pmd/lang/groovy/cpd/testdata/sample.txt
@@ -0,0 +1,421 @@
+ [Image] or [Truncated image[ Bcol Ecol
+L1
+ [] 49 50
+L2
+ [package] 1 7
+ [net] 9 11
+ [.] 12 12
+ [sourceforge] 13 23
+ [.] 24 24
+ [pmd] 25 27
+ [.] 28 28
+ [cpd] 29 31
+ [] 32 33
+L7
+ [class] 1 5
+ [BTree] 7 11
+ [<] 12 12
+ [K] 13 13
+ [,] 14 14
+ [V] 16 16
+ [>] 17 17
+ [extends] 19 25
+ [BTreeNode] 27 35
+ [<] 36 36
+ [K] 37 37
+ [>] 38 38
+ [{] 40 40
+ [] 41 1
+L9
+ [static] 2 7
+ [def] 9 11
+ [instance] 13 20
+ [] 21 1
+L11
+ [BlockManager] 2 13
+ [<] 14 14
+ [V] 15 15
+ [>] 16 16
+ [manager] 18 24
+ [] 25 1
+L13
+ [BTree] 2 6
+ [(] 7 7
+ [)] 8 8
+ [{] 10 10
+ [] 11 2
+L14
+ [instance] 3 10
+ [=] 12 12
+ [this] 14 17
+ [] 18 2
+L15
+ [getLeaf] 3 9
+ [(] 10 10
+ [this] 11 14
+ [)] 15 15
+ [] 16 2
+L16
+ [manager] 3 9
+ [=] 11 11
+ [new] 13 15
+ [BlockManager] 17 28
+ [<] 29 29
+ [>] 30 30
+ [(] 31 31
+ [)] 32 32
+ [] 33 1
+L17
+ [}] 2 2
+ [] 3 1
+L19
+ [def] 2 4
+ [split] 6 10
+ [(] 11 11
+ [)] 12 12
+ [{] 14 14
+ [] 15 2
+L22
+ [BTreeNode] 3 11
+ [<] 12 12
+ [K] 13 13
+ [>] 14 14
+ [left] 16 19
+ [=] 21 21
+ [clone] 23 27
+ [(] 28 28
+ [)] 29 29
+ [] 30 2
+L23
+ [BTreeNode] 3 11
+ [<] 12 12
+ [K] 13 13
+ [>] 14 14
+ [right] 16 20
+ [=] 22 22
+ [clone] 24 28
+ [(] 29 29
+ [)] 30 30
+ [] 31 2
+L26
+ [\[] 3 3
+ [left] 4 7
+ [,] 8 8
+ [right] 10 14
+ [\]] 15 15
+ [*.] 16 17
+ [parent] 18 23
+ [=] 25 25
+ [this] 27 30
+ [] 31 2
+L29
+ [left] 3 6
+ [.] 7 7
+ [pointers] 8 15
+ [=] 17 17
+ [pointers] 19 26
+ [.] 27 27
+ [subList] 28 34
+ [(] 35 35
+ [0] 36 36
+ [,] 37 37
+ [count] 39 43
+ [/] 45 45
+ [2] 47 47
+ [as] 49 50
+ [int] 52 54
+ [)] 55 55
+ [as] 57 58
+ [LinkedList] 60 69
+ [] 70 2
+L30
+ [right] 3 7
+ [.] 8 8
+ [pointers] 9 16
+ [=] 18 18
+ [pointers] 20 27
+ [.] 28 28
+ [subList] 29 35
+ [(] 36 36
+ [count] 37 41
+ [/] 43 43
+ [2] 45 45
+ [as] 47 48
+ [int] 50 52
+ [,] 53 53
+ [count] 55 59
+ [)] 60 60
+ [as] 62 63
+ [LinkedList] 65 74
+ [] 75 2
+L33
+ [if] 3 4
+ [(] 6 6
+ [left] 7 10
+ [.] 11 11
+ [internalNode] 12 23
+ [)] 24 24
+ [{] 26 26
+ [] 27 3
+L34
+ [left] 4 7
+ [.] 8 8
+ [pointers] 9 16
+ [\[] 17 17
+ [-] 18 18
+ [1] 19 19
+ [\]] 20 20
+ [.] 21 21
+ [key] 22 24
+ [=] 26 26
+ [null] 28 31
+ [] 32 2
+L35
+ [}] 3 3
+ [] 4 2
+L36
+ [else] 3 6
+ [{] 8 8
+ [] 9 3
+L37
+ [left] 4 7
+ [.] 8 8
+ [rightSibling] 9 20
+ [=] 22 22
+ [right] 24 28
+ [] 29 3
+L38
+ [right] 4 8
+ [.] 9 9
+ [leftSibling] 10 20
+ [=] 22 22
+ [left] 24 27
+ [] 28 2
+L39
+ [}] 3 3
+ [] 4 2
+L42
+ [if] 3 4
+ [(] 6 6
+ [!] 7 7
+ [bucketNode] 8 17
+ [)] 18 18
+ [{] 20 20
+ [] 21 3
+L43
+ [\[] 4 4
+ [left] 5 8
+ [,] 9 9
+ [right] 11 15
+ [\]] 16 16
+ [.] 17 17
+ [each] 18 21
+ [{] 23 23
+ [node] 25 28
+ [->] 30 31
+ [node] 33 36
+ [.] 37 37
+ [pointers] 38 45
+ [*.] 46 47
+ [value] 48 52
+ [*.] 53 54
+ [parent] 55 60
+ [=] 62 62
+ [node] 64 67
+ [}] 69 69
+ [] 70 2
+L44
+ [}] 3 3
+ [] 4 2
+L47
+ [pointers] 3 10
+ [.] 11 11
+ [clear] 12 16
+ [(] 17 17
+ [)] 18 18
+ [] 19 2
+L48
+ [addDirect] 3 11
+ [(] 12 12
+ [new] 13 15
+ [BTreeEntry] 17 26
+ [(] 27 27
+ [right] 28 32
+ [.] 33 33
+ [smallestKey] 34 44
+ [,] 45 45
+ [left] 47 50
+ [)] 51 51
+ [)] 52 52
+ [] 53 2
+L49
+ [addDirect] 3 11
+ [(] 12 12
+ [new] 13 15
+ [BTreeEntry] 17 26
+ [(] 27 27
+ [null] 28 31
+ [,] 32 32
+ [right] 34 38
+ [)] 39 39
+ [)] 40 40
+ [] 41 2
+L52
+ [if] 3 4
+ [(] 6 6
+ [leafNode] 7 14
+ [)] 15 15
+ [{] 17 17
+ [] 18 3
+L53
+ [getPointer] 4 13
+ [(] 14 14
+ [this] 15 18
+ [)] 19 19
+ [] 20 2
+L54
+ [}] 3 3
+ [] 4 1
+L55
+ [}] 2 2
+ [] 3 1
+L57
+ [def] 2 4
+ [add] 6 8
+ [(] 9 9
+ [K] 10 10
+ [key] 12 14
+ [,] 15 15
+ [V] 17 17
+ [value] 19 23
+ [)] 24 24
+ [{] 26 26
+ [] 27 2
+L59
+ [if] 3 4
+ [(] 6 6
+ [count] 7 11
+ [>] 13 13
+ [0] 15 15
+ [&&] 17 18
+ [search] 20 25
+ [(] 26 26
+ [key] 27 29
+ [)] 30 30
+ [)] 31 31
+ [{] 33 33
+ [] 34 3
+L60
+ [throw] 4 8
+ [new] 10 12
+ [IllegalArgumentException] 14 37
+ [(] 38 38
+ [] 39 40
+ [key] 41 43
+ [ is already in the tree] 44 67
+ [)] 68 68
+ [] 69 2
+L61
+ [}] 3 3
+ [] 4 2
+L63
+ [BlockManager] 3 14
+ [.] 15 15
+ [Block] 16 20
+ [.] 21 21
+ [BlockElement] 22 33
+ [<] 34 34
+ [V] 35 35
+ [>] 36 36
+ [element] 38 44
+ [=] 46 46
+ [manager] 48 54
+ [.] 55 55
+ [element] 56 62
+ [] 63 2
+L64
+ [element] 3 9
+ [.] 10 10
+ [value] 11 15
+ [=] 17 17
+ [value] 19 23
+ [] 24 2
+L66
+ [super] 3 7
+ [.] 8 8
+ [add] 9 11
+ [key] 13 15
+ [,] 16 16
+ [element] 18 24
+ [] 25 1
+L67
+ [}] 2 2
+ [] 3 1
+L69
+ [def] 2 4
+ [delete] 6 11
+ [(] 12 12
+ [K] 13 13
+ [key] 15 17
+ [)] 18 18
+ [{] 20 20
+ [] 21 2
+L71
+ [if] 3 4
+ [(] 6 6
+ [count] 7 11
+ [>] 13 13
+ [0] 15 15
+ [&&] 17 18
+ [!] 20 20
+ [search] 21 26
+ [(] 27 27
+ [key] 28 30
+ [)] 31 31
+ [)] 32 32
+ [{] 34 34
+ [] 35 3
+L72
+ [throw] 4 8
+ [new] 10 12
+ [IllegalArgumentException] 14 37
+ [(] 38 38
+ [] 39 40
+ [key] 41 43
+ [ is not in the tree] 44 63
+ [)] 64 64
+ [] 65 2
+L73
+ [}] 3 3
+ [] 4 2
+L75
+ [super] 3 7
+ [.] 8 8
+ [delete] 9 14
+ [key] 16 18
+ [] 19 2
+L77
+ [if] 3 4
+ [(] 6 6
+ [count] 7 11
+ [==] 13 14
+ [0] 16 16
+ [)] 17 17
+ [{] 19 19
+ [] 20 3
+L78
+ [getLeaf] 4 10
+ [(] 11 11
+ [this] 12 15
+ [)] 16 16
+ [] 17 2
+L79
+ [}] 3 3
+ [] 4 1
+L80
+ [}] 2 2
+ [] 3 4
+L81
+ [}] 1 1
+ [] 2 3
+EOF