mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 23:51:55 +08:00
[Pigeon] Fix Obj-C generation cast bug (#375)
This commit is contained in:
@ -446,7 +446,7 @@ static NSDictionary<NSString*, id>* wrapResult(NSDictionary *result, FlutterErro
|
||||
for (final Field field in klass.fields) {
|
||||
if (enumNames.contains(field.dataType)) {
|
||||
indent.writeln(
|
||||
'$resultName.${field.name} = (int)${_dictGetter(classNames, 'dict', field, options.prefix)};');
|
||||
'$resultName.${field.name} = [${_dictGetter(classNames, 'dict', field, options.prefix)} integerValue];');
|
||||
} else {
|
||||
indent.writeln(
|
||||
'$resultName.${field.name} = ${_dictGetter(classNames, 'dict', field, options.prefix)};');
|
||||
|
@ -69,6 +69,36 @@ void main() {
|
||||
expect(code, contains(' PREFIXEnum1Two = 1,'));
|
||||
});
|
||||
|
||||
test('gen one class source with enum', () {
|
||||
final Root root = Root(
|
||||
apis: <Api>[],
|
||||
classes: <Class>[
|
||||
Class(
|
||||
name: 'Foobar',
|
||||
fields: <Field>[
|
||||
Field(name: 'field1', dataType: 'String'),
|
||||
Field(name: 'enum1', dataType: 'Enum1'),
|
||||
],
|
||||
),
|
||||
],
|
||||
enums: <Enum>[
|
||||
Enum(
|
||||
name: 'Enum1',
|
||||
members: <String>[
|
||||
'one',
|
||||
'two',
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
final StringBuffer sink = StringBuffer();
|
||||
generateObjcSource(ObjcOptions(header: 'foo.h'), root, sink);
|
||||
final String code = sink.toString();
|
||||
expect(code, contains('#import "foo.h"'));
|
||||
expect(code, contains('@implementation Foobar'));
|
||||
expect(code, contains('result.enum1 = [dict[@"enum1"] integerValue];'));
|
||||
});
|
||||
|
||||
test('gen one api header', () {
|
||||
final Root root = Root(apis: <Api>[
|
||||
Api(name: 'Api', location: ApiLocation.host, methods: <Method>[
|
||||
|
Reference in New Issue
Block a user