Convert Go tests

This commit is contained in:
Clément Fournier 2020-06-13 22:00:58 +02:00
parent 4b3d58d4c9
commit da371182aa
11 changed files with 4197 additions and 85 deletions

View File

@ -43,10 +43,20 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-lang-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,29 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
public class EdgeCasesTokenizerTest {
private String getSampleCode(final String filename) throws IOException {
return IOUtils.toString(GoTokenizer.class.getResourceAsStream(filename), StandardCharsets.UTF_8);
}
@Test
public void testEscapedBackSlash() throws IOException {
// See https://github.com/pmd/pmd/issues/1751
final String filename = "issue1751.go";
final GoTokenizer tokenizer = new GoTokenizer();
final SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader(getSampleCode(filename), filename));
final Tokens tokens = new Tokens();
tokenizer.tokenize(sourceCode, tokens); // it should simply not fail
}
}

View File

@ -1,36 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
public class GoCPDTokenizerTest extends AbstractTokenizerTest {
private static final String FILENAME = "hello.go";
@Before
@Override
public void buildTokenizer() throws IOException {
this.tokenizer = new GoTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
}
@Override
public String getSampleCode() throws IOException {
return IOUtils.toString(GoTokenizer.class.getResourceAsStream(FILENAME));
}
@Test
public void tokenizeTest() throws IOException {
this.expectedTokenCount = 23;
super.tokenizeTest();
}
}

View File

@ -4,33 +4,40 @@
package net.sourceforge.pmd.cpd;
import java.io.IOException;
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 GoTokenizerTest extends AbstractTokenizerTest {
public class GoTokenizerTest extends CpdTextComparisonTest {
private static final String FILENAME = "btrfs.go";
@Before
@Override
public void buildTokenizer() throws IOException {
this.tokenizer = new GoTokenizer();
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME));
public GoTokenizerTest() {
super(".go");
}
@Override
public String getSampleCode() throws IOException {
return IOUtils.toString(GoTokenizer.class.getResourceAsStream(FILENAME));
public Tokenizer newTokenizer(Properties properties) {
return new GoTokenizer();
}
@Override
protected String getResourcePrefix() {
return "../lang/go/cpd/testdata";
}
@Test
public void tokenizeTest() throws IOException {
this.expectedTokenCount = 3517;
super.tokenizeTest();
public void simpleTest() {
doTest("hello");
}
@Test
public void bigFileTest() {
doTest("btrfs");
}
@Test
public void testIssue1751() {
doTest("issue-1751");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
[Image] or [Truncated image[ Bcol Ecol
L21
[import] 1 6
[(] 8 8
L22
["fmt"] 2 6
L24
["github.com/golang/example/stringu[ 2 39
L25
[)] 1 1
L27
[func] 1 4
[main] 6 9
[(] 10 10
[)] 11 11
[{] 13 13
L28
[fmt] 2 4
[.] 5 5
[Println] 6 12
[(] 13 13
[stringutil] 14 23
[.] 24 24
[Reverse] 25 31
[(] 32 32
["!selpmaxe oG ,olleH"] 33 53
[)] 54 54
[)] 55 55
L29
[}] 1 1
EOF

View File

@ -0,0 +1,84 @@
[Image] or [Truncated image[ Bcol Ecol
L1
[func] 1 4
[test] 6 9
[(] 10 10
[in] 11 12
[*] 14 14
[Value] 15 19
[,] 20 20
[param] 22 26
[*] 28 28
[Value] 29 33
[)] 34 34
[(] 36 36
[*] 37 37
[Value] 38 42
[,] 43 43
[*] 45 45
[Error] 46 50
[)] 51 51
[{] 53 53
L2
[output] 2 7
[:=] 9 10
[strings] 12 18
[.] 19 19
[Replace] 20 26
[(] 27 27
[in] 28 29
[.] 30 30
[String] 31 36
[(] 37 37
[)] 38 38
[,] 39 39
["\\\\"] 41 44
[,] 45 45
["\\\\\\\\"] 47 52
[,] 53 53
[-] 55 55
[1] 56 56
[)] 57 57
L3
[output] 2 7
[=] 9 9
[strings] 11 17
[.] 18 18
[Replace] 19 25
[(] 26 26
[output] 27 32
[,] 33 33
["\\""] 35 38
[,] 39 39
["\\\\\\""] 41 46
[,] 47 47
[-] 49 49
[1] 50 50
[)] 51 51
L4
[output] 2 7
[=] 9 9
[strings] 11 17
[.] 18 18
[Replace] 19 25
[(] 26 26
[output] 27 32
[,] 33 33
["'"] 35 37
[,] 38 38
["\\\\'"] 40 44
[,] 45 45
[-] 47 47
[1] 48 48
[)] 49 49
L5
[return] 2 7
[AsValue] 9 15
[(] 16 16
[output] 17 22
[)] 23 23
[,] 24 24
[nil] 26 28
L6
[}] 1 1
EOF

View File

@ -8,7 +8,6 @@ import static org.junit.Assert.assertEquals;
import java.util.Properties;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
@ -20,7 +19,7 @@ public class JavaTokenizerTest extends CpdTextComparisonTest {
}
@Override
public Tokenizer newTokenizer(@NotNull Properties properties) {
public Tokenizer newTokenizer(Properties properties) {
JavaTokenizer javaTokenizer = new JavaTokenizer();
javaTokenizer.setProperties(properties);
return javaTokenizer;
@ -112,7 +111,6 @@ public class JavaTokenizerTest extends CpdTextComparisonTest {
}
@NotNull
@Override
public Properties defaultProperties() {
return properties(false, false, false);