Added unittest for decorators.
This commit is contained in:
@ -9,6 +9,8 @@ import org.junit.jupiter.api.Test;
|
||||
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
||||
import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
|
||||
|
||||
|
||||
|
||||
class EcmascriptTokenizerTest extends CpdTextComparisonTest {
|
||||
|
||||
EcmascriptTokenizerTest() {
|
||||
@ -57,4 +59,7 @@ class EcmascriptTokenizerTest extends CpdTextComparisonTest {
|
||||
void testTabWidth() {
|
||||
doTest("tabWidth");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDecorators() { doTest("decorator"); }
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.typescript.cpd;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import net.sourceforge.pmd.cpd.test.CpdTextComparisonTest;
|
||||
import net.sourceforge.pmd.lang.ecmascript.cpd.EcmascriptTokenizer;
|
||||
import net.sourceforge.pmd.lang.typescript.TsLanguageModule;
|
||||
|
||||
class TypeScriptTokenizerTest extends CpdTextComparisonTest {
|
||||
@ -25,21 +24,4 @@ class TypeScriptTokenizerTest extends CpdTextComparisonTest {
|
||||
void apiSampleWatchTest() {
|
||||
doTest("APISample_Watch");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDecorators() throws IOException {
|
||||
Tokenizer t = new EcmascriptTokenizer();
|
||||
SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader("// A simple decorator" + PMD.EOL
|
||||
+ "@annotation" + PMD.EOL
|
||||
+ "class MyClass { }" + PMD.EOL
|
||||
+ "" + PMD.EOL
|
||||
+ "function annotation(target) {" + PMD.EOL
|
||||
+ " // Add a property on target" + PMD.EOL
|
||||
+ " target.annotated = true;" + PMD.EOL
|
||||
+ "}" + PMD.EOL
|
||||
));
|
||||
final Tokens tokens = new Tokens();
|
||||
t.tokenize(sourceCode, tokens);
|
||||
assertEquals("@annotation", tokens.getTokens().get(0).toString());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
// A simple decorator\n"
|
||||
@annotation
|
||||
class MyClass { }
|
||||
|
||||
function annotation(target) {
|
||||
// Add a property on target
|
||||
target.annotated = true;
|
||||
}
|
25
pmd-javascript/src/test/resources/net/sourceforge/pmd/lang/ecmascript/cpd/testdata/decorator.txt
vendored
Normal file
25
pmd-javascript/src/test/resources/net/sourceforge/pmd/lang/ecmascript/cpd/testdata/decorator.txt
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L2
|
||||
[@annotation] 1 12
|
||||
L3
|
||||
[class] 1 6
|
||||
[MyClass] 7 14
|
||||
[{] 15 16
|
||||
[}] 17 18
|
||||
L5
|
||||
[function] 1 9
|
||||
[annotation] 10 20
|
||||
[(] 20 21
|
||||
[target] 21 27
|
||||
[)] 27 28
|
||||
[{] 29 30
|
||||
L7
|
||||
[target] 4 10
|
||||
[.] 10 11
|
||||
[annotated] 11 20
|
||||
[=] 21 22
|
||||
[true] 23 27
|
||||
[;] 27 28
|
||||
L8
|
||||
[}] 1 2
|
||||
EOF
|
@ -1,24 +0,0 @@
|
||||
class Point {
|
||||
private _x: number;
|
||||
private _y: number;
|
||||
constructor(x: number, y: number) {
|
||||
this._x = x;
|
||||
this._y = y;
|
||||
}
|
||||
|
||||
@configurable(false)
|
||||
get x() {
|
||||
return this._x;
|
||||
}
|
||||
|
||||
@configurable(false)
|
||||
get y() {
|
||||
return this._y;
|
||||
}
|
||||
}
|
||||
|
||||
function configurable(value: boolean) {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
descriptor.configurable = value;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user