File tree Expand file tree Collapse file tree 5 files changed +63
-4
lines changed Expand file tree Collapse file tree 5 files changed +63
-4
lines changed Original file line number Diff line number Diff line change
1
+ ## 4.2.4
2
+
3
+ * [ dart] Fixes enum parameter handling in Dart test API class.
4
+
1
5
## 4.2.3
2
6
3
7
* [ java] Adds assert ` args != null ` .
Original file line number Diff line number Diff line change @@ -276,6 +276,8 @@ void _writeFlutterApi(
276
276
bool isMockHandler = false ,
277
277
}) {
278
278
assert (api.location == ApiLocation .flutter);
279
+ final List <String > customEnumNames =
280
+ root.enums.map ((Enum x) => x.name).toList ();
279
281
String codecName = _standardMessageCodec;
280
282
if (getCodecClasses (api, root).isNotEmpty) {
281
283
codecName = _getCodecName (api);
@@ -358,8 +360,14 @@ void _writeFlutterApi(
358
360
_makeGenericTypeArguments (arg.type);
359
361
final String castCall = _makeGenericCastCall (arg.type);
360
362
361
- indent.writeln (
362
- 'final $argType ? $argName = ($argsArray [$count ] as $genericArgType ?)${castCall .isEmpty ? '' : '?$castCall ' };' );
363
+ final String leftHandSide = 'final $argType ? $argName ' ;
364
+ if (customEnumNames.contains (arg.type.baseName)) {
365
+ indent.writeln (
366
+ '$leftHandSide = $argsArray [$count ] == null ? null : $argType .values[$argsArray [$count ] as int];' );
367
+ } else {
368
+ indent.writeln (
369
+ '$leftHandSide = ($argsArray [$count ] as $genericArgType ?)${castCall .isEmpty ? '' : '?$castCall ' };' );
370
+ }
363
371
if (! arg.type.isNullable) {
364
372
indent.writeln (
365
373
"assert($argName != null, 'Argument for $channelName was null, expected non-null $argType .');" );
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import 'dart:mirrors';
9
9
import 'ast.dart' ;
10
10
11
11
/// The current version of pigeon. This must match the version in pubspec.yaml.
12
- const String pigeonVersion = '4.2.3 ' ;
12
+ const String pigeonVersion = '4.2.4 ' ;
13
13
14
14
/// Read all the content from [stdin] to a String.
15
15
String readStdin () {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ name: pigeon
2
2
description : Code generator tool to make communication between Flutter and the host platform type-safe and easier.
3
3
repository : https://github.com/flutter/packages/tree/main/packages/pigeon
4
4
issue_tracker : https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
5
- version : 4.2.3 # This must match the version in lib/generator_tools.dart
5
+ version : 4.2.4 # This must match the version in lib/generator_tools.dart
6
6
7
7
environment :
8
8
sdk : " >=2.12.0 <3.0.0"
Original file line number Diff line number Diff line change @@ -1309,4 +1309,51 @@ name: foobar
1309
1309
final String code = sink.toString ();
1310
1310
expect (code, contains ('extends StandardMessageCodec' ));
1311
1311
});
1312
+
1313
+ test ('host test code handles enums' , () {
1314
+ final Root root = Root (
1315
+ apis: < Api > [
1316
+ Api (
1317
+ name: 'Api' ,
1318
+ location: ApiLocation .host,
1319
+ dartHostTestHandler: 'ApiMock' ,
1320
+ methods: < Method > [
1321
+ Method (
1322
+ name: 'doit' ,
1323
+ returnType: const TypeDeclaration .voidDeclaration (),
1324
+ arguments: < NamedType > [
1325
+ NamedType (
1326
+ type: const TypeDeclaration (
1327
+ baseName: 'Enum' ,
1328
+ isNullable: false ,
1329
+ ),
1330
+ name: 'anEnum' )
1331
+ ])
1332
+ ])
1333
+ ],
1334
+ classes: < Class > [],
1335
+ enums: < Enum > [
1336
+ Enum (
1337
+ name: 'Enum' ,
1338
+ members: < String > [
1339
+ 'one' ,
1340
+ 'two' ,
1341
+ ],
1342
+ )
1343
+ ],
1344
+ );
1345
+ final StringBuffer sink = StringBuffer ();
1346
+ generateTestDart (
1347
+ const DartOptions (),
1348
+ root,
1349
+ sink,
1350
+ dartOutPath: 'code.dart' ,
1351
+ testOutPath: 'test.dart' ,
1352
+ );
1353
+ final String testCode = sink.toString ();
1354
+ expect (
1355
+ testCode,
1356
+ contains (
1357
+ 'final Enum? arg_anEnum = args[0] == null ? null : Enum.values[args[0] as int]' ));
1358
+ });
1312
1359
}
You can’t perform that action at this time.
0 commit comments