Chromium Code Reviews| Index: test/file_generator_test.dart |
| diff --git a/test/file_generator_test.dart b/test/file_generator_test.dart |
| index bac4d150f78b397f97031c2fa2ce002bd1528d01..e4628cc0e5d10f8f9828d912ae502fd1aebc68f3 100644 |
| --- a/test/file_generator_test.dart |
| +++ b/test/file_generator_test.dart |
| @@ -297,8 +297,8 @@ import 'package:protobuf/protobuf.dart'; |
| expect(writer.toString(), expected); |
| }); |
| - test('FileGenerator outputs extra imports for a service', () { |
| - String expected = r''' |
| + test('FileGenerator outputs files for a service', () { |
| + String expectedClient = r''' |
| /// |
| // Generated code. Do not modify. |
| /// |
| @@ -308,12 +308,92 @@ import 'dart:async'; |
| import 'package:protobuf/protobuf.dart'; |
| +class Empty extends GeneratedMessage { |
| + static final BuilderInfo _i = new BuilderInfo('Empty') |
| + ..hasRequiredFields = false |
| + ; |
| + |
| + Empty() : super(); |
| + Empty.fromBuffer(List<int> i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromBuffer(i, r); |
| + Empty.fromJson(String i, [ExtensionRegistry r = ExtensionRegistry.EMPTY]) : super.fromJson(i, r); |
| + Empty clone() => new Empty()..mergeFromMessage(this); |
| + BuilderInfo get info_ => _i; |
| + static Empty create() => new Empty(); |
| + static PbList<Empty> createRepeated() => new PbList<Empty>(); |
| + static Empty getDefault() { |
| + if (_defaultInstance == null) _defaultInstance = new _ReadonlyEmpty(); |
| + return _defaultInstance; |
| + } |
| + static Empty _defaultInstance; |
| + static void $checkItem(Empty v) { |
| + if (v is !Empty) checkItemFailed(v, 'Empty'); |
| + } |
| +} |
| + |
| +class _ReadonlyEmpty extends Empty with ReadonlyMessageMixin {} |
| + |
| +class TestApi { |
|
Søren Gjesse
2016/05/27 07:34:35
Have you considered to also split out the client s
skybrian
2016/05/27 18:27:50
I considered it but I'm not sure it would accompli
|
| + RpcClient _client; |
| + TestApi(this._client); |
| + |
| + Future<Empty> ping(ClientContext ctx, Empty request) { |
| + var emptyResponse = new Empty(); |
| + return _client.invoke(ctx, 'Test', 'Ping', request, emptyResponse); |
| + } |
| +} |
| + |
| +'''; |
| + |
| + String expectedServer = r''' |
| +/// |
| +// Generated code. Do not modify. |
| +/// |
| +library test_pbserver; |
| + |
| +import 'dart:async'; |
| + |
| +import 'package:protobuf/protobuf.dart'; |
| + |
| +import 'test.pb.dart'; |
| + |
| import 'test.pbjson.dart'; |
| +abstract class TestServiceBase extends GeneratedService { |
| + Future<Empty> ping(ServerContext ctx, Empty request); |
| + |
| + GeneratedMessage createRequest(String method) { |
| + switch (method) { |
| + case 'Ping': return new Empty(); |
| + default: throw new ArgumentError('Unknown method: $method'); |
| + } |
| + } |
| + |
| + Future<GeneratedMessage> handleCall(ServerContext ctx, String method, GeneratedMessage request) { |
| + switch (method) { |
| + case 'Ping': return ping(ctx, request); |
| + default: throw new ArgumentError('Unknown method: $method'); |
| + } |
| + } |
| + |
| + Map<String, dynamic> get $json => Test$json; |
| + Map<String, dynamic> get $messageJson => Test$messageJson; |
| +} |
| + |
| '''; |
| + |
| + DescriptorProto empty = new DescriptorProto()..name = "Empty"; |
| + |
| + ServiceDescriptorProto sd = new ServiceDescriptorProto() |
| + ..name = 'Test' |
| + ..method.add(new MethodDescriptorProto() |
| + ..name = 'Ping' |
| + ..inputType = '.Empty' |
| + ..outputType = '.Empty'); |
| + |
| FileDescriptorProto fd = new FileDescriptorProto() |
| ..name = 'test' |
| - ..service.add(new ServiceDescriptorProto()); |
| + ..messageType.add(empty) |
| + ..service.add(sd); |
| var options = parseGenerationOptions( |
| new CodeGeneratorRequest(), new CodeGeneratorResponse()); |
| @@ -323,7 +403,8 @@ import 'test.pbjson.dart'; |
| var writer = new IndentingWriter(); |
| fg.writeMainHeader(writer); |
| - expect(writer.toString(), expected); |
| + expect(fg.generateMainFile(), expectedClient); |
| + expect(fg.generateServerFile(), expectedServer); |
| }); |
| test('FileGenerator handles field_name options', () { |