Index: pkg/args/test/parse_all_test.dart |
diff --git a/pkg/args/test/parse_all_test.dart b/pkg/args/test/parse_all_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..55e50ce0a65a10716e2636440260c4e80e4a5dc5 |
--- /dev/null |
+++ b/pkg/args/test/parse_all_test.dart |
@@ -0,0 +1,92 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library parse_all_test; |
+ |
+import 'package:unittest/unittest.dart'; |
+import 'package:args/args.dart'; |
+ |
+main() { |
+ group('ArgParser.parse()', () { |
Bob Nystrom
2013/06/20 00:33:36
"ArgParser.parse(parseAllOptions: true)"
Andrei Mouravski
2013/06/22 00:54:02
Done.
|
+ var parser; |
+ var args; |
+ |
+ setUp(() { |
+ parser = new ArgParser(); |
+ args = <String>[]; |
+ }); |
+ |
+ group('starting with a non-option', () { |
+ test('followed by flag', () { |
+ parser.addFlag('flag'); |
+ args = ['A', '--flag']; |
+ |
+ var results = parser.parse(args); |
+ expect(results['flag'], isFalse); |
+ expect(results.rest, orderedEquals(args)); |
Bob Nystrom
2013/06/20 00:33:36
Don't other tests cover this?
Andrei Mouravski
2013/06/22 00:54:02
Not quite.
Bob Nystrom
2013/06/24 15:53:20
Can you be more specific? There are existing compr
Andrei Mouravski
2013/06/24 20:41:03
Done.
|
+ |
+ var resultsAll = parseAll(parser, args); |
+ expect(resultsAll['flag'], isTrue); |
+ expect(resultsAll.rest, equals(['A'])); |
+ }); |
+ |
+ test('followed by option', () { |
+ parser.addOption('opt'); |
+ args = ['A', '--opt']; |
+ |
+ var results = parser.parse(args); |
+ expect(results['opt'], isNull); |
+ expect(results.rest, orderedEquals(args)); |
+ |
+ expectThrows(parser, args, parseAllOptions: true); |
+ }); |
+ |
+ test('followed by option and value', () { |
+ parser.addOption('opt'); |
+ args = ['A', '--opt', 'V']; |
+ |
+ var results = parser.parse(args); |
+ expect(results['opt'], isNull); |
+ expect(results.rest, orderedEquals(args)); |
+ |
+ var resultsAll = parseAll(parser, args); |
+ expect(resultsAll['opt'], equals('V')); |
+ expect(resultsAll.rest, equals(['A'])); |
+ }); |
+ |
+ test('followed by unknown flag', () { |
+ args = ['A', '--xflag']; |
+ var results = parser.parse(args); |
+ expect(results.rest, orderedEquals(args)); |
+ |
+ expectThrows(parser, args, parseAllOptions: true); |
+ }); |
+ |
+ test('followed by unknown option and value', () { |
+ args = ['A', '--xopt', 'V']; |
+ var results = parser.parse(args); |
+ expect(results.rest, orderedEquals(args)); |
+ |
+ expectThrows(parser, args, parseAllOptions: true); |
+ }); |
+ |
+ test('followed by command', () { |
+ parser.addCommand('com'); |
+ args = ['A', 'com']; |
+ |
+ var results = parser.parse(args); |
+ expect(results.command, isNull); |
+ expect(results.rest, orderedEquals(args)); |
+ |
+ expectThrows(parser, args, parseAllOptions: true); |
+ }); |
+ }); |
+ }); |
+} |
+ArgResults parseAll(ArgParser parser, List<String> args) => |
+ parser.parse(args, parseAllOptions: true); |
Bob Nystrom
2013/06/20 00:33:36
I'd probably just inline this in the tests to make
Andrei Mouravski
2013/06/22 00:54:02
Done.
|
+ |
+expectThrows(ArgParser parser, List<String> args, {parseAllOptions: false}) => |
Bob Nystrom
2013/06/20 00:33:36
You're always passing true for parseAllOptions. Ju
Andrei Mouravski
2013/06/22 00:54:02
Done.
|
+ expect(() => parser.parse(args, parseAllOptions: parseAllOptions), |
+ throwsFormatException, reason: "with parseAllOptions: $parseAllOptions"); |