Added unittest for decorators.

This commit is contained in:
wener
2023-09-12 11:30:34 +02:00
parent 940585de9a
commit dca539b841
5 changed files with 38 additions and 42 deletions

View File

@ -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"); }
}

View File

@ -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());
}
}

View File

@ -0,0 +1,8 @@
// A simple decorator\n"
@annotation
class MyClass { }
function annotation(target) {
// Add a property on target
target.annotated = true;
}

View 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

View File

@ -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;
};
}