mirror of
https://github.com/flutter/packages.git
synced 2025-07-03 09:08:54 +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) {
|
for (final Field field in klass.fields) {
|
||||||
if (enumNames.contains(field.dataType)) {
|
if (enumNames.contains(field.dataType)) {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'$resultName.${field.name} = (int)${_dictGetter(classNames, 'dict', field, options.prefix)};');
|
'$resultName.${field.name} = [${_dictGetter(classNames, 'dict', field, options.prefix)} integerValue];');
|
||||||
} else {
|
} else {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'$resultName.${field.name} = ${_dictGetter(classNames, 'dict', field, options.prefix)};');
|
'$resultName.${field.name} = ${_dictGetter(classNames, 'dict', field, options.prefix)};');
|
||||||
|
@ -69,6 +69,36 @@ void main() {
|
|||||||
expect(code, contains(' PREFIXEnum1Two = 1,'));
|
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', () {
|
test('gen one api header', () {
|
||||||
final Root root = Root(apis: <Api>[
|
final Root root = Root(apis: <Api>[
|
||||||
Api(name: 'Api', location: ApiLocation.host, methods: <Method>[
|
Api(name: 'Api', location: ApiLocation.host, methods: <Method>[
|
||||||
|
Reference in New Issue
Block a user