namespace properties are mostly working

This commit is contained in:
Dmitry Jemerov
2011-04-21 14:23:11 +02:00
parent c91cd748ff
commit d17f095eec
12 changed files with 216 additions and 20 deletions
@@ -42,7 +42,7 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
return answer.toString();
}
private Class generateNamespaceClass() {
protected Class generateNamespaceClass() {
JetFile jetFile = (JetFile) myFixture.getFile();
final JetNamespace namespace = jetFile.getRootNamespace();
String fqName = NamespaceCodegen.getJVMClassName(namespace.getFQName()).replace("/", ".");
@@ -89,6 +89,11 @@ public abstract class CodegenTestCase extends LightCodeInsightFixtureTestCase {
throw new IllegalArgumentException("couldn't find method " + name);
}
protected void assertIsCurrentTime(long returnValue) {
long currentTime = System.currentTimeMillis();
assertTrue(Math.abs(returnValue - currentTime) <= 1L);
}
private static class MyClassLoader extends ClassLoader {
public MyClassLoader(ClassLoader parent) {
super(parent);
@@ -56,8 +56,7 @@ public class NamespaceGenTest extends CodegenTestCase {
System.out.println(generateToText());
final Method main = generateFunction();
final long returnValue = (Long) main.invoke(null);
long currentTime = System.currentTimeMillis();
assertTrue(Math.abs(returnValue - currentTime) <= 1L);
assertIsCurrentTime(returnValue);
}
public void testIdentityHashCode() throws Exception {
@@ -1,5 +1,9 @@
package org.jetbrains.jet.codegen;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
/**
* @author yole
*/
@@ -8,6 +12,39 @@ public class PropertyGenTest extends CodegenTestCase {
loadFile("privateVal.jet");
System.out.println(generateToText());
// TODO
}
public void testPropertyInNamespace() throws Exception {
loadText("private val x = 239");
final Class nsClass = generateNamespaceClass();
final Field[] fields = nsClass.getDeclaredFields();
assertEquals(1, fields.length);
final Field field = fields[0];
field.setAccessible(true);
assertEquals("x", field.getName());
assertEquals(Modifier.PRIVATE | Modifier.STATIC, field.getModifiers());
assertEquals(239, field.get(null));
}
public void testFieldPropertyAccess() throws Exception {
loadFile("fieldPropertyAccess.jet");
final Method method = generateFunction();
assertEquals(1, method.invoke(null));
assertEquals(2, method.invoke(null));
}
public void testFieldGetter() throws Exception {
loadText("val now: Long get() = System.currentTimeMillis(); fun foo() = now");
final Method method = generateFunction("foo");
assertIsCurrentTime((Long) method.invoke(null));
}
public void testFieldSetter() throws Exception {
loadFile("fieldSetter.jet");
System.out.println(generateToText());
final Method method = generateFunction("append");
method.invoke(null, "IntelliJ ");
String value = (String) method.invoke(null, "IDEA");
assertEquals(value, "IntelliJ IDEA");
}
}