proper compilation of enums
This commit is contained in:
@@ -18,8 +18,14 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class EnumGenTest extends CodegenTestCase {
|
||||
|
||||
@@ -29,8 +35,41 @@ public class EnumGenTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
}
|
||||
|
||||
public void testSuperclassIsEnum() throws NoSuchFieldException, IllegalAccessException {
|
||||
loadFile("enum/simple.kt");
|
||||
Class season = loadImplementationClass(generateClassesInFile(), "Season");
|
||||
assertEquals("java.lang.Enum", season.getSuperclass().getName());
|
||||
}
|
||||
|
||||
public void testSimple() {
|
||||
public void testEnumClassModifiers() throws NoSuchFieldException, IllegalAccessException {
|
||||
loadFile("enum/simple.kt");
|
||||
Class season = loadImplementationClass(generateClassesInFile(), "Season");
|
||||
int modifiers = season.getModifiers();
|
||||
assertTrue((modifiers & 0x4000) != 0); // ACC_ENUM
|
||||
assertTrue((modifiers & Modifier.FINAL) != 0);
|
||||
}
|
||||
|
||||
public void testEnumFieldModifiers() throws NoSuchFieldException, IllegalAccessException {
|
||||
loadFile("enum/simple.kt");
|
||||
Class season = loadImplementationClass(generateClassesInFile(), "Season");
|
||||
Field summer = season.getField("SUMMER");
|
||||
int modifiers = summer.getModifiers();
|
||||
assertTrue((modifiers & 0x4000) != 0); // ACC_ENUM
|
||||
assertTrue((modifiers & Modifier.FINAL) != 0);
|
||||
assertTrue((modifiers & Modifier.STATIC) != 0);
|
||||
assertTrue((modifiers & Modifier.PUBLIC) != 0);
|
||||
}
|
||||
|
||||
public void testEnumConstantConstructors() throws Exception {
|
||||
loadText("enum class Color(val rgb: Int) { RED: Color(0xFF0000); GREEN: Color(0x00FF00); }");
|
||||
final Class colorClass = createClassLoader(generateClassesInFile()).loadClass("Color");
|
||||
final Field redField = colorClass.getField("RED");
|
||||
final Object redValue = redField.get(null);
|
||||
final Method rgbMethod = colorClass.getMethod("getRgb");
|
||||
assertEquals(0xFF0000, rgbMethod.invoke(redValue));
|
||||
}
|
||||
|
||||
public void testSimple() throws NoSuchFieldException, IllegalAccessException {
|
||||
blackBoxFile("enum/simple.kt");
|
||||
}
|
||||
|
||||
@@ -38,5 +77,19 @@ public class EnumGenTest extends CodegenTestCase {
|
||||
blackBoxFile("enum/asReturnExpression.kt");
|
||||
}
|
||||
|
||||
public void testToString() {
|
||||
blackBoxFile("enum/toString.kt");
|
||||
}
|
||||
|
||||
public void testName() {
|
||||
blackBoxFile("enum/name.kt");
|
||||
}
|
||||
|
||||
public void testOrdinal() {
|
||||
blackBoxFile("enum/ordinal.kt");
|
||||
}
|
||||
|
||||
public void testValues() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
blackBoxFile("enum/valueof.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user