forked from INRIA/spoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for issue INRIA#2237 reject invalide names
- Loading branch information
1 parent
8ff4eb4
commit 0b6f95e
Showing
2 changed files
with
75 additions
and
1 deletion.
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,49 @@ | ||
package spoon.generating; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import org.junit.Test; | ||
import spoon.Launcher; | ||
import spoon.reflect.reference.CtLocalVariableReference; | ||
/** | ||
* for correct identifier see JLS chapter 3.8 and for keywords 3.9 | ||
*/ | ||
public class CorrectIdentifierTest { | ||
|
||
@Test | ||
public void wrongIdentifer() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(IllegalArgumentException.class, () -> localVariableRef.setSimpleName("tacos.EatIt()")); | ||
} | ||
@Test | ||
public void wrongIdentifer2() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(IllegalArgumentException.class, () -> localVariableRef.setSimpleName("1tacos")); | ||
} | ||
@Test | ||
public void keyWord() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(IllegalArgumentException.class, () -> localVariableRef.setSimpleName("class")); | ||
} | ||
@Test | ||
public void keyWord2() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(IllegalArgumentException.class, () -> localVariableRef.setSimpleName("null")); | ||
} | ||
@Test | ||
public void keyWord3() { | ||
CtLocalVariableReference<Object> localVariableRef = new Launcher().getFactory().createLocalVariableReference(); | ||
assertThrows(IllegalArgumentException.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")); | ||
} | ||
} |