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

Side by Side Diff: pkg/args/test/args_test.dart

Issue 11819068: Add command support to args. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix a couple of type annotations. Created 7 years, 11 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/args/lib/src/utils.dart ('k') | pkg/args/test/command_test.dart » ('j') | 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) 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 args_test; 5 library args_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() {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 group('ArgParser.getDefault()', () { 63 group('ArgParser.getDefault()', () {
64 test('returns the default value for an option', () { 64 test('returns the default value for an option', () {
65 var parser = new ArgParser(); 65 var parser = new ArgParser();
66 parser.addOption('mode', defaultsTo: 'debug'); 66 parser.addOption('mode', defaultsTo: 'debug');
67 expect(parser.getDefault('mode'), 'debug'); 67 expect(parser.getDefault('mode'), 'debug');
68 }); 68 });
69 69
70 test('throws if the option is unknown', () { 70 test('throws if the option is unknown', () {
71 var parser = new ArgParser(); 71 var parser = new ArgParser();
72 parser.addOption('mode', defaultsTo: 'debug'); 72 parser.addOption('mode', defaultsTo: 'debug');
73 expect(()=>parser.getDefault('undefined'), 73 throwsIllegalArg(() => parser.getDefault('undefined'));
74 throwsArgumentError);
75 }); 74 });
76 }); 75 });
77 76
77 group('ArgParser.commands', () {
78 test('returns an empty map if there are no commands', () {
79 var parser = new ArgParser();
80 expect(parser.commands, isEmpty);
81 });
82
83 test('returns the commands that were added', () {
84 var parser = new ArgParser();
85 parser.addCommand('hide');
86 parser.addCommand('seek');
87 expect(parser.commands, hasLength(2));
88 expect(parser.commands['hide'], isNotNull);
89 expect(parser.commands['seek'], isNotNull);
90 });
91
92 test('iterates over the commands in the order they were added', () {
93 var parser = new ArgParser();
94 parser.addCommand('a');
95 parser.addCommand('d');
96 parser.addCommand('b');
97 parser.addCommand('c');
98 expect(parser.commands.keys, equals(['a', 'd', 'b', 'c']));
99 });
100 });
101
102 group('ArgParser.options', () {
103 test('returns an empty map if there are no options', () {
104 var parser = new ArgParser();
105 expect(parser.options, isEmpty);
106 });
107
108 test('returns the options that were added', () {
109 var parser = new ArgParser();
110 parser.addFlag('hide');
111 parser.addOption('seek');
112 expect(parser.options, hasLength(2));
113 expect(parser.options['hide'], isNotNull);
114 expect(parser.options['seek'], isNotNull);
115 });
116
117 test('iterates over the options in the order they were added', () {
118 var parser = new ArgParser();
119 parser.addFlag('a');
120 parser.addOption('d');
121 parser.addFlag('b');
122 parser.addOption('c');
123 expect(parser.options.keys, equals(['a', 'd', 'b', 'c']));
124 });
125 });
126
78 group('ArgResults.options', () { 127 group('ArgResults.options', () {
79 test('returns the provided options', () { 128 test('returns the provided options', () {
80 var parser = new ArgParser(); 129 var parser = new ArgParser();
81 parser.addFlag('woof'); 130 parser.addFlag('woof');
82 parser.addOption('meow'); 131 parser.addOption('meow');
83 var args = parser.parse(['--woof', '--meow', 'kitty']); 132 var args = parser.parse(['--woof', '--meow', 'kitty']);
84 expect(args.options, hasLength(2)); 133 expect(args.options, hasLength(2));
85 expect(args.options.any((o) => o == 'woof'), isTrue); 134 expect(args.options.any((o) => o == 'woof'), isTrue);
86 expect(args.options.any((o) => o == 'meow'), isTrue); 135 expect(args.options.any((o) => o == 'meow'), isTrue);
87 }); 136 });
(...skipping 18 matching lines...) Expand all
106 }); 155 });
107 } 156 }
108 157
109 throwsIllegalArg(function) { 158 throwsIllegalArg(function) {
110 expect(function, throwsArgumentError); 159 expect(function, throwsArgumentError);
111 } 160 }
112 161
113 throwsFormat(ArgParser parser, List<String> args) { 162 throwsFormat(ArgParser parser, List<String> args) {
114 expect(() => parser.parse(args), throwsFormatException); 163 expect(() => parser.parse(args), throwsFormatException);
115 } 164 }
OLDNEW
« no previous file with comments | « pkg/args/lib/src/utils.dart ('k') | pkg/args/test/command_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698