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

Unified Diff: test/parse_test.dart

Issue 975463004: Parse comma-separated multiple values. (Closed) Base URL: git@github.com:dart-lang/args@master
Patch Set: Code review changes Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« lib/src/arg_parser.dart ('K') | « test/args_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/parse_test.dart
diff --git a/test/parse_test.dart b/test/parse_test.dart
index 0dd00ba4956449006f339c44bc97b75b41f6360e..502210abd848a7dc3765d3b0676ccd692c6652ab 100644
--- a/test/parse_test.dart
+++ b/test/parse_test.dart
@@ -199,6 +199,51 @@ void main() {
parser.parse([]);
expect(a, isEmpty);
});
+
+ test('allowMultiple parses comma-separated strings', () {
+ var a;
+ var parser = new ArgParser();
+ parser.addOption('a',
+ allowMultiple: true, callback: (value) => a = value);
+
+ parser.parse(['--a=v,w', '--a=x']);
+ expect(a, equals(['v', 'w', 'x']));
+ });
+
+ test("allowMultiple doesn't parses comma-separated strings with "
+ "splitCommas: false", () {
+ var a;
+ var parser = new ArgParser();
+ parser.addOption('a',
+ allowMultiple: true,
+ splitCommas: false,
+ callback: (value) => a = value);
+
+ parser.parse(['--a=v,w', '--a=x']);
+ expect(a, equals(['v,w', 'x']));
+ });
+
+ test('allowMultiple parses empty strings', () {
+ var a;
+ var parser = new ArgParser();
+ parser.addOption('a',
+ allowMultiple: true, callback: (value) => a = value);
+
+ parser.parse(['--a=,v', '--a=w,', '--a=,', '--a=x,,y', '--a', '']);
+ expect(a, equals(['', 'v', 'w', '', '', '', 'x', '', 'y', '']));
+ });
+
+ test('allowMultiple with allowed parses comma-separated strings', () {
+ var a;
+ var parser = new ArgParser();
+ parser.addOption('a',
+ allowMultiple: true,
+ allowed: ['v', 'w', 'x'],
+ callback: (value) => a = value);
+
+ parser.parse(['--a=v,w', '--a=x']);
+ expect(a, equals(['v', 'w', 'x']));
+ });
});
group('abbreviations', () {
@@ -287,6 +332,14 @@ void main() {
throwsFormat(parser, ['-mprofile']);
});
+ test('throw if a comma-separated value is not allowed', () {
+ var parser = new ArgParser();
+ parser.addOption('mode', abbr: 'm', allowMultiple: true,
+ allowed: ['debug', 'release']);
+
+ throwsFormat(parser, ['-mdebug,profile']);
+ });
+
test('throw if any but the first is not a flag', () {
var parser = new ArgParser();
parser.addFlag('apple', abbr: 'a');
« lib/src/arg_parser.dart ('K') | « test/args_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698