Files
kotlin-fork/compiler/tests/org/jetbrains/jet/codegen/FunctionGenTest.java
T
Alexander Udalov 620143ae5b Add test on bytecode text
Test data should be a Kotlin source file with zero or more comments e.g. of
the form: '// 1 INVOKEVIRTUAL'. The test then checks that the generated
bytecode for this file contains exactly one occurrence of the string
'INVOKEVIRTUAL'
2013-02-11 02:01:43 +04:00

58 lines
2.2 KiB
Java

/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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;
public class FunctionGenTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
public void testAnyEqualsNullable() throws InvocationTargetException, IllegalAccessException {
loadText("fun foo(x: Any?) = x.equals(\"lala\")");
Method foo = generateFunction();
assertTrue((Boolean) foo.invoke(null, "lala"));
assertFalse((Boolean) foo.invoke(null, "mama"));
}
public void testNoRefToOuter() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
loadText("class A() { fun f() : ()->String { val s = \"OK\"; return { -> s } } }");
Class foo = generateClass("A");
final Object obj = foo.newInstance();
final Method f = foo.getMethod("f");
final Object closure = f.invoke(obj);
final Class<? extends Object> aClass = closure.getClass();
final Field[] fields = aClass.getDeclaredFields();
assertEquals(1, fields.length);
assertEquals("$s", fields[0].getName());
}
public void testAnyEquals() throws InvocationTargetException, IllegalAccessException {
loadText("fun foo(x: Any) = x.equals(\"lala\")");
Method foo = generateFunction();
assertTrue((Boolean) foo.invoke(null, "lala"));
assertFalse((Boolean) foo.invoke(null, "mama"));
}
}