OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library test.src.plugin.plugin_config_test; | 5 library test.src.plugin.plugin_config_test; |
6 | 6 |
7 import 'package:analyzer/source/analysis_options_provider.dart'; | 7 import 'package:analyzer/source/analysis_options_provider.dart'; |
8 import 'package:analyzer/src/plugin/plugin_configuration.dart'; | 8 import 'package:analyzer/src/plugin/plugin_configuration.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 import 'package:yaml/yaml.dart'; | |
10 | 11 |
11 main() { | 12 main() { |
12 group('PluginConfig', () { | 13 group('plugin config tests', () { |
13 group('parsing', () { | 14 group('parsing', () { |
14 test('plugin map', () { | 15 test('plugin map', () { |
15 const optionsSrc = ''' | 16 const optionsSrc = ''' |
16 analyzer: | 17 analyzer: |
17 plugins: | 18 plugins: |
18 my_plugin1: ^0.1.0 #shorthand | 19 my_plugin1: ^0.1.0 #shorthand |
19 my_plugin2: | 20 my_plugin2: |
20 version: ^0.2.0 | 21 version: ^0.2.0 |
21 my_plugin3: | 22 my_plugin3: |
22 class_name: MyPlugin | 23 class_name: MyPlugin |
23 library_uri: myplugin/myplugin.dart | 24 library_uri: myplugin/myplugin.dart |
24 path: '/u/disk/src/' | 25 path: '/u/disk/src/' |
25 '''; | 26 '''; |
26 var config = parseConfig(optionsSrc); | 27 var config = parseConfig(optionsSrc); |
27 var plugins = pluginsSortedByName(config); | 28 var plugins = pluginsSortedByName(config); |
28 expect(plugins, hasLength(3)); | 29 expect(plugins, hasLength(3)); |
29 expect(plugins[0].name, equals('my_plugin1')); | 30 expect(plugins[0].name, equals('my_plugin1')); |
30 expect(plugins[0].version, equals('^0.1.0')); | 31 expect(plugins[0].version, equals('^0.1.0')); |
31 expect(plugins[1].name, equals('my_plugin2')); | 32 expect(plugins[1].name, equals('my_plugin2')); |
32 expect(plugins[1].version, equals('^0.2.0')); | 33 expect(plugins[1].version, equals('^0.2.0')); |
33 expect(plugins[2].name, equals('my_plugin3')); | 34 expect(plugins[2].name, equals('my_plugin3')); |
34 expect(plugins[2].version, isNull); | 35 expect(plugins[2].version, isNull); |
35 expect(plugins[2].path, equals('/u/disk/src/')); | 36 expect(plugins[2].path, equals('/u/disk/src/')); |
36 expect(plugins[2].libraryUri, equals('myplugin/myplugin.dart')); | 37 expect(plugins[2].libraryUri, equals('myplugin/myplugin.dart')); |
37 expect(plugins[2].className, equals('MyPlugin')); | 38 expect(plugins[2].className, equals('MyPlugin')); |
38 }); | 39 }); |
40 test('plugin map (empty)', () { | |
41 const optionsSrc = ''' | |
42 analyzer: | |
43 plugins: | |
44 # my_plugin1: ^0.1.0 #shorthand | |
45 '''; | |
46 var config = parseConfig(optionsSrc); | |
47 // Commented out plugins shouldn't cause a parse failure. | |
48 expect(config.plugins.toList(), hasLength(0)); | |
scheglov
2015/09/23 17:10:49
Do you need this toList() invocation?
AFAIK hasLen
| |
49 }); | |
50 group('errors', () { | |
51 test('bad format', () { | |
52 const optionsSrc = ''' | |
53 analyzer: | |
54 plugins: | |
55 - my_plugin1 | |
56 - my_plugin2 | |
57 '''; | |
58 try { | |
59 parseConfig(optionsSrc); | |
60 fail('expected PluginConfigFormatException'); | |
61 } on PluginConfigFormatException catch (e) { | |
62 expect( | |
63 e.message, | |
64 equals( | |
65 'Unrecognized plugin config format (expected `YamlMap`, got `YamlList`)')); | |
66 expect(e.yamlNode, new isInstanceOf<YamlList>()); | |
67 } | |
68 }); | |
69 }); | |
39 }); | 70 }); |
40 }); | 71 }); |
41 } | 72 } |
42 | 73 |
43 PluginConfig parseConfig(String optionsSrc) { | 74 PluginConfig parseConfig(String optionsSrc) { |
44 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc); | 75 var options = new AnalysisOptionsProvider().getOptionsFromString(optionsSrc); |
45 return new PluginConfig.fromOptions(options); | 76 return new PluginConfig.fromOptions(options); |
46 } | 77 } |
47 | 78 |
48 List<PluginInfo> pluginsSortedByName(PluginConfig config) => | 79 List<PluginInfo> pluginsSortedByName(PluginConfig config) => |
49 config.plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name)); | 80 config.plugins.toList()..sort((p1, p2) => p1.name.compareTo(p2.name)); |
OLD | NEW |