added test case for KT-2372

This commit is contained in:
James Strachan
2012-07-05 14:16:20 +01:00
parent 3073af99db
commit 6863526d52
3 changed files with 34 additions and 3 deletions
@@ -22,6 +22,10 @@ public final class EqualsTest extends AbstractExpressionTest {
super("equals/");
}
public void TODO_testCustomEqualsMethodOnAny() throws Exception {
fooBoxTest();
}
public void testCustomEqualsMethod() throws Exception {
fooBoxTest();
}
@@ -9,13 +9,16 @@ class Foo(val name: String) {
}
}
fun callEqualsMethod(v1: Foo?, v2: Foo?): Boolean {
return v1 == v2
}
fun box() : Boolean {
val a = Foo("abc")
val b = Foo("abc")
val c = Foo("def")
if (a != b) return false
if (a == c) return false
if (!callEqualsMethod(a, b)) return false
if (callEqualsMethod(a, c)) return false
return true
}
@@ -0,0 +1,24 @@
package foo
class Foo(val name: String) {
public fun equals(that: Any?): Boolean {
if (that !is Foo) {
return false
}
return this.name == that.name
}
}
fun callEqualsMethod(v1: Any?, v2: Any?): Boolean {
return v1 == v2
}
fun box() : Boolean {
val a = Foo("abc")
val b = Foo("abc")
val c = Foo("def")
if (!callEqualsMethod(a, b)) return false
if (callEqualsMethod(a, c)) return false
return true
}