| 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.operation; | 5 library test.operation; |
| 6 | 6 |
| 7 import 'package:plugin/plugin.dart'; | 7 import 'package:plugin/plugin.dart'; |
| 8 import 'package:plugin/src/plugin_impl.dart'; | 8 import 'package:plugin/src/plugin_impl.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:test/test.dart'; |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 groupSep = ' | '; | |
| 13 | |
| 14 group('ExtensionManager', () { | 12 group('ExtensionManager', () { |
| 15 test('processPlugins', () { | 13 test('processPlugins', () { |
| 16 TestPlugin plugin1 = new TestPlugin('plugin1'); | 14 TestPlugin plugin1 = new TestPlugin('plugin1'); |
| 17 TestPlugin plugin2 = new TestPlugin('plugin1'); | 15 TestPlugin plugin2 = new TestPlugin('plugin1'); |
| 18 ExtensionManagerImpl manager = new ExtensionManagerImpl(); | 16 ExtensionManagerImpl manager = new ExtensionManagerImpl(); |
| 19 manager.processPlugins([plugin1, plugin2]); | 17 manager.processPlugins([plugin1, plugin2]); |
| 20 expect(plugin1.extensionPointsRegistered, true); | 18 expect(plugin1.extensionPointsRegistered, true); |
| 21 expect(plugin1.extensionsRegistered, true); | 19 expect(plugin1.extensionsRegistered, true); |
| 22 expect(plugin2.extensionPointsRegistered, true); | 20 expect(plugin2.extensionPointsRegistered, true); |
| 23 expect(plugin2.extensionsRegistered, true); | 21 expect(plugin2.extensionsRegistered, true); |
| 24 }); | 22 }); |
| 25 | 23 |
| 26 test('registerExtension - valid', () { | 24 test('registerExtension - valid', () { |
| 27 Plugin plugin = new TestPlugin('plugin'); | 25 Plugin plugin = new TestPlugin('plugin'); |
| 28 ExtensionManagerImpl manager = new ExtensionManagerImpl(); | 26 ExtensionManagerImpl manager = new ExtensionManagerImpl(); |
| 29 ExtensionPoint point = | 27 ExtensionPoint point = new ExtensionPoint(plugin, 'point', null); |
| 30 manager.registerExtensionPoint(plugin, 'point', null); | 28 manager.registerExtensionPoint(point); |
| 31 expect(point, isNotNull); | 29 expect(point, isNotNull); |
| 32 Object extension = 'extension'; | 30 Object extension = 'extension'; |
| 33 manager.registerExtension('plugin.point', extension); | 31 manager.registerExtension('plugin.point', extension); |
| 34 List<Object> extensions = point.extensions; | 32 List<Object> extensions = point.extensions; |
| 35 expect(extensions, isNotNull); | 33 expect(extensions, isNotNull); |
| 36 expect(extensions, hasLength(1)); | 34 expect(extensions, hasLength(1)); |
| 37 expect(extensions[0], extension); | 35 expect(extensions[0], extension); |
| 38 }); | 36 }); |
| 39 | 37 |
| 40 test('registerExtension - non existent', () { | 38 test('registerExtension - non existent', () { |
| 41 ExtensionManagerImpl manager = new ExtensionManagerImpl(); | 39 ExtensionManagerImpl manager = new ExtensionManagerImpl(); |
| 42 expect(() => manager.registerExtension('does not exist', 'extension'), | 40 expect(() => manager.registerExtension('does not exist', 'extension'), |
| 43 throwsA(new isInstanceOf<ExtensionError>())); | 41 throwsA(new isInstanceOf<ExtensionError>())); |
| 44 ; | 42 ; |
| 45 }); | 43 }); |
| 46 | 44 |
| 47 test('registerExtensionPoint - non-conflicting', () { | 45 test('registerExtensionPoint - non-conflicting', () { |
| 48 Plugin plugin1 = new TestPlugin('plugin1'); | 46 Plugin plugin1 = new TestPlugin('plugin1'); |
| 49 Plugin plugin2 = new TestPlugin('plugin2'); | 47 Plugin plugin2 = new TestPlugin('plugin2'); |
| 50 ExtensionManagerImpl manager = new ExtensionManagerImpl(); | 48 ExtensionManagerImpl manager = new ExtensionManagerImpl(); |
| 51 expect( | 49 manager |
| 52 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull); | 50 .registerExtensionPoint(new ExtensionPoint(plugin1, 'point1', null)); |
| 53 expect( | 51 manager |
| 54 manager.registerExtensionPoint(plugin1, 'point2', null), isNotNull); | 52 .registerExtensionPoint(new ExtensionPoint(plugin1, 'point2', null)); |
| 55 expect( | 53 manager |
| 56 manager.registerExtensionPoint(plugin2, 'point1', null), isNotNull); | 54 .registerExtensionPoint(new ExtensionPoint(plugin2, 'point1', null)); |
| 57 expect( | 55 manager |
| 58 manager.registerExtensionPoint(plugin2, 'point2', null), isNotNull); | 56 .registerExtensionPoint(new ExtensionPoint(plugin2, 'point2', null)); |
| 59 }); | 57 }); |
| 60 | 58 |
| 61 test('registerExtensionPoint - conflicting - same plugin', () { | 59 test('registerExtensionPoint - conflicting - same plugin', () { |
| 62 Plugin plugin1 = new TestPlugin('plugin1'); | 60 Plugin plugin1 = new TestPlugin('plugin1'); |
| 63 ExtensionManagerImpl manager = new ExtensionManagerImpl(); | 61 ExtensionManagerImpl manager = new ExtensionManagerImpl(); |
| 62 manager |
| 63 .registerExtensionPoint(new ExtensionPoint(plugin1, 'point1', null)); |
| 64 expect( | 64 expect( |
| 65 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull); | 65 () => manager.registerExtensionPoint( |
| 66 expect(() => manager.registerExtensionPoint(plugin1, 'point1', null), | 66 new ExtensionPoint(plugin1, 'point1', null)), |
| 67 throwsA(new isInstanceOf<ExtensionError>())); | 67 throwsA(new isInstanceOf<ExtensionError>())); |
| 68 }); | 68 }); |
| 69 | 69 |
| 70 test('registerExtensionPoint - conflicting - different plugins', () { | 70 test('registerExtensionPoint - conflicting - different plugins', () { |
| 71 Plugin plugin1 = new TestPlugin('plugin1'); | 71 Plugin plugin1 = new TestPlugin('plugin1'); |
| 72 Plugin plugin2 = new TestPlugin('plugin1'); | 72 Plugin plugin2 = new TestPlugin('plugin1'); |
| 73 ExtensionManagerImpl manager = new ExtensionManagerImpl(); | 73 ExtensionManagerImpl manager = new ExtensionManagerImpl(); |
| 74 manager |
| 75 .registerExtensionPoint(new ExtensionPoint(plugin1, 'point1', null)); |
| 74 expect( | 76 expect( |
| 75 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull); | 77 () => manager.registerExtensionPoint( |
| 76 expect(() => manager.registerExtensionPoint(plugin2, 'point1', null), | 78 new ExtensionPoint(plugin2, 'point1', null)), |
| 77 throwsA(new isInstanceOf<ExtensionError>())); | 79 throwsA(new isInstanceOf<ExtensionError>())); |
| 78 }); | 80 }); |
| 79 }); | 81 }); |
| 80 | 82 |
| 81 group('ExtensionPointImpl', () { | 83 group('ExtensionPointImpl', () { |
| 82 test('extensions - empty', () { | 84 test('extensions - empty', () { |
| 83 Plugin plugin = new TestPlugin('plugin'); | 85 Plugin plugin = new TestPlugin('plugin'); |
| 84 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null); | 86 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null); |
| 85 List<Object> extensions = point.extensions; | 87 List<Object> extensions = point.extensions; |
| 86 expect(extensions, isNotNull); | 88 expect(extensions, isNotNull); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 110 point.add('extension 1'); | 112 point.add('extension 1'); |
| 111 point.add('extension 2'); | 113 point.add('extension 2'); |
| 112 point.add('extension 3'); | 114 point.add('extension 3'); |
| 113 List<Object> extensions = point.extensions; | 115 List<Object> extensions = point.extensions; |
| 114 expect(extensions, isNotNull); | 116 expect(extensions, isNotNull); |
| 115 expect(extensions, hasLength(3)); | 117 expect(extensions, hasLength(3)); |
| 116 }); | 118 }); |
| 117 | 119 |
| 118 test('add - with validator - valid', () { | 120 test('add - with validator - valid', () { |
| 119 Plugin plugin = new TestPlugin('plugin'); | 121 Plugin plugin = new TestPlugin('plugin'); |
| 120 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', | 122 ExtensionPointImpl point = |
| 121 (Object extension) { | 123 new ExtensionPointImpl(plugin, 'point', (Object extension) { |
| 122 if (extension is! String) { | 124 if (extension is! String) { |
| 123 throw new ExtensionError(''); | 125 throw new ExtensionError(''); |
| 124 } | 126 } |
| 125 }); | 127 }); |
| 126 point.add('extension'); | 128 point.add('extension'); |
| 127 }); | 129 }); |
| 128 | 130 |
| 129 test('add - with validator - invalid', () { | 131 test('add - with validator - invalid', () { |
| 130 Plugin plugin = new TestPlugin('plugin'); | 132 Plugin plugin = new TestPlugin('plugin'); |
| 131 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', | 133 ExtensionPointImpl point = |
| 132 (Object extension) { | 134 new ExtensionPointImpl(plugin, 'point', (Object extension) { |
| 133 if (extension is! String) { | 135 if (extension is! String) { |
| 134 throw new ExtensionError(''); | 136 throw new ExtensionError(''); |
| 135 } | 137 } |
| 136 }); | 138 }); |
| 137 expect(() => point.add(1), throwsA(new isInstanceOf<ExtensionError>())); | 139 expect(() => point.add(1), throwsA(new isInstanceOf<ExtensionError>())); |
| 138 }); | 140 }); |
| 139 }); | 141 }); |
| 140 } | 142 } |
| 141 | 143 |
| 142 /** | 144 /** |
| (...skipping 22 matching lines...) Expand all Loading... |
| 165 @override | 167 @override |
| 166 void registerExtensionPoints(RegisterExtensionPoint register) { | 168 void registerExtensionPoints(RegisterExtensionPoint register) { |
| 167 extensionPointsRegistered = true; | 169 extensionPointsRegistered = true; |
| 168 } | 170 } |
| 169 | 171 |
| 170 @override | 172 @override |
| 171 void registerExtensions(RegisterExtension register) { | 173 void registerExtensions(RegisterExtension register) { |
| 172 extensionsRegistered = true; | 174 extensionsRegistered = true; |
| 173 } | 175 } |
| 174 } | 176 } |
| OLD | NEW |