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

Side by Side Diff: runtime/observatory/tests/service/command_test.dart

Issue 2767533002: Revert "Fix observatory tests broken by running dartfmt." (Closed)
Patch Set: Created 3 years, 9 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
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 // VMOptions=--error_on_bad_type --error_on_bad_override 4 // VMOptions=--error_on_bad_type --error_on_bad_override
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 7
8 import 'package:observatory/cli.dart'; 8 import 'package:observatory/cli.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 17 matching lines...) Expand all
28 possibles.where((possible) => possible.startsWith(args[0])).toList()); 28 possibles.where((possible) => possible.startsWith(args[0])).toList());
29 } 29 }
30 30
31 Future run(List<String> args) { 31 Future run(List<String> args) {
32 out.write('executing ${name}(${args})\n'); 32 out.write('executing ${name}(${args})\n');
33 return new Future.value(null); 33 return new Future.value(null);
34 } 34 }
35 } 35 }
36 36
37 void testCommandComplete() { 37 void testCommandComplete() {
38 RootCommand cmd = new RootCommand([ 38 RootCommand cmd =
39 new TestCommand(null, 'alpha', []), 39 new RootCommand([new TestCommand(null, 'alpha', []),
40 new TestCommand(null, 'game', [ 40
41 new TestCommand(null, 'checkers', []), 41 new TestCommand(null, 'game', [
42 new TestCommand(null, 'chess', []) 42 new TestCommand(null, 'checkers', []),
43 ]), 43 new TestCommand(null, 'chess', [])]),
44 new TestCommand(null, 'gamera', [ 44
45 new TestCommand(null, 'london', []), 45 new TestCommand(null, 'gamera', [
46 new TestCommand(null, 'tokyo', []), 46 new TestCommand(null, 'london', []),
47 new TestCommand(null, 'topeka', []) 47 new TestCommand(null, 'tokyo', []),
48 ]), 48 new TestCommand(null, 'topeka', [])]),
49 new TestCompleteCommand( 49
50 null, 'count', [new TestCommand(null, 'chocula', [])]) 50 new TestCompleteCommand(null, 'count', [
51 ]); 51 new TestCommand(null, 'chocula', [])])]);
52 52
53 // Show all commands. 53 // Show all commands.
54 cmd.completeCommand('').then((result) { 54 cmd.completeCommand('').then((result) {
55 expect(result, equals(['alpha ', 'game ', 'gamera ', 'count '])); 55 expect(result, equals(['alpha ', 'game ', 'gamera ', 'count ']));
56 }); 56 });
57 57
58 // Substring completion. 58 // Substring completion.
59 cmd.completeCommand('al').then((result) { 59 cmd.completeCommand('al').then((result) {
60 expect(result, equals(['alpha '])); 60 expect(result, equals(['alpha ']));
61 }); 61 });
(...skipping 13 matching lines...) Expand all
75 expect(result, equals(['game ', 'gamera '])); 75 expect(result, equals(['game ', 'gamera ']));
76 }); 76 });
77 77
78 // Ambiguous completion, exact match not preferred. 78 // Ambiguous completion, exact match not preferred.
79 cmd.completeCommand('game').then((result) { 79 cmd.completeCommand('game').then((result) {
80 expect(result, equals(['game ', 'gamera '])); 80 expect(result, equals(['game ', 'gamera ']));
81 }); 81 });
82 82
83 // Show all subcommands. 83 // Show all subcommands.
84 cmd.completeCommand('gamera ').then((result) { 84 cmd.completeCommand('gamera ').then((result) {
85 expect( 85 expect(result, equals(['gamera london ', 'gamera tokyo ', 'gamera topeka ']) );
86 result, equals(['gamera london ', 'gamera tokyo ', 'gamera topeka ']));
87 }); 86 });
88 87
89 // Subcommand completion. 88 // Subcommand completion.
90 cmd.completeCommand('gamera l').then((result) { 89 cmd.completeCommand('gamera l').then((result) {
91 expect(result, equals(['gamera london '])); 90 expect(result, equals(['gamera london ']));
92 }); 91 });
93 92
94 // Extra space, with subcommand. 93 // Extra space, with subcommand.
95 cmd.completeCommand('gamera london ').then((result) { 94 cmd.completeCommand('gamera london ').then((result) {
96 expect(result, equals(['gamera london '])); 95 expect(result, equals(['gamera london ']));
(...skipping 15 matching lines...) Expand all
112 expect(result, equals(['game checkers '])); 111 expect(result, equals(['game checkers ']));
113 }); 112 });
114 113
115 // Ambiguous non-exact prefix means no matches. 114 // Ambiguous non-exact prefix means no matches.
116 cmd.completeCommand('gam chec').then((result) { 115 cmd.completeCommand('gam chec').then((result) {
117 expect(result, equals([])); 116 expect(result, equals([]));
118 }); 117 });
119 118
120 // Locals + subcommands, show all. 119 // Locals + subcommands, show all.
121 cmd.completeCommand('count ').then((result) { 120 cmd.completeCommand('count ').then((result) {
122 expect(result, 121 expect(result, equals(['count chocula ',
123 equals(['count chocula ', 'count one ', 'count two ', 'count three '])); 122 'count one ',
123 'count two ',
124 'count three ']));
124 }); 125 });
125 126
126 // Locals + subcommands, single local match. 127 // Locals + subcommands, single local match.
127 cmd.completeCommand('count th').then((result) { 128 cmd.completeCommand('count th').then((result) {
128 expect(result, equals(['count three '])); 129 expect(result, equals(['count three ']));
129 }); 130 });
130 131
131 // Locals + subcommands, ambiguous local match. 132 // Locals + subcommands, ambiguous local match.
132 cmd.completeCommand('count t').then((result) { 133 cmd.completeCommand('count t').then((result) {
133 expect(result, equals(['count two ', 'count three '])); 134 expect(result, equals(['count two ', 'count three ']));
(...skipping 10 matching lines...) Expand all
144 }); 145 });
145 } 146 }
146 147
147 void testCommandRunSimple() { 148 void testCommandRunSimple() {
148 // Run a simple command. 149 // Run a simple command.
149 StringBuffer out = new StringBuffer(); 150 StringBuffer out = new StringBuffer();
150 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', [])]); 151 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', [])]);
151 152
152 // Full name dispatch works. Argument passing works. 153 // Full name dispatch works. Argument passing works.
153 cmd.runCommand('alpha dog').then(expectAsync((_) { 154 cmd.runCommand('alpha dog').then(expectAsync((_) {
154 expect(out.toString(), contains('executing alpha([dog])\n')); 155 expect(out.toString(), contains('executing alpha([dog])\n'));
155 out.clear(); 156 out.clear();
156 // Substring dispatch works. 157 // Substring dispatch works.
157 cmd.runCommand('al cat mouse').then(expectAsync((_) { 158 cmd.runCommand('al cat mouse').then(expectAsync((_) {
158 expect(out.toString(), contains('executing alpha([cat , mouse])\n')); 159 expect(out.toString(), contains('executing alpha([cat , mouse])\n'));
159 })); 160 }));
160 })); 161 }));
161 } 162 }
162 163
163 void testCommandRunSubcommand() { 164 void testCommandRunSubcommand() {
164 // Run a simple command. 165 // Run a simple command.
165 StringBuffer out = new StringBuffer(); 166 StringBuffer out = new StringBuffer();
166 RootCommand cmd = new RootCommand([ 167 RootCommand cmd =
167 new TestCommand(out, 'alpha', 168 new RootCommand([
168 [new TestCommand(out, 'beta', []), new TestCommand(out, 'gamma', [])]) 169 new TestCommand(out, 'alpha', [
169 ]); 170 new TestCommand(out, 'beta', []),
171 new TestCommand(out, 'gamma', [])])]);
170 172
171 cmd.runCommand('a b').then(expectAsync((_) { 173 cmd.runCommand('a b').then(expectAsync((_) {
172 expect(out.toString(), equals('executing beta([])\n')); 174 expect(out.toString(), equals('executing beta([])\n'));
173 out.clear(); 175 out.clear();
174 cmd.runCommand('alpha g ').then(expectAsync((_) { 176 cmd.runCommand('alpha g ').then(expectAsync((_) {
175 expect(out.toString(), equals('executing gamma([])\n')); 177 expect(out.toString(), equals('executing gamma([])\n'));
176 })); 178 }));
177 })); 179 }));
178 } 180 }
179 181
180 void testCommandRunNotFound() { 182 void testCommandRunNotFound() {
181 // Run a simple command. 183 // Run a simple command.
182 StringBuffer out = new StringBuffer(); 184 StringBuffer out = new StringBuffer();
183 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', [])]); 185 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', [])]);
184 186
185 cmd.runCommand('goose').catchError(expectAsync((e) { 187 cmd.runCommand('goose').catchError(expectAsync((e) {
186 expect(e.toString(), equals("No such command: 'goose'")); 188 expect(e.toString(), equals("No such command: 'goose'"));
187 })); 189 }));
188 } 190 }
189 191
190 void testCommandRunAmbiguous() { 192 void testCommandRunAmbiguous() {
191 // Run a simple command. 193 // Run a simple command.
192 StringBuffer out = new StringBuffer(); 194 StringBuffer out = new StringBuffer();
193 RootCommand cmd = new RootCommand( 195 RootCommand cmd = new RootCommand([new TestCommand(out, 'alpha', []),
194 [new TestCommand(out, 'alpha', []), new TestCommand(out, 'ankle', [])]); 196 new TestCommand(out, 'ankle', [])]);
195 197
196 cmd.runCommand('a 55').catchError(expectAsync((e) { 198 cmd.runCommand('a 55').catchError(expectAsync((e) {
197 expect(e.toString(), equals("Command 'a 55' is ambiguous: [alpha, ankle]")); 199 expect(e.toString(),
198 out.clear(); 200 equals("Command 'a 55' is ambiguous: [alpha, ankle]"));
199 cmd.runCommand('ankl 55').then(expectAsync((_) { 201 out.clear();
200 expect(out.toString(), equals('executing ankle([55])\n')); 202 cmd.runCommand('ankl 55').then(expectAsync((_) {
201 })); 203 expect(out.toString(), equals('executing ankle([55])\n'));
204 }));
202 })); 205 }));
203 } 206 }
204 207
205 void testCommandRunAlias() { 208 void testCommandRunAlias() {
206 // Run a simple command. 209 // Run a simple command.
207 StringBuffer out = new StringBuffer(); 210 StringBuffer out = new StringBuffer();
208 var aliasCmd = new TestCommand(out, 'alpha', []); 211 var aliasCmd = new TestCommand(out, 'alpha', []);
209 aliasCmd.alias = 'a'; 212 aliasCmd.alias = 'a';
210 RootCommand cmd = 213 RootCommand cmd = new RootCommand([aliasCmd,
211 new RootCommand([aliasCmd, new TestCommand(out, 'ankle', [])]); 214 new TestCommand(out, 'ankle', [])]);
212 215
213 cmd.runCommand('a 55').then(expectAsync((_) { 216 cmd.runCommand('a 55').then(expectAsync((_) {
214 expect(out.toString(), equals('executing alpha([55])\n')); 217 expect(out.toString(), equals('executing alpha([55])\n'));
215 })); 218 }));
216 } 219 }
217 220
218 main() { 221 main() {
219 test('command completion test suite', testCommandComplete); 222 test('command completion test suite', testCommandComplete);
220 test('run a simple command', testCommandRunSimple); 223 test('run a simple command', testCommandRunSimple);
221 test('run a subcommand', testCommandRunSubcommand); 224 test('run a subcommand', testCommandRunSubcommand);
222 test('run a command which is not found', testCommandRunNotFound); 225 test('run a command which is not found', testCommandRunNotFound);
223 test('run a command which is ambiguous', testCommandRunAmbiguous); 226 test('run a command which is ambiguous', testCommandRunAmbiguous);
224 test('run a command using an alias', testCommandRunAlias); 227 test('run a command using an alias', testCommandRunAlias);
225 } 228 }
229
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/code_test.dart ('k') | runtime/observatory/tests/service/complex_reload/v1/main.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698