Provide "equals" and "hashCode" for reflection objects

This commit is contained in:
Alexander Udalov
2014-06-30 19:16:59 +04:00
parent 704de8992e
commit c5d92cc03e
8 changed files with 81 additions and 2 deletions
@@ -0,0 +1,29 @@
import kotlin.test.*
val top = 42
var top2 = -23
val Int.intExt: Int get() = this
val Char.charExt: Int get() = this.toInt()
class A(var mem: String)
class B(var mem: String)
fun checkEqual(x: Any, y: Any) {
assertEquals(x, y)
assertEquals(x.hashCode(), y.hashCode(), "Elements are equal but their hash codes are not: ${x.hashCode()} != ${y.hashCode()}")
}
fun box(): String {
checkEqual(::top, ::top)
checkEqual(::top2, ::top2)
checkEqual(Int::intExt, Int::intExt)
checkEqual(A::mem, A::mem)
assertFalse(::top == ::top2)
assertFalse(Int::intExt == Char::charExt)
assertFalse(A::mem == B::mem)
return "OK"
}
@@ -1381,7 +1381,7 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection")
@InnerTestClasses({Reflection.Enclosing.class, Reflection.GenericSignature.class, Reflection.Mapping.class})
@InnerTestClasses({Reflection.Enclosing.class, Reflection.GenericSignature.class, Reflection.Mapping.class, Reflection.MethodsFromAny.class})
public static class Reflection extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInReflection() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection"), Pattern.compile("^(.+)\\.kt$"), true);
@@ -1530,12 +1530,26 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny")
public static class MethodsFromAny extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInMethodsFromAny() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("equalsHashCode.kt")
public void testEqualsHashCode() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/reflection/methodsFromAny/equalsHashCode.kt");
}
}
public static Test innerSuite() {
TestSuite suite = new TestSuite("Reflection");
suite.addTestSuite(Reflection.class);
suite.addTest(Enclosing.innerSuite());
suite.addTestSuite(GenericSignature.class);
suite.addTestSuite(Mapping.class);
suite.addTestSuite(MethodsFromAny.class);
return suite;
}
}