Fix JS tests
Rewrite assertions for better error messages The difference is 32 tokens instead of 30; this is because previously, AnyTokenizer tokenized `window.alert` as a single token. Now it tokenizes it a `window`, `.`, `alert`.
This commit is contained in:
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AnyTokenizerForTypescriptTest extends CpdTextComparisonTest {
|
||||
|
||||
public AnyTokenizerForTypescriptTest() {
|
||||
super(".ts");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getResourcePrefix() {
|
||||
return "testdata/ts";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tokenizer newTokenizer(Properties properties) {
|
||||
return new AnyTokenizer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFile1() {
|
||||
doTest("SampleTypeScript");
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,10 @@
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import org.junit.Assert;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.emptyString;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.cli.BaseCPDCLITest;
|
||||
@ -16,8 +19,7 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
|
||||
"src/test/resources/net/sourceforge/pmd/cpd/ts/File1.ts",
|
||||
"src/test/resources/net/sourceforge/pmd/cpd/ts/File2.ts");
|
||||
|
||||
String out = getOutput();
|
||||
Assert.assertTrue(out.contains("Found a 9 line (30 tokens) duplication in the following files"));
|
||||
assertThat(getOutput(), containsString("Found a 9 line (32 tokens) duplication in the following files"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -25,7 +27,6 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
|
||||
runCPD("--minimum-tokens", "5", "--language", "js", "--files",
|
||||
"src/test/resources/net/sourceforge/pmd/cpd/ts/");
|
||||
|
||||
String out = getOutput();
|
||||
Assert.assertTrue(out.trim().isEmpty());
|
||||
assertThat(getOutput().trim(), emptyString());
|
||||
}
|
||||
}
|
||||
|
9
pmd-javascript/src/test/resources/net/sourceforge/pmd/cpd/testdata/ts/SampleTypeScript.ts
vendored
Normal file
9
pmd-javascript/src/test/resources/net/sourceforge/pmd/cpd/testdata/ts/SampleTypeScript.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
(function(){
|
||||
|
||||
var x = 1;
|
||||
var y = 2;
|
||||
var z = 3;
|
||||
window.alert('Test');
|
||||
|
||||
|
||||
})();
|
40
pmd-javascript/src/test/resources/net/sourceforge/pmd/cpd/testdata/ts/SampleTypeScript.txt
vendored
Normal file
40
pmd-javascript/src/test/resources/net/sourceforge/pmd/cpd/testdata/ts/SampleTypeScript.txt
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L1
|
||||
[(] 1 1
|
||||
[function] 2 9
|
||||
[(] 10 10
|
||||
[)] 11 11
|
||||
[{] 12 12
|
||||
L3
|
||||
[var] 1 3
|
||||
[x] 5 5
|
||||
[=] 7 7
|
||||
[1] 9 9
|
||||
[;] 10 10
|
||||
L4
|
||||
[var] 1 3
|
||||
[y] 5 5
|
||||
[=] 7 7
|
||||
[2] 9 9
|
||||
[;] 10 10
|
||||
L5
|
||||
[var] 1 3
|
||||
[z] 5 5
|
||||
[=] 7 7
|
||||
[3] 9 9
|
||||
[;] 10 10
|
||||
L6
|
||||
[window] 1 6
|
||||
[.] 7 7
|
||||
[alert] 8 12
|
||||
[(] 13 13
|
||||
['Test'] 14 19
|
||||
[)] 20 20
|
||||
[;] 21 21
|
||||
L9
|
||||
[}] 1 1
|
||||
[)] 2 2
|
||||
[(] 3 3
|
||||
[)] 4 4
|
||||
[;] 5 5
|
||||
EOF
|
Reference in New Issue
Block a user