Add test for overriding methods of Any from Swift
This commit is contained in:
committed by
Vasily Levchenko
parent
9fb2d4b956
commit
0a2a8a58c1
@@ -663,6 +663,16 @@ __attribute__((swift_name("ArraysInitBlock")))
|
|||||||
- (NSString *)log __attribute__((swift_name("log()")));
|
- (NSString *)log __attribute__((swift_name("log()")));
|
||||||
@end;
|
@end;
|
||||||
|
|
||||||
|
__attribute__((objc_subclassing_restricted))
|
||||||
|
__attribute__((swift_name("OverrideMethodsOfAnyKt")))
|
||||||
|
@interface KtOverrideMethodsOfAnyKt : KtBase
|
||||||
|
|
||||||
|
/**
|
||||||
|
@note This method converts all Kotlin exceptions to errors.
|
||||||
|
*/
|
||||||
|
+ (BOOL)testObj:(id)obj other:(id)other swift:(BOOL)swift error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test(obj:other:swift:)")));
|
||||||
|
@end;
|
||||||
|
|
||||||
__attribute__((objc_subclassing_restricted))
|
__attribute__((objc_subclassing_restricted))
|
||||||
__attribute__((swift_name("ThrowsEmptyKt")))
|
__attribute__((swift_name("ThrowsEmptyKt")))
|
||||||
@interface KtThrowsEmptyKt : KtBase
|
@interface KtThrowsEmptyKt : KtBase
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package overrideMethodsOfAny
|
||||||
|
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
fun test(obj: Any, other: Any, swift: Boolean) {
|
||||||
|
if (!swift) {
|
||||||
|
// Doesn't work for Swift, see https://youtrack.jetbrains.com/issue/KT-44613.
|
||||||
|
assertEquals(42, obj.hashCode())
|
||||||
|
assertTrue(obj.equals(other))
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(obj.equals(obj))
|
||||||
|
assertFalse(obj.equals(null))
|
||||||
|
assertFalse(obj.equals(Any()))
|
||||||
|
|
||||||
|
assertEquals("toString", obj.toString())
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Kt
|
||||||
|
|
||||||
|
private class SwiftOverridingMethodsOfAny : Hashable, Equatable, CustomStringConvertible {
|
||||||
|
var hashValue: Int { return 42 }
|
||||||
|
|
||||||
|
static func == (lhs: SwiftOverridingMethodsOfAny, rhs: SwiftOverridingMethodsOfAny) -> Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
var description: String { return "toString" }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func testSwift() throws {
|
||||||
|
try OverrideMethodsOfAnyKt.test(obj: SwiftOverridingMethodsOfAny(), other: SwiftOverridingMethodsOfAny(), swift: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ObjCOverridingMethodsOfAny : NSObject {
|
||||||
|
override var hash: Int { return 42 }
|
||||||
|
|
||||||
|
override func isEqual(_ other: Any?) -> Bool {
|
||||||
|
return other is ObjCOverridingMethodsOfAny
|
||||||
|
}
|
||||||
|
|
||||||
|
override var description: String { return "toString" }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func testObjC() throws {
|
||||||
|
try OverrideMethodsOfAnyKt.test(obj: ObjCOverridingMethodsOfAny(), other: ObjCOverridingMethodsOfAny(), swift: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
class OverrideMethodsOfAnyTests : SimpleTestProvider {
|
||||||
|
override init() {
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
test("TestSwift", testSwift)
|
||||||
|
test("TestObjC", testObjC)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user