Added some tests on interface check for ObjC
This commit is contained in:
@@ -989,6 +989,11 @@ __attribute__((swift_name("ClassForTypeCheck")))
|
|||||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||||
@end;
|
@end;
|
||||||
|
|
||||||
|
__attribute__((swift_name("InterfaceForTypeCheck")))
|
||||||
|
@protocol ValuesInterfaceForTypeCheck
|
||||||
|
@required
|
||||||
|
@end;
|
||||||
|
|
||||||
@interface ValuesEnumeration (ValuesKt)
|
@interface ValuesEnumeration (ValuesKt)
|
||||||
- (ValuesEnumeration *)getAnswer __attribute__((swift_name("getAnswer()")));
|
- (ValuesEnumeration *)getAnswer __attribute__((swift_name("getAnswer()")));
|
||||||
@end;
|
@end;
|
||||||
@@ -1069,6 +1074,7 @@ __attribute__((swift_name("ValuesKt")))
|
|||||||
+ (void)warning __attribute__((swift_name("warning()"))) __attribute__((deprecated("warning")));
|
+ (void)warning __attribute__((swift_name("warning()"))) __attribute__((deprecated("warning")));
|
||||||
+ (void)gc __attribute__((swift_name("gc()")));
|
+ (void)gc __attribute__((swift_name("gc()")));
|
||||||
+ (BOOL)testClassTypeCheckX:(id)x __attribute__((swift_name("testClassTypeCheck(x:)")));
|
+ (BOOL)testClassTypeCheckX:(id)x __attribute__((swift_name("testClassTypeCheck(x:)")));
|
||||||
|
+ (BOOL)testInterfaceTypeCheckX:(id)x __attribute__((swift_name("testInterfaceTypeCheck(x:)")));
|
||||||
@property (class, readonly) double dbl __attribute__((swift_name("dbl")));
|
@property (class, readonly) double dbl __attribute__((swift_name("dbl")));
|
||||||
@property (class, readonly) float flt __attribute__((swift_name("flt")));
|
@property (class, readonly) float flt __attribute__((swift_name("flt")));
|
||||||
@property (class, readonly) int32_t integer __attribute__((swift_name("integer")));
|
@property (class, readonly) int32_t integer __attribute__((swift_name("integer")));
|
||||||
|
|||||||
@@ -777,4 +777,8 @@ class SharedRefs {
|
|||||||
|
|
||||||
open class ClassForTypeCheck
|
open class ClassForTypeCheck
|
||||||
|
|
||||||
fun testClassTypeCheck(x: Any) = x is ClassForTypeCheck
|
fun testClassTypeCheck(x: Any) = x is ClassForTypeCheck
|
||||||
|
|
||||||
|
interface InterfaceForTypeCheck
|
||||||
|
|
||||||
|
fun testInterfaceTypeCheck(x: Any) = x is InterfaceForTypeCheck
|
||||||
@@ -1004,6 +1004,18 @@ func testClassTypeCheck() throws {
|
|||||||
try assertTrue(ValuesKt.testClassTypeCheck(x: ClassForTypeCheckInheritor()))
|
try assertTrue(ValuesKt.testClassTypeCheck(x: ClassForTypeCheckInheritor()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ClassForInterfaceTypeCheckInheritor1 : InterfaceForTypeCheck { }
|
||||||
|
class ClassForInterfaceTypeCheckInheritor2 : Base23, InterfaceForTypeCheck { }
|
||||||
|
class ClassForInterfaceTypeCheckInheritor3 : Base23, ExtendedBase1, InterfaceForTypeCheck { }
|
||||||
|
class ClassForInterfaceTypeCheck_Fail : Base23 { }
|
||||||
|
|
||||||
|
func testInterfaceTypeCheck() throws {
|
||||||
|
try assertTrue(ValuesKt.testInterfaceTypeCheck(x: ClassForInterfaceTypeCheckInheritor1()))
|
||||||
|
try assertTrue(ValuesKt.testInterfaceTypeCheck(x: ClassForInterfaceTypeCheckInheritor2()))
|
||||||
|
try assertTrue(ValuesKt.testInterfaceTypeCheck(x: ClassForInterfaceTypeCheckInheritor3()))
|
||||||
|
try assertFalse(ValuesKt.testInterfaceTypeCheck(x: ClassForInterfaceTypeCheck_Fail()))
|
||||||
|
}
|
||||||
|
|
||||||
// -------- Execution of the test --------
|
// -------- Execution of the test --------
|
||||||
|
|
||||||
class ValuesTests : TestProvider {
|
class ValuesTests : TestProvider {
|
||||||
@@ -1054,6 +1066,7 @@ class ValuesTests : TestProvider {
|
|||||||
TestCase(name: "TestWeakRefs", method: withAutorelease(testWeakRefs)),
|
TestCase(name: "TestWeakRefs", method: withAutorelease(testWeakRefs)),
|
||||||
TestCase(name: "TestSharedRefs", method: withAutorelease(TestSharedRefs().test)),
|
TestCase(name: "TestSharedRefs", method: withAutorelease(TestSharedRefs().test)),
|
||||||
TestCase(name: "TestClassTypeCheck", method: withAutorelease(testClassTypeCheck)),
|
TestCase(name: "TestClassTypeCheck", method: withAutorelease(testClassTypeCheck)),
|
||||||
|
TestCase(name: "TestInterfaceTypeCheck", method: withAutorelease(testInterfaceTypeCheck)),
|
||||||
TestCase(name: "TestGH2931", method: withAutorelease(testGH2931)),
|
TestCase(name: "TestGH2931", method: withAutorelease(testGH2931)),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,8 @@ class MutablePairImpl(first: Int, second: Int) : NSObject(), MutablePairProtocol
|
|||||||
constructor() : this(123, 321)
|
constructor() : this(123, 321)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Zzz
|
||||||
|
|
||||||
fun testTypeOps() {
|
fun testTypeOps() {
|
||||||
assertTrue(99.asAny() is NSNumber)
|
assertTrue(99.asAny() is NSNumber)
|
||||||
assertTrue(null.asAny() is NSNumber?)
|
assertTrue(null.asAny() is NSNumber?)
|
||||||
@@ -149,6 +151,7 @@ fun testTypeOps() {
|
|||||||
assertTrue("bar".asAny() is NSString)
|
assertTrue("bar".asAny() is NSString)
|
||||||
|
|
||||||
assertTrue(Foo.asAny() is FooMeta)
|
assertTrue(Foo.asAny() is FooMeta)
|
||||||
|
assertFalse(Foo.asAny() is Zzz)
|
||||||
assertTrue(Foo.asAny() is NSObjectMeta)
|
assertTrue(Foo.asAny() is NSObjectMeta)
|
||||||
assertTrue(Foo.asAny() is NSObject)
|
assertTrue(Foo.asAny() is NSObject)
|
||||||
assertFalse(Foo.asAny() is Foo)
|
assertFalse(Foo.asAny() is Foo)
|
||||||
|
|||||||
Reference in New Issue
Block a user