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

Side by Side Diff: pkg/analyzer/test/plugin/plugin_impl_test.dart

Issue 1063153004: Convert analyzer and analysis_server to use the plugin package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/pubspec.yaml ('k') | pkg/analyzer/test/plugin/test_all.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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:analyzer/plugin/plugin.dart';
8 import 'package:analyzer/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(() => manager.registerExtension('does not exist', 'extension'),
43 throwsA(new isInstanceOf<ExtensionError>()));
44 ;
45 });
46
47 test('registerExtensionPoint - non-conflicting', () {
48 Plugin plugin1 = new TestPlugin('plugin1');
49 Plugin plugin2 = new TestPlugin('plugin2');
50 ExtensionManager manager = new ExtensionManager();
51 expect(
52 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull);
53 expect(
54 manager.registerExtensionPoint(plugin1, 'point2', null), isNotNull);
55 expect(
56 manager.registerExtensionPoint(plugin2, 'point1', null), isNotNull);
57 expect(
58 manager.registerExtensionPoint(plugin2, 'point2', null), isNotNull);
59 });
60
61 test('registerExtensionPoint - conflicting - same plugin', () {
62 Plugin plugin1 = new TestPlugin('plugin1');
63 ExtensionManager manager = new ExtensionManager();
64 expect(
65 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull);
66 expect(() => manager.registerExtensionPoint(plugin1, 'point1', null),
67 throwsA(new isInstanceOf<ExtensionError>()));
68 });
69
70 test('registerExtensionPoint - conflicting - different plugins', () {
71 Plugin plugin1 = new TestPlugin('plugin1');
72 Plugin plugin2 = new TestPlugin('plugin1');
73 ExtensionManager manager = new ExtensionManager();
74 expect(
75 manager.registerExtensionPoint(plugin1, 'point1', null), isNotNull);
76 expect(() => manager.registerExtensionPoint(plugin2, 'point1', null),
77 throwsA(new isInstanceOf<ExtensionError>()));
78 });
79 });
80
81 group('ExtensionPointImpl', () {
82 test('extensions - empty', () {
83 Plugin plugin = new TestPlugin('plugin');
84 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null);
85 List<Object> extensions = point.extensions;
86 expect(extensions, isNotNull);
87 expect(extensions, isEmpty);
88 });
89
90 test('uniqueIdentifier', () {
91 Plugin plugin = new TestPlugin('plugin');
92 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null);
93 expect(point.uniqueIdentifier, 'plugin.point');
94 });
95
96 test('add - single', () {
97 Plugin plugin = new TestPlugin('plugin');
98 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null);
99 Object extension = 'extension';
100 point.add(extension);
101 List<Object> extensions = point.extensions;
102 expect(extensions, isNotNull);
103 expect(extensions, hasLength(1));
104 expect(extensions[0], extension);
105 });
106
107 test('add - multiple', () {
108 Plugin plugin = new TestPlugin('plugin');
109 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point', null);
110 point.add('extension 1');
111 point.add('extension 2');
112 point.add('extension 3');
113 List<Object> extensions = point.extensions;
114 expect(extensions, isNotNull);
115 expect(extensions, hasLength(3));
116 });
117
118 test('add - with validator - valid', () {
119 Plugin plugin = new TestPlugin('plugin');
120 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point',
121 (Object extension) {
122 if (extension is! String) {
123 throw new ExtensionError('');
124 }
125 });
126 point.add('extension');
127 });
128
129 test('add - with validator - invalid', () {
130 Plugin plugin = new TestPlugin('plugin');
131 ExtensionPointImpl point = new ExtensionPointImpl(plugin, 'point',
132 (Object extension) {
133 if (extension is! String) {
134 throw new ExtensionError('');
135 }
136 });
137 expect(() => point.add(1), throwsA(new isInstanceOf<ExtensionError>()));
138 });
139 });
140 }
141
142 /**
143 * A simple plugin that can be used by tests.
144 */
145 class TestPlugin extends Plugin {
146 /**
147 * A flag indicating whether the method [registerExtensionPoints] has been
148 * invoked.
149 */
150 bool extensionPointsRegistered = false;
151
152 /**
153 * A flag indicating whether the method [registerExtensions] has been invoked.
154 */
155 bool extensionsRegistered = false;
156
157 @override
158 String uniqueIdentifier;
159
160 /**
161 * Initialize a newly created plugin to have the given identifier.
162 */
163 TestPlugin(this.uniqueIdentifier);
164
165 @override
166 void registerExtensionPoints(RegisterExtensionPoint register) {
167 extensionPointsRegistered = true;
168 }
169
170 @override
171 void registerExtensions(RegisterExtension register) {
172 extensionsRegistered = true;
173 }
174 }
OLDNEW
« no previous file with comments | « pkg/analyzer/pubspec.yaml ('k') | pkg/analyzer/test/plugin/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698