Index: test/file_generator_test.dart |
diff --git a/test/file_generator_test.dart b/test/file_generator_test.dart |
index 6a63842902c125c5230b50f940b54d3aee210484..d93c071b7515b0528cf86722ca1151bf21d8eb3d 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; |
@@ -102,17 +102,17 @@ class PhoneNumber extends GeneratedMessage { |
if (v is !PhoneNumber) checkItemFailed(v, 'PhoneNumber'); |
} |
- String get number => $_get(0, 1, ''); |
+ String get number => $_get(0, 1, '') as String; |
void set number(String v) { $_setString(0, 1, v); } |
bool hasNumber() => $_has(0, 1); |
void clearNumber() => clearField(1); |
- int get type => $_get(1, 2, 0); |
+ int get type => $_get(1, 2, 0) as int; |
void set type(int v) { $_setUnsignedInt32(1, 2, v); } |
bool hasType() => $_has(1, 2); |
void clearType() => clearField(2); |
- String get name => $_get(2, 3, '\$'); |
+ String get name => $_get(2, 3, '\$') as String; |
void set name(String v) { $_setString(2, 3, v); } |
bool hasName() => $_has(2, 3); |
void clearName() => clearField(3); |
@@ -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''' |
@@ -288,17 +286,17 @@ class PhoneNumber extends GeneratedMessage { |
if (v is !PhoneNumber) checkItemFailed(v, 'PhoneNumber'); |
} |
- String get no => $_get(0, 1, ''); |
+ String get no => $_get(0, 1, '') as String; |
void set no(String v) { $_setString(0, 1, v); } |
bool hasNo() => $_has(0, 1); |
void clearNo() => clearField(1); |
- int get the_type => $_get(1, 2, 0); |
+ int get the_type => $_get(1, 2, 0) as int; |
void set the_type(int v) { $_setUnsignedInt32(1, 2, v); } |
bool hasThe_type() => $_has(1, 2); |
void clearThe_type() => clearField(2); |
- String get name_ => $_get(2, 3, '\$'); |
+ String get name_ => $_get(2, 3, '\$') as String; |
void set name_(String v) { $_setString(2, 3, v); } |
bool hasName_() => $_has(2, 3); |
void clearName_() => clearField(3); |
@@ -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]); |
@@ -368,17 +365,17 @@ class M extends GeneratedMessage { |
if (v is !M) checkItemFailed(v, 'M'); |
} |
- M get m => $_get(0, 1, null); |
+ M get m => $_get(0, 1, null) as M; |
void set m(M v) { setField(1, v); } |
bool hasM() => $_has(0, 1); |
void clearM() => clearField(1); |
- p1.M get m1 => $_get(1, 2, null); |
+ p1.M get m1 => $_get(1, 2, null) as p1.M; |
void set m1(p1.M v) { setField(2, v); } |
bool hasM1() => $_has(1, 2); |
void clearM1() => clearField(2); |
- p2.M get m2 => $_get(2, 3, null); |
+ p2.M get m2 => $_get(2, 3, null) as p2.M; |
void set m2(p2.M v) { setField(3, v); } |
bool hasM2() => $_has(2, 3); |
void clearM2() => clearField(3); |
@@ -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(); |