JS backend: tests for KT-5772

This commit is contained in:
Michael Nedzelsky
2014-09-18 22:15:02 +04:00
parent bdca7e0e37
commit e6a17cbd78
5 changed files with 126 additions and 0 deletions
@@ -0,0 +1,40 @@
package foo
class A(val value: Int) : Comparable<A> {
override public fun compareTo(other: A): Int = other.value compareTo value
}
class B(val value: Int)
fun testExtensionFunctionAsCompareTo() {
val compareTo: B.( B ) -> Int = { (other) -> other.value compareTo this.value }
val x: B = B(100)
val y: B = B(200)
assertEquals(false, x < y, "ext fun: x < y")
assertEquals(true, x > y, "ext fun: x > y")
assertEquals(1, x compareTo y, "ext fun: x compareTo y")
}
fun testMethodAsCompareTo() {
val x: A = A(100)
val y: A = A(200)
assertEquals(false, x < y, "meth: x < y")
assertEquals(true, x > y, "meth: x > y")
assertEquals(1, x compareTo y, "meth: x compareTo y")
assertEquals(false, (x: Comparable<A>) < y, "meth: (x: Comparable<A>) < y")
assertEquals(true, (x: Comparable<A>) > y, "meth: (x: Comparable<A>) > y")
assertEquals(1, (x: Comparable<A>) compareTo y, "meth: (x: Comparable<A>) compareTo y")
}
fun box(): String {
testExtensionFunctionAsCompareTo()
testMethodAsCompareTo()
return "OK"
}