| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.operation; |
| 6 |
| 7 import 'package:analysis_server/plugin/plugin.dart'; |
| 8 import 'package:analysis_server/src/plugin/plugin_impl.dart'; |
| 9 import 'package:unittest/unittest.dart'; |
| 10 |
| 11 main() { |
| 12 groupSep = ' | '; |
| 13 |
| 14 group('ExtensionManager', () { |
| 15 test('processPlugins', () { |
| 16 TestPlugin plugin1 = new TestPlugin('plugin1'); |
| 17 TestPlugin plugin2 = new TestPlugin('plugin1'); |
| 18 ExtensionManager manager = new ExtensionManager(); |
| 19 manager.processPlugins([plugin1, plugin2]); |
| 20 expect(plugin1.extensionPointsRegistered, true); |
| 21 expect(plugin1.extensionsRegistered, true); |
| 22 expect(plugin2.extensionPointsRegistered, true); |
| 23 expect(plugin2.extensionsRegistered, true); |
| 24 }); |
| 25 |
| 26 test('registerExtension - valid', () { |
| 27 Plugin plugin = new TestPlugin('plugin'); |
| 28 ExtensionManager manager = new ExtensionManager(); |
| 29 ExtensionPoint point = |
| 30 manager.registerExtensionPoint(plugin, 'point', null); |
| 31 expect(point, isNotNull); |
| 32 Object extension = 'extension'; |
| 33 manager.registerExtension('plugin.point', extension); |
| 34 List<Object> extensions = point.extensions; |
| 35 expect(extensions, isNotNull); |
| 36 expect(extensions, hasLength(1)); |
| 37 expect(extensions[0], extension); |
| 38 }); |
| 39 |
| 40 test('registerExtension - non existent', () { |
| 41 ExtensionManager manager = new ExtensionManager(); |
| 42 expect( |
| 43 () => manager.registerExtension('does not exist', 'extension'), |
| 44 throwsA(new isInstanceOf<ExtensionError>())); |
| 45 ; |
| 46 }); |
| 47 |
| 48 test('registerExtensionPoint - non-conflicting', () { |
| 49 Plugin plugin1 = new TestPlugin('plugin1'); |
| 50 Plugin plugin2 = new TestPlugin('plugin2'); |
| 51 ExtensionManager manager = new ExtensionManager(); |
| 52 expect( |
| 53 manager.registerExtensionPoint(plugin1, 'point1', null), |
| 54 isNotNull); |
| 55 expect( |
| 56 manager.registerExtensionPoint(plugin1, 'point2', null), |
| 57 isNotNull); |
| 58 expect( |
| 59 manager.registerExtensionPoint(plugin2, 'point1', null), |
| 60 isNotNull); |
| 61 expect( |
| 62 manager.registerExtensionPoint(plugin2, 'point2', null), |
| 63 isNotNull); |
| 64 }); |
| 65 |
| 66 test('registerExtensionPoint - conflicting - same plugin', () { |
| 67 Plugin plugin1 = new TestPlugin('plugin1'); |
| 68 ExtensionManager manager = new ExtensionManager(); |
| 69 expect( |
| 70 manager.registerExtensionPoint(plugin1, 'point1', null), |
| 71 isNotNull); |
| 72 expect( |
| 73 () => manager.registerExtensionPoint(plugin1, 'point1', null), |
| 74 throwsA(new isInstanceOf<ExtensionError>())); |
| 75 }); |
| 76 |
| 77 test('registerExtensionPoint - conflicting - different plugins', () { |
| 78 Plugin plugin1 = new TestPlugin('plugin1'); |
| 79 Plugin plugin2 = new TestPlugin('plugin1'); |
| 80 ExtensionManager manager = new ExtensionManager(); |
| 81 expect( |
| 82 manager.registerExtensionPoint(plugin1, 'point1', null), |
| 83 isNotNull); |
| 84 expect( |
| 85 () => manager.registerExtensionPoint(plugin2, 'point1', null), |
| 86 throwsA(new isInstanceOf<ExtensionError>())); |
| 87 }); |
| 88 }); |
| 89 |
| 90 group('ExtensionPointImpl', () { |
| 91 test('extensions - empty', () { |
| 92 Plugin plugin = new TestPlugin('plugin'); |
| 93 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null); |
| 94 List<Object> extensions = point.extensions; |
| 95 expect(extensions, isNotNull); |
| 96 expect(extensions, isEmpty); |
| 97 }); |
| 98 |
| 99 test('uniqueIdentifier', () { |
| 100 Plugin plugin = new TestPlugin('plugin'); |
| 101 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null); |
| 102 expect(point.uniqueIdentifier, 'plugin.point'); |
| 103 }); |
| 104 |
| 105 test('add - single', () { |
| 106 Plugin plugin = new TestPlugin('plugin'); |
| 107 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null); |
| 108 Object extension = 'extension'; |
| 109 point.add(extension); |
| 110 List<Object> extensions = point.extensions; |
| 111 expect(extensions, isNotNull); |
| 112 expect(extensions, hasLength(1)); |
| 113 expect(extensions[0], extension); |
| 114 }); |
| 115 |
| 116 test('add - multiple', () { |
| 117 Plugin plugin = new TestPlugin('plugin'); |
| 118 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null); |
| 119 point.add('extension 1'); |
| 120 point.add('extension 2'); |
| 121 point.add('extension 3'); |
| 122 List<Object> extensions = point.extensions; |
| 123 expect(extensions, isNotNull); |
| 124 expect(extensions, hasLength(3)); |
| 125 }); |
| 126 |
| 127 test('add - with validator - valid', () { |
| 128 Plugin plugin = new TestPlugin('plugin'); |
| 129 ExtensionPointImpl point = |
| 130 new ExtensionPointImpl(plugin, 'point', (Object extension) { |
| 131 if (extension is! String) { |
| 132 throw new ExtensionError(''); |
| 133 } |
| 134 }); |
| 135 point.add('extension'); |
| 136 }); |
| 137 |
| 138 test('add - with validator - invalid', () { |
| 139 Plugin plugin = new TestPlugin('plugin'); |
| 140 ExtensionPointImpl point = |
| 141 new ExtensionPointImpl(plugin, 'point', (Object extension) { |
| 142 if (extension is! String) { |
| 143 throw new ExtensionError(''); |
| 144 } |
| 145 }); |
| 146 expect(() => point.add(1), throwsA(new isInstanceOf<ExtensionError>())); |
| 147 }); |
| 148 }); |
| 149 } |
| 150 |
| 151 /** |
| 152 * A simple plugin that can be used by tests. |
| 153 */ |
| 154 class TestPlugin extends Plugin { |
| 155 /** |
| 156 * A flag indicating whether the method [registerExtensionPoints] has been |
| 157 * invoked. |
| 158 */ |
| 159 bool extensionPointsRegistered = false; |
| 160 |
| 161 /** |
| 162 * A flag indicating whether the method [registerExtensions] has been invoked. |
| 163 */ |
| 164 bool extensionsRegistered = false; |
| 165 |
| 166 @override |
| 167 String uniqueIdentifier; |
| 168 |
| 169 /** |
| 170 * Initialize a newly created plugin to have the given identifier. |
| 171 */ |
| 172 TestPlugin(this.uniqueIdentifier); |
| 173 |
| 174 @override |
| 175 void registerExtensionPoints(RegisterExtensionPoint register) { |
| 176 extensionPointsRegistered = true; |
| 177 } |
| 178 |
| 179 @override |
| 180 void registerExtensions(RegisterExtension register) { |
| 181 extensionsRegistered = true; |
| 182 } |
| 183 } |
| OLD | NEW |