Expose enum .values function when generating Obj-C header

This commit is contained in:
Svyatoslav Scherbina
2020-10-30 10:49:51 +03:00
committed by Stanislav Erokhin
parent 740d50ca09
commit 58855b9eff
8 changed files with 195 additions and 9 deletions
@@ -0,0 +1,16 @@
package enumValues
enum class EnumLeftRightUpDown {
LEFT, RIGHT, UP, DOWN
}
enum class EnumOneTwoThreeValues {
ONE, TWO, THREE, VALUES
}
enum class EnumValuesValues_ {
VALUES, VALUES_
}
enum class EmptyEnum {
}
@@ -0,0 +1,47 @@
import Kt
private func testEnumValues() throws {
let values = EnumLeftRightUpDown.values()
try assertEquals(actual: values.size, expected: 4)
try assertSame(actual: values.get(index: 0), expected: EnumLeftRightUpDown.left)
try assertSame(actual: values.get(index: 1), expected: EnumLeftRightUpDown.right)
try assertSame(actual: values.get(index: 2), expected: EnumLeftRightUpDown.up)
try assertSame(actual: values.get(index: 3), expected: EnumLeftRightUpDown.down)
}
private func testEnumValuesMangled() throws {
let values = EnumOneTwoThreeValues.values_()
try assertEquals(actual: values.size, expected: 4)
try assertSame(actual: values.get(index: 0), expected: EnumOneTwoThreeValues.one)
try assertSame(actual: values.get(index: 1), expected: EnumOneTwoThreeValues.two)
try assertSame(actual: values.get(index: 2), expected: EnumOneTwoThreeValues.three)
try assertSame(actual: values.get(index: 3), expected: EnumOneTwoThreeValues.values)
}
private func testEnumValuesMangledTwice() throws {
let values = EnumValuesValues_.values__()
try assertEquals(actual: values.size, expected: 2)
try assertSame(actual: values.get(index: 0), expected: EnumValuesValues_.values)
try assertSame(actual: values.get(index: 1), expected: EnumValuesValues_.values_)
}
private func testEnumValuesEmpty() throws {
try assertEquals(actual: EmptyEnum.values().size, expected: 0)
}
class EnumValuesTests : SimpleTestProvider {
override init() {
super.init()
test("TestEnumValues", testEnumValues)
test("TestEnumValuesMangled", testEnumValuesMangled)
test("TestEnumValuesMangledTwice", testEnumValuesMangledTwice)
test("TestEnumValuesEmpty", testEnumValuesEmpty)
}
}
@@ -331,6 +331,52 @@ __attribute__((swift_name("DeallocRetainKt")))
+ (KtKotlinWeakReference<id> *)createWeakReferenceValue:(id)value __attribute__((swift_name("createWeakReference(value:)")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("EnumLeftRightUpDown")))
@interface KtEnumLeftRightUpDown : KtKotlinEnum<KtEnumLeftRightUpDown *>
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
- (instancetype)initWithName:(NSString *)name ordinal:(int32_t)ordinal __attribute__((swift_name("init(name:ordinal:)"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable));
@property (class, readonly) KtEnumLeftRightUpDown *left __attribute__((swift_name("left")));
@property (class, readonly) KtEnumLeftRightUpDown *right __attribute__((swift_name("right")));
@property (class, readonly) KtEnumLeftRightUpDown *up __attribute__((swift_name("up")));
@property (class, readonly) KtEnumLeftRightUpDown *down __attribute__((swift_name("down")));
+ (KtKotlinArray<KtEnumLeftRightUpDown *> *)values __attribute__((swift_name("values()")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("EnumOneTwoThreeValues")))
@interface KtEnumOneTwoThreeValues : KtKotlinEnum<KtEnumOneTwoThreeValues *>
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
- (instancetype)initWithName:(NSString *)name ordinal:(int32_t)ordinal __attribute__((swift_name("init(name:ordinal:)"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable));
@property (class, readonly) KtEnumOneTwoThreeValues *one __attribute__((swift_name("one")));
@property (class, readonly) KtEnumOneTwoThreeValues *two __attribute__((swift_name("two")));
@property (class, readonly) KtEnumOneTwoThreeValues *three __attribute__((swift_name("three")));
@property (class, readonly) KtEnumOneTwoThreeValues *values __attribute__((swift_name("values")));
+ (KtKotlinArray<KtEnumOneTwoThreeValues *> *)values __attribute__((swift_name("values()")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("EnumValuesValues_")))
@interface KtEnumValuesValues_ : KtKotlinEnum<KtEnumValuesValues_ *>
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
- (instancetype)initWithName:(NSString *)name ordinal:(int32_t)ordinal __attribute__((swift_name("init(name:ordinal:)"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable));
@property (class, readonly) KtEnumValuesValues_ *values __attribute__((swift_name("values")));
@property (class, readonly) KtEnumValuesValues_ *values __attribute__((swift_name("values")));
+ (KtKotlinArray<KtEnumValuesValues_ *> *)values __attribute__((swift_name("values()")));
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("EmptyEnum")))
@interface KtEmptyEnum : KtKotlinEnum<KtEmptyEnum *>
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
- (instancetype)initWithName:(NSString *)name ordinal:(int32_t)ordinal __attribute__((swift_name("init(name:ordinal:)"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable));
+ (KtKotlinArray<KtEmptyEnum *> *)values __attribute__((swift_name("values()")));
@end;
__attribute__((swift_name("FHolder")))
@interface KtFHolder : KtBase
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
@@ -696,6 +742,7 @@ __attribute__((swift_name("Enumeration")))
@property (class, readonly) KtEnumeration *answer __attribute__((swift_name("answer")));
@property (class, readonly) KtEnumeration *year __attribute__((swift_name("year")));
@property (class, readonly) KtEnumeration *temperature __attribute__((swift_name("temperature")));
+ (KtKotlinArray<KtEnumeration *> *)values __attribute__((swift_name("values()")));
@property (readonly) int32_t enumValue __attribute__((swift_name("enumValue")));
@end;
@@ -1407,6 +1454,7 @@ __attribute__((swift_name("TestInvalidIdentifiers.E")))
@property (class, readonly) KtTestInvalidIdentifiersE *_5_ __attribute__((swift_name("_5_")));
@property (class, readonly) KtTestInvalidIdentifiersE *__ __attribute__((swift_name("__")));
@property (class, readonly) KtTestInvalidIdentifiersE *__ __attribute__((swift_name("__")));
+ (KtKotlinArray<KtTestInvalidIdentifiersE *> *)values __attribute__((swift_name("values()")));
@property (readonly) int32_t value __attribute__((swift_name("value")));
@end;