Add trivial tests for compositions of ObjCExport and overriding
This commit is contained in:
committed by
SvyatoslavScherbina
parent
ad58a55e03
commit
d029e3b730
@@ -280,3 +280,61 @@ class Deeply {
|
||||
}
|
||||
|
||||
data class CKeywords(val float: Float, val `enum`: Int, var goto: Boolean)
|
||||
|
||||
interface Base1 {
|
||||
fun same(value: Int?): Int?
|
||||
}
|
||||
|
||||
interface ExtendedBase1 : Base1 {
|
||||
override fun same(value: Int?): Int?
|
||||
}
|
||||
|
||||
interface Base2 {
|
||||
fun same(value: Int?): Int?
|
||||
}
|
||||
|
||||
internal interface Base3 {
|
||||
fun same(value: Int?): Int
|
||||
}
|
||||
|
||||
open class Base23 : Base2, Base3 {
|
||||
override fun same(value: Int?): Int = error("should not reach here")
|
||||
}
|
||||
|
||||
fun call(base1: Base1, value: Int?) = base1.same(value)
|
||||
fun call(extendedBase1: ExtendedBase1, value: Int?) = extendedBase1.same(value)
|
||||
fun call(base2: Base2, value: Int?) = base2.same(value)
|
||||
fun call(base3: Any, value: Int?) = (base3 as Base3).same(value)
|
||||
fun call(base23: Base23, value: Int?) = base23.same(value)
|
||||
|
||||
interface Transform<T, R> {
|
||||
fun map(value: T): R
|
||||
}
|
||||
|
||||
interface TransformWithDefault<T> : Transform<T, T> {
|
||||
override fun map(value: T): T = value
|
||||
}
|
||||
|
||||
class TransformInheritingDefault<T> : TransformWithDefault<T>
|
||||
|
||||
interface TransformIntString {
|
||||
fun map(intValue: Int): String
|
||||
}
|
||||
|
||||
abstract class TransformIntToString : Transform<Int, String>, TransformIntString {
|
||||
override abstract fun map(intValue: Int): String
|
||||
}
|
||||
|
||||
open class TransformIntToDecimalString : TransformIntToString() {
|
||||
override fun map(intValue: Int): String = intValue.toString()
|
||||
}
|
||||
|
||||
private class TransformDecimalStringToInt : Transform<String, Int> {
|
||||
override fun map(stringValue: String): Int = stringValue.toInt()
|
||||
}
|
||||
|
||||
fun createTransformDecimalStringToInt(): Transform<String, Int> = TransformDecimalStringToInt()
|
||||
|
||||
open class TransformIntToLong : Transform<Int, Long> {
|
||||
override fun map(value: Int): Long = value.toLong()
|
||||
}
|
||||
@@ -496,6 +496,35 @@ func testNames() throws {
|
||||
try assertEquals(actual: CKeywords(float: 1.0, enum : 42, goto: true).goto_, expected: true)
|
||||
}
|
||||
|
||||
class Base123 : Base23, ExtendedBase1 {
|
||||
override func same(value: KotlinInt?) -> KotlinInt {
|
||||
return value!
|
||||
}
|
||||
}
|
||||
|
||||
func testSwiftOverride() throws {
|
||||
let impl = Base123()
|
||||
try assertEquals(actual: ValuesKt.call(base1: impl, value: 1), expected: 1)
|
||||
try assertEquals(actual: ValuesKt.call(extendedBase1: impl, value: 2), expected: 2)
|
||||
try assertEquals(actual: ValuesKt.call(base2: impl, value: 3), expected: 3)
|
||||
try assertEquals(actual: ValuesKt.call(base3: impl, value: 4), expected: 4)
|
||||
try assertEquals(actual: ValuesKt.call(base23: impl, value: 5), expected: 5)
|
||||
}
|
||||
|
||||
class TransformIntToLongCallingSuper : TransformIntToLong {
|
||||
override func map(value: KotlinInt) -> KotlinLong {
|
||||
return super.map(value: value)
|
||||
}
|
||||
}
|
||||
|
||||
func testKotlinOverride() throws {
|
||||
try assertEquals(actual: TransformInheritingDefault().map(value: 1) as! Int32, expected: 1)
|
||||
try assertEquals(actual: TransformIntToDecimalString().map(value: 2), expected: "2")
|
||||
try assertEquals(actual: TransformIntToDecimalString().map(intValue: 3), expected: "3")
|
||||
try assertEquals(actual: ValuesKt.createTransformDecimalStringToInt().map(value: "4") as! Int32, expected: 4)
|
||||
try assertEquals(actual: TransformIntToLongCallingSuper().map(value: 5), expected: 5)
|
||||
}
|
||||
|
||||
// -------- Execution of the test --------
|
||||
|
||||
class ValuesTests : TestProvider {
|
||||
@@ -533,6 +562,8 @@ class ValuesTests : TestProvider {
|
||||
TestCase(name: "TestShared", method: withAutorelease(testShared)),
|
||||
TestCase(name: "TestPureSwiftClasses", method: withAutorelease(testPureSwiftClasses)),
|
||||
TestCase(name: "TestNames", method: withAutorelease(testNames)),
|
||||
TestCase(name: "TestSwiftOverride", method: withAutorelease(testSwiftOverride)),
|
||||
TestCase(name: "TestKotlinOverride", method: withAutorelease(testKotlinOverride)),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user