Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: test/file_generator_test.dart

Issue 1829573002: Fix all strong mode warnings in protoc-plugin (Closed) Base URL: git@github.com:dart-lang/dart-protoc-plugin.git@master
Patch Set: regenerate pb.dart files Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/enum_generator_test.dart ('k') | test/generated_message_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/file_generator_test.dart
diff --git a/test/file_generator_test.dart b/test/file_generator_test.dart
index 6a63842902c125c5230b50f940b54d3aee210484..0ec58963eba0d75d2fe00011681d9ea95f3a5da3 100644
--- a/test/file_generator_test.dart
+++ b/test/file_generator_test.dart
@@ -13,56 +13,56 @@ import 'package:test/test.dart';
FileDescriptorProto buildFileDescriptor(
{phoneNumber: true, topLevelEnum: false}) {
-
- FileDescriptorProto fd = new FileDescriptorProto()
- ..name = 'test';
+ FileDescriptorProto fd = new FileDescriptorProto()..name = 'test';
if (topLevelEnum) {
fd.enumType.add(new EnumDescriptorProto()
..name = 'PhoneType'
..value.addAll([
- new EnumValueDescriptorProto()
- ..name = 'MOBILE'
- ..number = 0,
- new EnumValueDescriptorProto()
- ..name = 'HOME'
- ..number = 1,
- new EnumValueDescriptorProto()
- ..name = 'WORK'
- ..number = 2,
- new EnumValueDescriptorProto()
- ..name = 'BUSINESS'
- ..number = 2]));
+ new EnumValueDescriptorProto()
+ ..name = 'MOBILE'
+ ..number = 0,
+ new EnumValueDescriptorProto()
+ ..name = 'HOME'
+ ..number = 1,
+ new EnumValueDescriptorProto()
+ ..name = 'WORK'
+ ..number = 2,
+ new EnumValueDescriptorProto()
+ ..name = 'BUSINESS'
+ ..number = 2
+ ]));
}
if (phoneNumber) {
fd.messageType.add(new DescriptorProto()
..name = 'PhoneNumber'
..field.addAll([
- // required string number = 1;
- new FieldDescriptorProto()
- ..name = 'number'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_REQUIRED
- ..type = FieldDescriptorProto_Type.TYPE_STRING,
- // optional int32 type = 2;
- // OR
- // optional PhoneType type = 2;
- new FieldDescriptorProto()
- ..name = 'type'
- ..number = 2
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = topLevelEnum ? FieldDescriptorProto_Type.TYPE_ENUM
- : FieldDescriptorProto_Type.TYPE_INT32
- ..typeName = topLevelEnum ? '.PhoneType' : '',
- // optional string name = 3 [default = "$"];
- new FieldDescriptorProto()
- ..name = 'name'
- ..number = 3
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_STRING
- ..defaultValue = r'$'
- ]));
+ // required string number = 1;
+ new FieldDescriptorProto()
+ ..name = 'number'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_REQUIRED
+ ..type = FieldDescriptorProto_Type.TYPE_STRING,
+ // optional int32 type = 2;
+ // OR
+ // optional PhoneType type = 2;
+ new FieldDescriptorProto()
+ ..name = 'type'
+ ..number = 2
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = topLevelEnum
+ ? FieldDescriptorProto_Type.TYPE_ENUM
+ : FieldDescriptorProto_Type.TYPE_INT32
+ ..typeName = topLevelEnum ? '.PhoneType' : '',
+ // optional string name = 3 [default = "$"];
+ new FieldDescriptorProto()
+ ..name = 'name'
+ ..number = 3
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_STRING
+ ..defaultValue = r'$'
+ ]));
}
return fd;
@@ -81,9 +81,9 @@ import 'package:protobuf/protobuf.dart';
class PhoneNumber extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('PhoneNumber')
- ..a(1, 'number', PbFieldType.QS)
- ..a(2, 'type', PbFieldType.O3)
- ..a(3, 'name', PbFieldType.OS, '\$')
+ ..a/*<String>*/(1, 'number', PbFieldType.QS)
+ ..a/*<int>*/(2, 'type', PbFieldType.O3)
+ ..a/*<String>*/(3, 'name', PbFieldType.OS, '\$')
;
PhoneNumber() : super();
@@ -164,8 +164,8 @@ class PhoneType extends ProtobufEnum {
WORK,
];
- static final Map<int, PhoneType> _byValue = ProtobufEnum.initByValue(values);
- static PhoneType valueOf(int value) => _byValue[value];
+ static final Map<int, dynamic> _byValue = ProtobufEnum.initByValue(values);
+ static PhoneType valueOf(int value) => _byValue[value] as PhoneType;
static void $checkItem(PhoneType v) {
if (v is !PhoneType) checkItemFailed(v, 'PhoneType');
}
@@ -184,9 +184,8 @@ const PhoneType$json = const {
};
''';
- FileDescriptorProto fd = buildFileDescriptor(
- phoneNumber: false,
- topLevelEnum: true);
+ FileDescriptorProto fd =
+ buildFileDescriptor(phoneNumber: false, topLevelEnum: true);
var options = parseGenerationOptions(
new CodeGeneratorRequest(), new CodeGeneratorResponse());
@@ -235,13 +234,13 @@ import 'package:protobuf/protobuf.dart';
FileDescriptorProto fd = new FileDescriptorProto()
..name = 'test'
..messageType.add(new DescriptorProto()
- ..name = 'Count'
- ..field.addAll([
- new FieldDescriptorProto()
- ..name = 'count'
- ..number = 1
- ..type = FieldDescriptorProto_Type.TYPE_INT64
- ]));
+ ..name = 'Count'
+ ..field.addAll([
+ new FieldDescriptorProto()
+ ..name = 'count'
+ ..number = 1
+ ..type = FieldDescriptorProto_Type.TYPE_INT64
+ ]));
var options = parseGenerationOptions(
new CodeGeneratorRequest(), new CodeGeneratorResponse());
@@ -254,7 +253,6 @@ import 'package:protobuf/protobuf.dart';
expect(writer.toString(), expected);
});
-
test('FileGenerator handles field_name options', () {
// NOTE: Below > 80 cols because it is matching generated code > 80 cols.
String expected = r'''
@@ -267,9 +265,9 @@ import 'package:protobuf/protobuf.dart';
class PhoneNumber extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('PhoneNumber')
- ..a(1, 'no', PbFieldType.QS)
- ..a(2, 'the_type', PbFieldType.O3)
- ..a(3, 'name_', PbFieldType.OS, '\$')
+ ..a/*<String>*/(1, 'no', PbFieldType.QS)
+ ..a/*<int>*/(2, 'the_type', PbFieldType.O3)
+ ..a/*<String>*/(3, 'name_', PbFieldType.OS, '\$')
;
PhoneNumber() : super();
@@ -319,10 +317,9 @@ const PhoneNumber$json = const {
FileDescriptorProto fd = buildFileDescriptor();
var request = new CodeGeneratorRequest();
request.parameter = 'field_name=PhoneNumber.number|No,'
- 'field_name=PhoneNumber.name|Name_,'
- 'field_name=PhoneNumber.type|The_type';
- var options = parseGenerationOptions(
- request, new CodeGeneratorResponse());
+ 'field_name=PhoneNumber.name|Name_,'
+ 'field_name=PhoneNumber.type|The_type';
+ var options = parseGenerationOptions(request, new CodeGeneratorResponse());
FileGenerator fg = new FileGenerator(fd);
link(options, [fg]);
@@ -346,9 +343,9 @@ import 'package2.pb.dart' as p2;
class M extends GeneratedMessage {
static final BuilderInfo _i = new BuilderInfo('M')
- ..a(1, 'm', PbFieldType.OM, M.getDefault, M.create)
- ..a(2, 'm1', PbFieldType.OM, p1.M.getDefault, p1.M.create)
- ..a(3, 'm2', PbFieldType.OM, p2.M.getDefault, p2.M.create)
+ ..a/*<M>*/(1, 'm', PbFieldType.OM, M.getDefault, M.create)
+ ..a/*<p1.M>*/(2, 'm1', PbFieldType.OM, p1.M.getDefault, p1.M.create)
+ ..a/*<p2.M>*/(3, 'm2', PbFieldType.OM, p2.M.getDefault, p2.M.create)
..hasRequiredFields = false
;
@@ -427,67 +424,67 @@ const M$json = const {
// Description of package1.proto.
DescriptorProto md1 = new DescriptorProto()
- ..name = 'M'
- ..field.addAll([
- // optional M m = 1;
- new FieldDescriptorProto()
- ..name = 'm'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".p1.M",
- ]);
+ ..name = 'M'
+ ..field.addAll([
+ // optional M m = 1;
+ new FieldDescriptorProto()
+ ..name = 'm'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".p1.M",
+ ]);
FileDescriptorProto fd1 = new FileDescriptorProto()
- ..package = 'p1'
- ..name = 'package1.proto'
- ..messageType.add(md1);
+ ..package = 'p1'
+ ..name = 'package1.proto'
+ ..messageType.add(md1);
// Description of package1.proto.
DescriptorProto md2 = new DescriptorProto()
- ..name = 'M'
- ..field.addAll([
- // optional M m = 1;
- new FieldDescriptorProto()
- ..name = 'x'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".p2.M",
- ]);
+ ..name = 'M'
+ ..field.addAll([
+ // optional M m = 1;
+ new FieldDescriptorProto()
+ ..name = 'x'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".p2.M",
+ ]);
FileDescriptorProto fd2 = new FileDescriptorProto()
- ..package = 'p2'
- ..name = 'package2.proto'
- ..messageType.add(md2);
+ ..package = 'p2'
+ ..name = 'package2.proto'
+ ..messageType.add(md2);
// Description of test.proto.
DescriptorProto md = new DescriptorProto()
- ..name = 'M'
- ..field.addAll([
- // optional M m = 1;
- new FieldDescriptorProto()
- ..name = 'm'
- ..number = 1
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".M",
- // optional p1.M m1 = 2;
- new FieldDescriptorProto()
- ..name = 'm1'
- ..number = 2
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".p1.M",
- // optional p2.M m2 = 3;
- new FieldDescriptorProto()
- ..name = 'm2'
- ..number = 3
- ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
- ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
- ..typeName = ".p2.M",
- ]);
+ ..name = 'M'
+ ..field.addAll([
+ // optional M m = 1;
+ new FieldDescriptorProto()
+ ..name = 'm'
+ ..number = 1
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".M",
+ // optional p1.M m1 = 2;
+ new FieldDescriptorProto()
+ ..name = 'm1'
+ ..number = 2
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".p1.M",
+ // optional p2.M m2 = 3;
+ new FieldDescriptorProto()
+ ..name = 'm2'
+ ..number = 3
+ ..label = FieldDescriptorProto_Label.LABEL_OPTIONAL
+ ..type = FieldDescriptorProto_Type.TYPE_MESSAGE
+ ..typeName = ".p2.M",
+ ]);
FileDescriptorProto fd = new FileDescriptorProto()
- ..name = 'test.proto'
- ..messageType.add(md);
+ ..name = 'test.proto'
+ ..messageType.add(md);
fd.dependency.addAll(['package1.proto', 'package2.proto']);
var request = new CodeGeneratorRequest();
var response = new CodeGeneratorResponse();
« no previous file with comments | « test/enum_generator_test.dart ('k') | test/generated_message_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698