Implement equals, hashCode and toString for Objective-C objects
This commit is contained in:
committed by
SvyatoslavScherbina
parent
6b042a5510
commit
4e285a5ef4
@@ -2101,7 +2101,8 @@ if (isMac()) {
|
||||
|
||||
task interop_objc_smoke(type: RunInteropKonanTest) {
|
||||
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
|
||||
goldValue = "Hello, World!\nKotlin says: Hello, everybody!\nHello from Kotlin\n2, 1\nDeallocated\nDeallocated\n"
|
||||
goldValue = "Hello, World!\nKotlin says: Hello, everybody!\nHello from Kotlin\n2, 1\n" +
|
||||
"true\ntrue\nDeallocated\nDeallocated\n"
|
||||
|
||||
source = "interop/objc/smoke.kt"
|
||||
interop = 'objcSmoke'
|
||||
|
||||
@@ -23,6 +23,21 @@ fun run() {
|
||||
replacePairElements(pair, 1, 2)
|
||||
pair.swap()
|
||||
println("${pair.first}, ${pair.second}")
|
||||
|
||||
// equals and hashCode (virtually):
|
||||
val map = mapOf(foo to pair, pair to foo)
|
||||
|
||||
// equals (directly):
|
||||
if (!foo.equals(pair)) {
|
||||
// toString (directly):
|
||||
println(map[pair].toString() + map[foo].toString() == foo.description() + pair.description())
|
||||
}
|
||||
|
||||
// hashCode (directly):
|
||||
if (foo.hashCode() == foo.hash().toInt()) {
|
||||
// toString (virtually):
|
||||
println(map.keys.map { it.toString() }.min() == foo.description())
|
||||
}
|
||||
}
|
||||
|
||||
fun MutablePairProtocol.swap() {
|
||||
|
||||
Reference in New Issue
Block a user