added test for object

This commit is contained in:
Pavel Talanov
2012-02-02 17:34:16 +04:00
parent c8e08e3ca2
commit 044fb0705d
3 changed files with 50 additions and 0 deletions
@@ -16,6 +16,7 @@ public final class Namer {
private static final String CLASS_OBJECT_NAME = "Class";
private static final String TRAIT_OBJECT_NAME = "Trait";
private static final String NAMESPACE_OBJECT_NAME = "Namespace";
private static final String OBJECT_OBJECT_NAME = "object";
private static final String SETTER_PREFIX = "set_";
private static final String GETTER_PREFIX = "get_";
private static final String BACKING_FIELD_PREFIX = "$";
@@ -76,6 +77,8 @@ public final class Namer {
private final JsName traitName;
@NotNull
private final JsName namespaceName;
@NotNull
private final JsName objectName;
private Namer(@NotNull JsScope rootScope) {
kotlinName = rootScope.declareName(KOTLIN_OBJECT_NAME);
@@ -83,6 +86,7 @@ public final class Namer {
traitName = kotlinScope.declareName(TRAIT_OBJECT_NAME);
namespaceName = kotlinScope.declareName(NAMESPACE_OBJECT_NAME);
className = kotlinScope.declareName(CLASS_OBJECT_NAME);
objectName = kotlinScope.declareName(OBJECT_OBJECT_NAME);
}
@NotNull
@@ -100,6 +104,11 @@ public final class Namer {
return kotlin(createMethodReference(namespaceName));
}
@NotNull
public JsNameRef objectCreationMethodReference() {
return kotlin(createMethodReference(objectName));
}
@NotNull
private JsNameRef createMethodReference(@NotNull JsName name) {
JsNameRef qualifier = name.makeRef();
@@ -0,0 +1,21 @@
package org.jetbrains.k2js.test;
import org.junit.Test;
/**
* @author Pavel Talanov
*/
public class ObjectTest extends TranslationTest {
private static final String MAIN = "object/";
@Override
protected String mainDirectory() {
return MAIN;
}
@Test
public void objectWithMethods() throws Exception {
testFooBoxIsTrue("objectWithMethods.kt");
}
}
@@ -0,0 +1,20 @@
package foo
val a = object {
fun c() = 3
fun b() = 2
}
fun box() : Boolean {
if (a.c() != 3) {
return false;
}
if (a.b() != 2) {
return false;
}
return true;
}