-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: reject invalid simple names (#3189)
- Loading branch information
1 parent
9207950
commit 9db3f61
Showing
8 changed files
with
142 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package spoon.generating; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import spoon.Launcher; | ||
import spoon.SpoonException; | ||
import spoon.reflect.reference.CtLocalVariableReference; | ||
/** | ||
* for correct identifier see JLS chapter 3.8 and for keywords 3.9. | ||
* Ignored tests because we have to cut some corners between spec and jdt. | ||
*/ | ||
public class CorrectIdentifierTest { | ||
|
||
@Test | ||
public void wrongIdentifer() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(SpoonException.class, () -> localVariableRef.setSimpleName("tacos.EatIt()")); | ||
} | ||
@Test | ||
public void wrongIdentifer2() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(SpoonException.class, () -> localVariableRef.setSimpleName(";tacos")); | ||
} | ||
@Ignore | ||
@Test | ||
public void keyWord() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(SpoonException.class, () -> localVariableRef.setSimpleName("class")); | ||
} | ||
@Ignore | ||
@Test | ||
public void keyWord2() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(SpoonException.class, () -> localVariableRef.setSimpleName("null")); | ||
} | ||
@Ignore | ||
@Test | ||
public void keyWord3() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(SpoonException.class, () -> localVariableRef.setSimpleName("true")); | ||
} | ||
@Test | ||
public void correctIdentifer() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertDoesNotThrow(() -> localVariableRef.setSimpleName("EatIt")); | ||
|
||
} | ||
@Test | ||
public void correctIdentifer2() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertDoesNotThrow(() -> localVariableRef.setSimpleName("ClassFoo")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters