| OLD | NEW |
| 1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
| 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 library file_generator_test; | 6 library file_generator_test; |
| 7 | 7 |
| 8 import 'package:protoc-plugin/src/descriptor.pb.dart'; | 8 import 'package:protoc_plugin/src/descriptor.pb.dart'; |
| 9 import 'package:protoc-plugin/src/plugin.pb.dart'; | 9 import 'package:protoc_plugin/src/plugin.pb.dart'; |
| 10 import 'package:protoc-plugin/protoc.dart'; | 10 import 'package:protoc_plugin/protoc.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 | 13 |
| 14 void main() { | 14 void main() { |
| 15 test('testValidGeneratorOptions', () { | 15 test('testValidGeneratorOptions', () { |
| 16 checkValid(String parameter, Map expected) { | 16 checkValid(String parameter, Map expected) { |
| 17 var request = new CodeGeneratorRequest(); | 17 var request = new CodeGeneratorRequest(); |
| 18 if (parameter != null) request.parameter = parameter; | 18 if (parameter != null) request.parameter = parameter; |
| 19 var response = new CodeGeneratorResponse(); | 19 var response = new CodeGeneratorResponse(); |
| 20 var options = new GenerationOptions(request, response); | 20 var options = parseGenerationOptions(request, response); |
| 21 expect(options, new isInstanceOf<GenerationOptions>()); | 21 expect(options, new isInstanceOf<GenerationOptions>()); |
| 22 expect(response.error, ''); | 22 expect(response.error, ''); |
| 23 expect(options.fieldNameOptions, equals(expected)); | 23 expect(options.fieldNameOverrides, equals(expected)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 checkValid(null, {}); | 26 checkValid(null, {}); |
| 27 checkValid('', {}); | 27 checkValid('', {}); |
| 28 checkValid(',', {}); | 28 checkValid(',', {}); |
| 29 checkValid(',,,', {}); | 29 checkValid(',,,', {}); |
| 30 checkValid(' , , ,', {}); | 30 checkValid(' , , ,', {}); |
| 31 | 31 |
| 32 checkValid('field_name=a|b', {'.a' : 'b'}); | 32 checkValid('field_name=a|b', {'.a' : 'b'}); |
| 33 checkValid('field_name = a | b,,,', {'.a' : 'b'}); | 33 checkValid('field_name = a | b,,,', {'.a' : 'b'}); |
| 34 checkValid('field_name=a|b,field_name=p.C|d', {'.a' : 'b', '.p.C' : 'd'}); | 34 checkValid('field_name=a|b,field_name=p.C|d', {'.a' : 'b', '.p.C' : 'd'}); |
| 35 checkValid(' field_name = a | b, , field_name = p.C | d ', | 35 checkValid(' field_name = a | b, , field_name = p.C | d ', |
| 36 {'.a' : 'b', '.p.C' : 'd'}); | 36 {'.a' : 'b', '.p.C' : 'd'}); |
| 37 }); | 37 }); |
| 38 | 38 |
| 39 test('testInvalidGeneratorOptions', () { | 39 test('testInvalidGeneratorOptions', () { |
| 40 checkInvalid(String parameter) { | 40 checkInvalid(String parameter) { |
| 41 var request = new CodeGeneratorRequest(); | 41 var request = new CodeGeneratorRequest(); |
| 42 if (parameter != null) request.parameter = parameter; | 42 if (parameter != null) request.parameter = parameter; |
| 43 var response = new CodeGeneratorResponse(); | 43 var response = new CodeGeneratorResponse(); |
| 44 var options = new GenerationOptions(request, response); | 44 var options = parseGenerationOptions(request, response); |
| 45 expect(options, isNull); | 45 expect(options, isNull); |
| 46 } | 46 } |
| 47 | 47 |
| 48 checkInvalid('abc'); | 48 checkInvalid('abc'); |
| 49 checkInvalid('abc,def'); | 49 checkInvalid('abc,def'); |
| 50 checkInvalid('field_name='); | 50 checkInvalid('field_name='); |
| 51 checkInvalid('field_name=a'); | 51 checkInvalid('field_name=a'); |
| 52 checkInvalid('field_name=a|'); | 52 checkInvalid('field_name=a|'); |
| 53 checkInvalid('field_name=|'); | 53 checkInvalid('field_name=|'); |
| 54 checkInvalid('field_name=|b'); | 54 checkInvalid('field_name=|b'); |
| 55 }); | 55 }); |
| 56 } | 56 } |
| OLD | NEW |