Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: test/plugin_impl_test.dart

Issue 1959373002: Rework plugin API to work better with strong mode (Closed) Base URL: https://github.com/dart-lang/plugin.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:unittest/unittest.dart';
10 10
11 main() { 11 main() {
12 groupSep = ' | '; 12 groupSep = ' | ';
13 13
14 group('ExtensionManager', () { 14 group('ExtensionManager', () {
15 test('processPlugins', () { 15 test('processPlugins', () {
16 TestPlugin plugin1 = new TestPlugin('plugin1'); 16 TestPlugin plugin1 = new TestPlugin('plugin1');
17 TestPlugin plugin2 = new TestPlugin('plugin1'); 17 TestPlugin plugin2 = new TestPlugin('plugin1');
18 ExtensionManagerImpl manager = new ExtensionManagerImpl(); 18 ExtensionManagerImpl manager = new ExtensionManagerImpl();
19 manager.processPlugins([plugin1, plugin2]); 19 manager.processPlugins([plugin1, plugin2]);
20 expect(plugin1.extensionPointsRegistered, true); 20 expect(plugin1.extensionPointsRegistered, true);
21 expect(plugin1.extensionsRegistered, true); 21 expect(plugin1.extensionsRegistered, true);
22 expect(plugin2.extensionPointsRegistered, true); 22 expect(plugin2.extensionPointsRegistered, true);
23 expect(plugin2.extensionsRegistered, true); 23 expect(plugin2.extensionsRegistered, true);
24 }); 24 });
25 25
26 test('registerExtension - valid', () { 26 test('registerExtension - valid', () {
27 Plugin plugin = new TestPlugin('plugin'); 27 Plugin plugin = new TestPlugin('plugin');
28 ExtensionManagerImpl manager = new ExtensionManagerImpl(); 28 ExtensionManagerImpl manager = new ExtensionManagerImpl();
29 ExtensionPoint point = 29 ExtensionPoint point = new ExtensionPoint(plugin, 'point', null);
30 manager.registerExtensionPoint(plugin, 'point', null); 30 manager.registerExtensionPoint(point);
31 expect(point, isNotNull); 31 expect(point, isNotNull);
32 Object extension = 'extension'; 32 Object extension = 'extension';
33 manager.registerExtension('plugin.point', extension); 33 manager.registerExtension('plugin.point', extension);
34 List<Object> extensions = point.extensions; 34 List<Object> extensions = point.extensions;
35 expect(extensions, isNotNull); 35 expect(extensions, isNotNull);
36 expect(extensions, hasLength(1)); 36 expect(extensions, hasLength(1));
37 expect(extensions[0], extension); 37 expect(extensions[0], extension);
38 }); 38 });
39 39
40 test('registerExtension - non existent', () { 40 test('registerExtension - non existent', () {
41 ExtensionManagerImpl manager = new ExtensionManagerImpl(); 41 ExtensionManagerImpl manager = new ExtensionManagerImpl();
42 expect(() => manager.registerExtension('does not exist', 'extension'), 42 expect(() => manager.registerExtension('does not exist', 'extension'),
43 throwsA(new isInstanceOf<ExtensionError>())); 43 throwsA(new isInstanceOf<ExtensionError>()));
44 ; 44 ;
45 }); 45 });
46 46
47 test('registerExtensionPoint - non-conflicting', () { 47 test('registerExtensionPoint - non-conflicting', () {
48 Plugin plugin1 = new TestPlugin('plugin1'); 48 Plugin plugin1 = new TestPlugin('plugin1');
49 Plugin plugin2 = new TestPlugin('plugin2'); 49 Plugin plugin2 = new TestPlugin('plugin2');
50 ExtensionManagerImpl manager = new ExtensionManagerImpl(); 50 ExtensionManagerImpl manager = new ExtensionManagerImpl();
51 expect( 51 manager
52 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull); 52 .registerExtensionPoint(new ExtensionPoint(plugin1, 'point1', null));
53 expect( 53 manager
54 manager.registerExtensionPoint(plugin1, 'point2', null), isNotNull); 54 .registerExtensionPoint(new ExtensionPoint(plugin1, 'point2', null));
55 expect( 55 manager
56 manager.registerExtensionPoint(plugin2, 'point1', null), isNotNull); 56 .registerExtensionPoint(new ExtensionPoint(plugin2, 'point1', null));
57 expect( 57 manager
58 manager.registerExtensionPoint(plugin2, 'point2', null), isNotNull); 58 .registerExtensionPoint(new ExtensionPoint(plugin2, 'point2', null));
59 }); 59 });
60 60
61 test('registerExtensionPoint - conflicting - same plugin', () { 61 test('registerExtensionPoint - conflicting - same plugin', () {
62 Plugin plugin1 = new TestPlugin('plugin1'); 62 Plugin plugin1 = new TestPlugin('plugin1');
63 ExtensionManagerImpl manager = new ExtensionManagerImpl(); 63 ExtensionManagerImpl manager = new ExtensionManagerImpl();
64 manager
65 .registerExtensionPoint(new ExtensionPoint(plugin1, 'point1', null));
64 expect( 66 expect(
65 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull); 67 () => manager.registerExtensionPoint(
66 expect(() => manager.registerExtensionPoint(plugin1, 'point1', null), 68 new ExtensionPoint(plugin1, 'point1', null)),
67 throwsA(new isInstanceOf<ExtensionError>())); 69 throwsA(new isInstanceOf<ExtensionError>()));
68 }); 70 });
69 71
70 test('registerExtensionPoint - conflicting - different plugins', () { 72 test('registerExtensionPoint - conflicting - different plugins', () {
71 Plugin plugin1 = new TestPlugin('plugin1'); 73 Plugin plugin1 = new TestPlugin('plugin1');
72 Plugin plugin2 = new TestPlugin('plugin1'); 74 Plugin plugin2 = new TestPlugin('plugin1');
73 ExtensionManagerImpl manager = new ExtensionManagerImpl(); 75 ExtensionManagerImpl manager = new ExtensionManagerImpl();
76 manager
77 .registerExtensionPoint(new ExtensionPoint(plugin1, 'point1', null));
74 expect( 78 expect(
75 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull); 79 () => manager.registerExtensionPoint(
76 expect(() => manager.registerExtensionPoint(plugin2, 'point1', null), 80 new ExtensionPoint(plugin2, 'point1', null)),
77 throwsA(new isInstanceOf<ExtensionError>())); 81 throwsA(new isInstanceOf<ExtensionError>()));
78 }); 82 });
79 }); 83 });
80 84
81 group('ExtensionPointImpl', () { 85 group('ExtensionPointImpl', () {
82 test('extensions - empty', () { 86 test('extensions - empty', () {
83 Plugin plugin = new TestPlugin('plugin'); 87 Plugin plugin = new TestPlugin('plugin');
84 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null); 88 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null);
85 List<Object> extensions = point.extensions; 89 List<Object> extensions = point.extensions;
86 expect(extensions, isNotNull); 90 expect(extensions, isNotNull);
(...skipping 23 matching lines...) Expand all
110 point.add('extension 1'); 114 point.add('extension 1');
111 point.add('extension 2'); 115 point.add('extension 2');
112 point.add('extension 3'); 116 point.add('extension 3');
113 List<Object> extensions = point.extensions; 117 List<Object> extensions = point.extensions;
114 expect(extensions, isNotNull); 118 expect(extensions, isNotNull);
115 expect(extensions, hasLength(3)); 119 expect(extensions, hasLength(3));
116 }); 120 });
117 121
118 test('add - with validator - valid', () { 122 test('add - with validator - valid', () {
119 Plugin plugin = new TestPlugin('plugin'); 123 Plugin plugin = new TestPlugin('plugin');
120 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', 124 ExtensionPointImpl point =
121 (Object extension) { 125 new ExtensionPointImpl(plugin, 'point', (Object extension) {
122 if (extension is! String) { 126 if (extension is! String) {
123 throw new ExtensionError(''); 127 throw new ExtensionError('');
124 } 128 }
125 }); 129 });
126 point.add('extension'); 130 point.add('extension');
127 }); 131 });
128 132
129 test('add - with validator - invalid', () { 133 test('add - with validator - invalid', () {
130 Plugin plugin = new TestPlugin('plugin'); 134 Plugin plugin = new TestPlugin('plugin');
131 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', 135 ExtensionPointImpl point =
132 (Object extension) { 136 new ExtensionPointImpl(plugin, 'point', (Object extension) {
133 if (extension is! String) { 137 if (extension is! String) {
134 throw new ExtensionError(''); 138 throw new ExtensionError('');
135 } 139 }
136 }); 140 });
137 expect(() => point.add(1), throwsA(new isInstanceOf<ExtensionError>())); 141 expect(() => point.add(1), throwsA(new isInstanceOf<ExtensionError>()));
138 }); 142 });
139 }); 143 });
140 } 144 }
141 145
142 /** 146 /**
(...skipping 22 matching lines...) Expand all
165 @override 169 @override
166 void registerExtensionPoints(RegisterExtensionPoint register) { 170 void registerExtensionPoints(RegisterExtensionPoint register) {
167 extensionPointsRegistered = true; 171 extensionPointsRegistered = true;
168 } 172 }
169 173
170 @override 174 @override
171 void registerExtensions(RegisterExtension register) { 175 void registerExtensions(RegisterExtension register) {
172 extensionsRegistered = true; 176 extensionsRegistered = true;
173 } 177 }
174 } 178 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698