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 protoc_options_test; | 6 library protoc_options_test; |
7 | 7 |
8 import 'package:protoc_plugin/src/plugin.pb.dart'; | 8 import 'package:protoc_plugin/src/plugin.pb.dart'; |
9 import 'package:protoc_plugin/protoc.dart'; | 9 import 'package:protoc_plugin/protoc.dart'; |
10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
11 | 11 |
12 | |
13 void main() { | 12 void main() { |
14 test('testValidGeneratorOptions', () { | 13 test('testValidGeneratorOptions', () { |
15 checkValid(String parameter, Map expected) { | 14 checkValid(String parameter) { |
16 var request = new CodeGeneratorRequest(); | 15 var request = new CodeGeneratorRequest(); |
17 if (parameter != null) request.parameter = parameter; | 16 if (parameter != null) request.parameter = parameter; |
18 var response = new CodeGeneratorResponse(); | 17 var response = new CodeGeneratorResponse(); |
19 var options = parseGenerationOptions(request, response); | 18 var options = parseGenerationOptions(request, response); |
20 expect(options, new isInstanceOf<GenerationOptions>()); | 19 expect(options, new isInstanceOf<GenerationOptions>()); |
21 expect(response.error, ''); | 20 expect(response.error, ''); |
22 expect(options.fieldNameOverrides, equals(expected)); | |
23 } | 21 } |
24 | 22 |
25 checkValid(null, {}); | 23 checkValid(null); |
26 checkValid('', {}); | 24 checkValid(''); |
27 checkValid(',', {}); | 25 checkValid(','); |
28 checkValid(',,,', {}); | 26 checkValid(',,,'); |
29 checkValid(' , , ,', {}); | 27 checkValid(' , , ,'); |
30 | |
31 checkValid('field_name=a|b', {'.a' : 'b'}); | |
32 checkValid('field_name = a | b,,,', {'.a' : 'b'}); | |
33 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 ', | |
35 {'.a' : 'b', '.p.C' : 'd'}); | |
36 }); | 28 }); |
37 | 29 |
38 test('testInvalidGeneratorOptions', () { | 30 test('testInvalidGeneratorOptions', () { |
39 checkInvalid(String parameter) { | 31 checkInvalid(String parameter) { |
40 var request = new CodeGeneratorRequest(); | 32 var request = new CodeGeneratorRequest(); |
41 if (parameter != null) request.parameter = parameter; | 33 if (parameter != null) request.parameter = parameter; |
42 var response = new CodeGeneratorResponse(); | 34 var response = new CodeGeneratorResponse(); |
43 var options = parseGenerationOptions(request, response); | 35 var options = parseGenerationOptions(request, response); |
44 expect(options, isNull); | 36 expect(options, isNull); |
45 } | 37 } |
46 | 38 |
47 checkInvalid('abc'); | 39 checkInvalid('abc'); |
48 checkInvalid('abc,def'); | 40 checkInvalid('abc,def'); |
49 checkInvalid('field_name='); | |
50 checkInvalid('field_name=a'); | |
51 checkInvalid('field_name=a|'); | |
52 checkInvalid('field_name=|'); | |
53 checkInvalid('field_name=|b'); | |
54 }); | 41 }); |
55 } | 42 } |
OLD | NEW |