| 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 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked |
| 4 | 5 |
| 5 import 'dart:async'; | 6 import 'dart:async'; |
| 6 | 7 |
| 7 import 'package:observatory/cli.dart'; | 8 import 'package:observatory/cli.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 9 | 10 |
| 10 class TestCommand extends Command { | 11 class TestCommand extends Command { |
| 11 TestCommand(this.out, name, children) : super(name, children); | 12 TestCommand(this.out, name, children) : super(name, children); |
| 12 StringBuffer out; | 13 StringBuffer out; |
| 13 | 14 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 57 |
| 57 // Substring completion. | 58 // Substring completion. |
| 58 cmd.completeCommand('al').then((result) { | 59 cmd.completeCommand('al').then((result) { |
| 59 expect(result, equals(['alpha '])); | 60 expect(result, equals(['alpha '])); |
| 60 }); | 61 }); |
| 61 | 62 |
| 62 // Full string completion. | 63 // Full string completion. |
| 63 cmd.completeCommand('alpha').then((result) { | 64 cmd.completeCommand('alpha').then((result) { |
| 64 expect(result, equals(['alpha '])); | 65 expect(result, equals(['alpha '])); |
| 65 }); | 66 }); |
| 66 | 67 |
| 67 // Extra space, no subcommands. | 68 // Extra space, no subcommands. |
| 68 cmd.completeCommand('alpha ').then((result) { | 69 cmd.completeCommand('alpha ').then((result) { |
| 69 expect(result, equals(['alpha '])); | 70 expect(result, equals(['alpha '])); |
| 70 }); | 71 }); |
| 71 | 72 |
| 72 // Ambiguous completion. | 73 // Ambiguous completion. |
| 73 cmd.completeCommand('g').then((result) { | 74 cmd.completeCommand('g').then((result) { |
| 74 expect(result, equals(['game ', 'gamera '])); | 75 expect(result, equals(['game ', 'gamera '])); |
| 75 }); | 76 }); |
| 76 | 77 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = | 167 RootCommand cmd = |
| 167 new RootCommand([ | 168 new RootCommand([ |
| 168 new TestCommand(out, 'alpha', [ | 169 new TestCommand(out, 'alpha', [ |
| 169 new TestCommand(out, 'beta', []), | 170 new TestCommand(out, 'beta', []), |
| 170 new TestCommand(out, 'gamma', [])])]); | 171 new TestCommand(out, 'gamma', [])])]); |
| 171 | 172 |
| 172 cmd.runCommand('a b').then(expectAsync((_) { | 173 cmd.runCommand('a b').then(expectAsync((_) { |
| 173 expect(out.toString(), equals('executing beta([])\n')); | 174 expect(out.toString(), equals('executing beta([])\n')); |
| 174 out.clear(); | 175 out.clear(); |
| 175 cmd.runCommand('alpha g ').then(expectAsync((_) { | 176 cmd.runCommand('alpha g ').then(expectAsync((_) { |
| 176 expect(out.toString(), equals('executing gamma([])\n')); | 177 expect(out.toString(), equals('executing gamma([])\n')); |
| 177 })); | 178 })); |
| 178 })); | 179 })); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void testCommandRunNotFound() { | 182 void testCommandRunNotFound() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 219 |
| 219 main() { | 220 main() { |
| 220 test('command completion test suite', testCommandComplete); | 221 test('command completion test suite', testCommandComplete); |
| 221 test('run a simple command', testCommandRunSimple); | 222 test('run a simple command', testCommandRunSimple); |
| 222 test('run a subcommand', testCommandRunSubcommand); | 223 test('run a subcommand', testCommandRunSubcommand); |
| 223 test('run a command which is not found', testCommandRunNotFound); | 224 test('run a command which is not found', testCommandRunNotFound); |
| 224 test('run a command which is ambiguous', testCommandRunAmbiguous); | 225 test('run a command which is ambiguous', testCommandRunAmbiguous); |
| 225 test('run a command using an alias', testCommandRunAlias); | 226 test('run a command using an alias', testCommandRunAlias); |
| 226 } | 227 } |
| 227 | 228 |
| OLD | NEW |