OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 command_test; | 5 library command_test; |
6 | 6 |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'package:args/args.dart'; | 8 import 'package:args/args.dart'; |
9 | 9 |
10 main() { | 10 main() { |
11 group('ArgParser.addCommand()', () { | 11 group('ArgParser.addCommand()', () { |
| 12 test('creates a new ArgParser if none is given', () { |
| 13 var parser = new ArgParser(); |
| 14 var command = parser.addCommand('install'); |
| 15 expect(parser.commands['install'], equals(command)); |
| 16 expect(command is ArgParser, isTrue); |
| 17 }); |
| 18 |
| 19 test('uses the command parser if given one', () { |
| 20 var parser = new ArgParser(); |
| 21 var command = new ArgParser(); |
| 22 var result = parser.addCommand('install', command); |
| 23 expect(parser.commands['install'], equals(command)); |
| 24 expect(result, equals(command)); |
| 25 }); |
| 26 |
12 test('throws on a duplicate command name', () { | 27 test('throws on a duplicate command name', () { |
13 var parser = new ArgParser(); | 28 var parser = new ArgParser(); |
14 parser.addCommand('install'); | 29 parser.addCommand('install'); |
15 throwsIllegalArg(() => parser.addCommand('install')); | 30 throwsIllegalArg(() => parser.addCommand('install')); |
16 }); | 31 }); |
17 }); | 32 }); |
18 | 33 |
19 group('ArgParser.parse()', () { | 34 group('ArgParser.parse()', () { |
20 test('parses a command', () { | 35 test('parses a command', () { |
21 var parser = new ArgParser(); | 36 var parser = new ArgParser(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 }); | 205 }); |
191 } | 206 } |
192 | 207 |
193 throwsIllegalArg(function) { | 208 throwsIllegalArg(function) { |
194 expect(function, throwsArgumentError); | 209 expect(function, throwsArgumentError); |
195 } | 210 } |
196 | 211 |
197 throwsFormat(ArgParser parser, List<String> args) { | 212 throwsFormat(ArgParser parser, List<String> args) { |
198 expect(() => parser.parse(args), throwsFormatException); | 213 expect(() => parser.parse(args), throwsFormatException); |
199 } | 214 } |
OLD | NEW |