forked from google/protobuf.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes google#849.
- Loading branch information
Showing
4 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
syntax = "proto3"; | ||
|
||
enum A { | ||
X = 0; | ||
Y = 1; | ||
} | ||
|
||
message Message { | ||
A enum_field = 1; | ||
map<int32, A> map_value_field = 2; | ||
repeated A repeated_enum_field = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:test/test.dart'; | ||
|
||
import '../out/protos/enum_test.pb.dart'; | ||
|
||
void main() { | ||
group('Enum parsing in maps, lists, messages', () { | ||
test('Parse known fields', () { | ||
final json = { | ||
'enumField': 'Y', | ||
'mapValueField': {'1': 'Y'}, | ||
'repeatedEnumField': ['Y'], | ||
}; | ||
|
||
final msg = Message(); | ||
msg.mergeFromProto3Json(json); | ||
expect(msg.enumField, A.Y); | ||
expect(msg.mapValueField.values.toList(), [A.Y]); | ||
expect(msg.repeatedEnumField, [A.Y]); | ||
}); | ||
|
||
test('Skip unknown fields', () { | ||
final json = { | ||
'enumField': 'Z', | ||
'mapValueField': {'1': 'X', '2': 'Z', '3': 'Y'}, | ||
'repeatedEnumField': ['X', 'Z', 'Y'], | ||
}; | ||
|
||
final msg = Message(); | ||
msg.enumField = A.Y; | ||
msg.mergeFromProto3Json(json, ignoreUnknownFields: true); | ||
expect(msg.enumField, A.Y); | ||
expect(msg.mapValueField.values.toList(), [A.X, A.Y]); | ||
expect(msg.repeatedEnumField, [A.X, A.Y]); | ||
}); | ||
}); | ||
} |