Convert lua tests
This commit is contained in:
@@ -49,10 +49,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>
|
||||
|
@@ -4,53 +4,34 @@
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import net.sourceforge.pmd.testframework.AbstractTokenizerTest;
|
||||
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class LuaTokenizerTest extends AbstractTokenizerTest {
|
||||
|
||||
private final String filename;
|
||||
private final int nExpectedTokens;
|
||||
|
||||
public LuaTokenizerTest(String filename, int nExpectedTokens) {
|
||||
this.filename = filename;
|
||||
this.nExpectedTokens = nExpectedTokens;
|
||||
}
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(
|
||||
new Object[] { "factorial.lua", 44 },
|
||||
new Object[] { "helloworld.lua", 5 }
|
||||
);
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void buildTokenizer() throws IOException {
|
||||
this.tokenizer = new LuaTokenizer();
|
||||
this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), this.filename));
|
||||
public class LuaTokenizerTest extends CpdTextComparisonTest {
|
||||
public LuaTokenizerTest() {
|
||||
super(".lua");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSampleCode() throws IOException {
|
||||
return IOUtils.toString(LuaTokenizer.class.getResourceAsStream(this.filename), StandardCharsets.UTF_8);
|
||||
protected String getResourcePrefix() {
|
||||
return "../lang/lua/cpd/testdata";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tokenizer newTokenizer(Properties properties) {
|
||||
return new LuaTokenizer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenizeTest() throws IOException {
|
||||
this.expectedTokenCount = nExpectedTokens;
|
||||
super.tokenizeTest();
|
||||
public void testSimple() {
|
||||
doTest("helloworld");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactorial() {
|
||||
doTest("factorial");
|
||||
}
|
||||
}
|
||||
|
55
pmd-lua/src/test/resources/net/sourceforge/pmd/lang/lua/cpd/testdata/factorial.txt
vendored
Normal file
55
pmd-lua/src/test/resources/net/sourceforge/pmd/lang/lua/cpd/testdata/factorial.txt
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L2
|
||||
[function] 5 12
|
||||
[fact] 14 17
|
||||
[(] 19 19
|
||||
[n] 20 20
|
||||
[)] 21 21
|
||||
L3
|
||||
[if] 7 8
|
||||
[n] 10 10
|
||||
[==] 12 13
|
||||
[0] 15 15
|
||||
[then] 17 20
|
||||
L4
|
||||
[return] 9 14
|
||||
[1] 16 16
|
||||
L5
|
||||
[else] 7 10
|
||||
L6
|
||||
[return] 9 14
|
||||
[n] 16 16
|
||||
[*] 18 18
|
||||
[fact] 20 23
|
||||
[(] 24 24
|
||||
[n] 25 25
|
||||
[-] 26 26
|
||||
[1] 27 27
|
||||
[)] 28 28
|
||||
L7
|
||||
[end] 7 9
|
||||
L8
|
||||
[end] 5 7
|
||||
L10
|
||||
[print] 5 9
|
||||
[(] 10 10
|
||||
["enter a number:"] 11 27
|
||||
[)] 28 28
|
||||
L11
|
||||
[a] 5 5
|
||||
[=] 7 7
|
||||
[io] 9 10
|
||||
[.] 11 11
|
||||
[read] 12 15
|
||||
[(] 16 16
|
||||
["*number"] 17 25
|
||||
[)] 26 26
|
||||
L12
|
||||
[print] 5 9
|
||||
[(] 10 10
|
||||
[fact] 11 14
|
||||
[(] 15 15
|
||||
[a] 16 16
|
||||
[)] 17 17
|
||||
[)] 18 18
|
||||
EOF
|
7
pmd-lua/src/test/resources/net/sourceforge/pmd/lang/lua/cpd/testdata/helloworld.txt
vendored
Normal file
7
pmd-lua/src/test/resources/net/sourceforge/pmd/lang/lua/cpd/testdata/helloworld.txt
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L1
|
||||
[print] 2 6
|
||||
[(] 7 7
|
||||
["Hello World"] 8 20
|
||||
[)] 21 21
|
||||
EOF
|
Reference in New Issue
Block a user