Skip to content
This repository
Browse code

partial tests cleanup

  • Loading branch information...
commit e702d5d73d976f4e2cfd8ee3f334ce2769a4575a 1 parent 20b8c14
Vitaly Puzrin authored January 08, 2013
38  test/appendConstDefault.js
@@ -5,28 +5,24 @@
5 5
 var assert = require('assert');
6 6
 
7 7
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
8  
-describe('ArgumentParser', function () {
9  
-  describe('....', function () {
10  
-    var parser;
11  
-    var args;
12 8
 
13  
-    it("TestOptionalsActionAppendConstWithDefault", function () {
14  
-      // Tests the append_const action for an Optional
15  
-      parser = new ArgumentParser({debug: true});
16  
-      parser.addArgument(['-b'], {action: 'appendConst', constant: 'Exception', defaultValue: ['X']});
17  
-      parser.addArgument(['-c'], {action: 'append', dest: 'b'});
18  
-      
19  
-      args = parser.parseArgs([]);
20  
-      assert.deepEqual(args, {b: ['X']});
21  
-      args = parser.parseArgs('-b'.split(' '));
22  
-      assert.deepEqual(args, {b: ['X', 'Exception']});
23  
-      args = parser.parseArgs('-b -cx -b -cyz'.split(' '));
24  
-      assert.deepEqual(args, {b: ['X', 'Exception', 'x', 'Exception', 'yz']});
25  
-      // problem is b not getting 'X' default
26  
-    });
  9
+describe('....', function () {
  10
+  var parser;
  11
+  var args;
  12
+
  13
+  it("TestOptionalsActionAppendConstWithDefault", function () {
  14
+    // Tests the append_const action for an Optional
  15
+    parser = new ArgumentParser({debug: true});
  16
+    parser.addArgument(['-b'], {action: 'appendConst', constant: 'Exception', defaultValue: ['X']});
  17
+    parser.addArgument(['-c'], {action: 'append', dest: 'b'});
  18
+
  19
+    args = parser.parseArgs([]);
  20
+    assert.deepEqual(args, {b: ['X']});
  21
+    args = parser.parseArgs('-b'.split(' '));
  22
+    assert.deepEqual(args, {b: ['X', 'Exception']});
  23
+    args = parser.parseArgs('-b -cx -b -cyz'.split(' '));
  24
+    assert.deepEqual(args, {b: ['X', 'Exception', 'x', 'Exception', 'yz']});
  25
+    // problem is b not getting 'X' default
27 26
   });
28 27
 });
29 28
 
30  
-/*
31  
-
32  
-*/
262  test/base.js
... ...
@@ -1,4 +1,4 @@
1  
-/*global describe, it, beforeEach*/
  1
+/*global describe, it*/
2 2
 
3 3
 
4 4
 'use strict';
@@ -6,140 +6,164 @@
6 6
 var assert = require('assert');
7 7
 
8 8
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
9  
-describe('ArgumentParser', function () {
10  
-  describe('base', function () {
11  
-    var parser;
12  
-    var args;
13  
-    beforeEach(function () {
14  
-      parser = new ArgumentParser({debug: true});
15  
-      parser.addArgument([ '-f', '--foo' ]);
16  
-    });
17 9
 
18  
-    it("should parse argument in short form", function () {
19  
-      args = parser.parseArgs('-f 1'.split(' '));
20  
-      assert.equal(args.foo, 1);
21  
-      args = parser.parseArgs('-f=1'.split(' '));
22  
-      assert.equal(args.foo, 1);
23  
-      args = parser.parseArgs('-f1'.split(' '));
24  
-      assert.equal(args.foo, 1);
25  
-    });
  10
+describe('base', function () {
  11
+  var parser;
  12
+  var args;
26 13
 
27  
-    it("should parse argument in long form", function () {
28  
-      args = parser.parseArgs('--foo 1'.split(' '));
29  
-      assert.equal(args.foo, 1);
30  
-      args = parser.parseArgs('--foo=1'.split(' '));
31  
-      assert.equal(args.foo, 1);
32  
-    });
  14
+  it("should parse argument in short form", function () {
  15
+    parser = new ArgumentParser({debug: true});
  16
+    parser.addArgument(['-f', '--foo']);
33 17
 
34  
-    it("should parse multiple arguments", function () {
35  
-      parser.addArgument(['--bar' ]);
36  
-      args = parser.parseArgs('--foo 5 --bar 6'.split(' '));
37  
-      assert.equal(args.foo, 5);
38  
-      assert.equal(args.bar, 6);
39  
-    });
  18
+    args = parser.parseArgs('-f 1'.split(' '));
  19
+    assert.equal(args.foo, 1);
  20
+    args = parser.parseArgs('-f=1'.split(' '));
  21
+    assert.equal(args.foo, 1);
  22
+    args = parser.parseArgs('-f1'.split(' '));
  23
+    assert.equal(args.foo, 1);
  24
+  });
40 25
 
41  
-    it("should check argument type", function () {
42  
-      parser.addArgument(['--bar' ], { type: 'int' });
43  
-      assert.throws(function () {
44  
-        parser.parseArgs('--bar bar'.split(' '));
45  
-      });
46  
-      assert.doesNotThrow(function () {
47  
-        parser.parseArgs('--bar 1'.split(' '));
48  
-      });
49  
-    });
  26
+  it("should parse argument in long form", function () {
  27
+    parser = new ArgumentParser({debug: true});
  28
+    parser.addArgument(['-f', '--foo']);
50 29
 
51  
-    it("should not drop down with empty args (without positional arguments)", function () {
52  
-      assert.doesNotThrow(function () {
53  
-        parser.parseArgs([]);
54  
-      });
55  
-    });
  30
+    args = parser.parseArgs('--foo 1'.split(' '));
  31
+    assert.equal(args.foo, 1);
  32
+    args = parser.parseArgs('--foo=1'.split(' '));
  33
+    assert.equal(args.foo, 1);
  34
+  });
56 35
 
57  
-    it("should drop down with empty args (positional arguments)", function () {
58  
-      parser.addArgument([ 'baz']);
59  
-      assert.throws(
60  
-        function () {parser.parseArgs([]); },
61  
-        /too few arguments/
62  
-      );
63  
-    });
  36
+  it("should parse multiple arguments", function () {
  37
+    parser = new ArgumentParser({debug: true});
  38
+    parser.addArgument(['-f', '--foo']);
  39
+    parser.addArgument(['--bar']);
64 40
 
65  
-    it("should support pseudo-argument", function () {
66  
-      parser.addArgument([ 'bar' ], { nargs: '+' });
67  
-      args = parser.parseArgs([ '-f', 'foo', '--', '-f', 'bar' ]);
68  
-      assert.equal(args.foo, 'foo');
69  
-      assert.equal(args.bar.length, 2);
70  
-    });
  41
+    args = parser.parseArgs('--foo 5 --bar 6'.split(' '));
  42
+    assert.equal(args.foo, 5);
  43
+    assert.equal(args.bar, 6);
  44
+  });
71 45
 
72  
-    it("should support #setDefaults", function () {
73  
-      parser.setDefaults({bar: 1});
74  
-      args = parser.parseArgs([]);
75  
-      assert.equal(args.bar, 1);
76  
-    });
  46
+  it("should check argument type", function () {
  47
+    parser = new ArgumentParser({debug: true});
  48
+    parser.addArgument(['-f', '--foo']);
  49
+    parser.addArgument(['--bar' ], { type: 'int' });
77 50
 
78  
-    it("should throw TypeError with conflicting options", function () {
79  
-      assert.throws(
80  
-        function () {
81  
-          parser.addArgument(['-f']);
82  
-        },
83  
-        /Conflicting option string/
84  
-      );
85  
-      assert.throws(
86  
-        function () {
87  
-          parser.addArgument(['--foo']);
88  
-        },
89  
-        /Conflicting option string/
90  
-      );
91  
-      assert.throws(
92  
-        function () {
93  
-          parser.addArgument(['-f', '--flame']);
94  
-        },
95  
-        /Conflicting option string/
96  
-      );
97  
-      assert.throws(
98  
-        function () {
99  
-          parser.addArgument(['-m', '--foo']);
100  
-        },
101  
-        /Conflicting option string/
102  
-      );
  51
+    assert.throws(function () {
  52
+      parser.parseArgs('--bar bar'.split(' '));
  53
+    });
  54
+    assert.doesNotThrow(function () {
  55
+      parser.parseArgs('--bar 1'.split(' '));
103 56
     });
  57
+  });
104 58
 
105  
-    it("should parse negative arguments", function () {
106  
-      parser.addArgument([ 'bar' ], { type: 'int', });
107  
-      args = parser.parseArgs(['-1']);
  59
+  it("should not drop down with empty args (without positional arguments)", function () {
  60
+    parser = new ArgumentParser({debug: true});
  61
+    parser.addArgument(['-f', '--foo']);
108 62
 
109  
-      assert.equal(args.bar, -1);
110  
-    });
  63
+    assert.doesNotThrow(function () { parser.parseArgs([]); });
  64
+  });
111 65
 
112  
-    it("should infer option destination from long and short options", function () {
113  
-      //parser.addArgument(['-f', '--foo']);        // from long option
114  
-      parser.addArgument(['-g']);                 // from short option
115  
-      parser.addArgument(['-x'], { dest: 'xxx' });// from dest keyword
116  
-
117  
-      args = parser.parseArgs(['-f', '1']);
118  
-      assert.deepEqual(args, { foo: '1', g: null, xxx: null});
119  
-      args = parser.parseArgs(['-g', '2']);
120  
-      assert.deepEqual(args, { foo: null, g: '2', xxx: null});
121  
-      args = parser.parseArgs(['-f', 1, '-g', 2, '-x', 3]);
122  
-      assert.deepEqual(args, { foo: 1, g: 2, xxx: 3});
123  
-    });
  66
+  it("should drop down with empty args (positional arguments)", function () {
  67
+    parser = new ArgumentParser({debug: true});
  68
+    parser.addArgument(['-f', '--foo']);
  69
+    parser.addArgument([ 'baz']);
124 70
 
125  
-    it("should accept 0 defaultValue", function () {
126  
-      parser.addArgument(['bar'], { nargs: '?', defaultValue: 0});
127  
-      args = parser.parseArgs([]);
128  
-      assert.equal(args.bar, 0);
129  
-      // could also test for '', and false
130  
-    });
  71
+    assert.throws(
  72
+      function ()  {parser.parseArgs([]); },
  73
+      /too few arguments/
  74
+    );
  75
+  });
131 76
 
132  
-    it("should accept defaultValue for nargs:'*'", function () {
133  
-      parser.addArgument(['bar'], { nargs: '*', defaultValue: 42});
134  
-      args = parser.parseArgs([]);
135  
-      assert.equal(args.bar, 42);
136  
-    });
  77
+  it("should support pseudo-argument", function () {
  78
+    parser = new ArgumentParser({debug: true});
  79
+    parser.addArgument(['-f', '--foo']);
  80
+    parser.addArgument([ 'bar' ], { nargs: '+' });
137 81
 
138  
-    it("getDefault() should get defaults", function () {
139  
-      parser.addArgument(['-g', '--goo'], {defaultValue: 42});
140  
-      assert.equal(parser.getDefault('goo'), 42);
141  
-      assert.equal(parser.getDefault('help'), require('../lib/const').SUPPRESS);
142  
-    });
  82
+    args = parser.parseArgs([ '-f', 'foo', '--', '-f', 'bar' ]);
  83
+    assert.equal(args.foo, 'foo');
  84
+    assert.equal(args.bar.length, 2);
  85
+  });
  86
+
  87
+  it("should support #setDefaults", function () {
  88
+    parser = new ArgumentParser({debug: true});
  89
+    parser.addArgument(['-f', '--foo']);
  90
+    parser.setDefaults({bar: 1});
  91
+
  92
+    args = parser.parseArgs([]);
  93
+    assert.equal(args.bar, 1);
  94
+  });
  95
+
  96
+  it("should throw TypeError with conflicting options", function () {
  97
+    parser = new ArgumentParser({debug: true});
  98
+    parser.addArgument(['-f', '--foo']);
  99
+
  100
+    assert.throws(
  101
+      function () { parser.addArgument(['-f']); },
  102
+      /Conflicting option string/
  103
+    );
  104
+    assert.throws(
  105
+      function () { parser.addArgument(['--foo']); },
  106
+      /Conflicting option string/
  107
+    );
  108
+    assert.throws(
  109
+      function () { parser.addArgument(['-f', '--flame']); },
  110
+      /Conflicting option string/
  111
+    );
  112
+    assert.throws(
  113
+      function () { parser.addArgument(['-m', '--foo']); },
  114
+      /Conflicting option string/
  115
+    );
  116
+  });
  117
+
  118
+  it("should parse negative arguments", function () {
  119
+    parser = new ArgumentParser({debug: true});
  120
+    parser.addArgument(['-f', '--foo']);
  121
+    parser.addArgument([ 'bar' ], { type: 'int', });
  122
+
  123
+    args = parser.parseArgs(['-1']);
  124
+    assert.equal(args.bar, -1);
  125
+  });
  126
+
  127
+  it("should infer option destination from long and short options", function () {
  128
+    parser = new ArgumentParser({debug: true});
  129
+    parser.addArgument(['-f', '--foo']);        // from long option
  130
+    parser.addArgument(['-g']);                 // from short option
  131
+    parser.addArgument(['-x'], { dest: 'xxx' });// from dest keyword
  132
+
  133
+    args = parser.parseArgs(['-f', '1']);
  134
+    assert.deepEqual(args, { foo: '1', g: null, xxx: null});
  135
+    args = parser.parseArgs(['-g', '2']);
  136
+    assert.deepEqual(args, { foo: null, g: '2', xxx: null});
  137
+    args = parser.parseArgs(['-f', 1, '-g', 2, '-x', 3]);
  138
+    assert.deepEqual(args, { foo: 1, g: 2, xxx: 3});
  139
+  });
  140
+
  141
+  it("should accept 0 defaultValue", function () {
  142
+    parser = new ArgumentParser({debug: true});
  143
+    parser.addArgument(['-f', '--foo']);
  144
+    parser.addArgument(['bar'], { nargs: '?', defaultValue: 0});
  145
+
  146
+    args = parser.parseArgs([]);
  147
+    assert.equal(args.bar, 0);
  148
+    // could also test for '', and false
  149
+  });
  150
+
  151
+  it("should accept defaultValue for nargs:'*'", function () {
  152
+    parser = new ArgumentParser({debug: true});
  153
+    parser.addArgument(['-f', '--foo']);
  154
+    parser.addArgument(['bar'], { nargs: '*', defaultValue: 42});
  155
+
  156
+    args = parser.parseArgs([]);
  157
+    assert.equal(args.bar, 42);
  158
+  });
  159
+
  160
+  it("getDefault() should get defaults", function () {
  161
+    parser = new ArgumentParser({debug: true});
  162
+    parser.addArgument(['-f', '--foo']);
  163
+    parser.addArgument(['-g', '--goo'], {defaultValue: 42});
  164
+
  165
+    assert.equal(parser.getDefault('goo'), 42);
  166
+    assert.equal(parser.getDefault('help'), require('../lib/const').SUPPRESS);
143 167
   });
144 168
 });
145 169
 
105  test/childgroups.js
@@ -6,56 +6,61 @@
6 6
 var assert = require('assert');
7 7
 
8 8
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
9  
-describe('ArgumentParser', function () {
10  
-  describe('group', function () {
11  
-    var args;
12  
-    var parentParser, group, xgroup, childParser;
13  
-    beforeEach(function () {
14  
-      // parent has name group and exclusive group that should be passed to child
15  
-      parentParser = new ArgumentParser({prog: 'PROG', debug: true, addHelp: false});
16  
-      parentParser.addArgument(['--foo'], {help: 'parent foo'});
17  
-      // parentParser.addArgument(['pbar'], {help: 'parent positional'});
18  
-      group = parentParser.addArgumentGroup({title: 'parent group'});
19  
-      group.addArgument(['--gfoo'], {help: 'group foo help'});
20  
-      group.addArgument(['gbar'], {help: 'group bar help'});
21  
-      xgroup = parentParser.addMutuallyExclusiveGroup({required: true});
22  
-      xgroup.addArgument(['--xfoo'], {action: 'storeTrue', help: 'xfoo or xbar, set true'});
23  
-      xgroup.addArgument(['--xbar'], {action: 'storeFalse', help: 'xfoo or xbar, set false'});
24  
-      childParser = new ArgumentParser({parents: [parentParser], description: 'child parser', debug: true});
25  
-      childParser.addArgument(['--cbar'], {help: 'child bar opt arg'});
26  
-    });
27  
-    it('compare help parent and child', function () {
28  
-      // format helps and compare selected passages
29  
-      var phelp = parentParser.formatHelp();
30  
-      var chelp = childParser.formatHelp();
31  
-      assert(phelp.match(/parent group:/));
32  
-      assert(chelp.match(/parent group:/));
33  
-    });
34  
-    it('child should  throw error if an xclusive group member is missing', function () {
35  
-      assert.throws(
36  
-        function () {
37  
-          args = childParser.parseArgs(['gbararg']);
38  
-        },
39  
-        /one of the arguments (.*) is required/i
40  
-      );
41  
-    });
42  
-    it('child accepts an xgroup item and positional arg from parent', function () {
43  
-      args = childParser.parseArgs(['--xbar', 'gbararg']);
44  
-      assert.equal(args.gbar, 'gbararg');
45  
-      assert.equal(args.xbar, false);
46  
-    });
47  
-    it('', function () {
48  
-      args = childParser.parseArgs(['--foo', 'fooarg', 'gbararg', '--xfoo']);
49  
-      assert.equal(args.foo, 'fooarg');
50  
-    });
51  
-    it('child throws error if both xclusive options are given', function () {
52  
-      assert.throws(
53  
-        function () {
54  
-          args = childParser.parseArgs(['--xfoo', '--xbar']);
55  
-        },
56  
-        /Not allowed with argument/i
57  
-      );
58  
-    });
  9
+
  10
+describe('group', function () {
  11
+  var args;
  12
+  var parentParser, group, xgroup, childParser;
  13
+
  14
+  beforeEach(function () {
  15
+    // parent has name group and exclusive group that should be passed to child
  16
+    parentParser = new ArgumentParser({prog: 'PROG', debug: true, addHelp: false});
  17
+    parentParser.addArgument(['--foo'], {help: 'parent foo'});
  18
+    // parentParser.addArgument(['pbar'], {help: 'parent positional'});
  19
+    group = parentParser.addArgumentGroup({title: 'parent group'});
  20
+    group.addArgument(['--gfoo'], {help: 'group foo help'});
  21
+    group.addArgument(['gbar'], {help: 'group bar help'});
  22
+    xgroup = parentParser.addMutuallyExclusiveGroup({required: true});
  23
+    xgroup.addArgument(['--xfoo'], {action: 'storeTrue', help: 'xfoo or xbar, set true'});
  24
+    xgroup.addArgument(['--xbar'], {action: 'storeFalse', help: 'xfoo or xbar, set false'});
  25
+    childParser = new ArgumentParser({parents: [parentParser], description: 'child parser', debug: true});
  26
+    childParser.addArgument(['--cbar'], {help: 'child bar opt arg'});
  27
+  });
  28
+
  29
+  it('compare help parent and child', function () {
  30
+    // format helps and compare selected passages
  31
+    var phelp = parentParser.formatHelp();
  32
+    var chelp = childParser.formatHelp();
  33
+    assert(phelp.match(/parent group:/));
  34
+    assert(chelp.match(/parent group:/));
  35
+  });
  36
+
  37
+  it('child should  throw error if an xclusive group member is missing', function () {
  38
+    assert.throws(
  39
+      function () {
  40
+        args = childParser.parseArgs(['gbararg']);
  41
+      },
  42
+      /one of the arguments (.*) is required/
  43
+    );
  44
+  });
  45
+
  46
+  it('child accepts an xgroup item and positional arg from parent', function () {
  47
+    args = childParser.parseArgs(['--xbar', 'gbararg']);
  48
+    assert.equal(args.gbar, 'gbararg');
  49
+    assert.equal(args.xbar, false);
  50
+  });
  51
+
  52
+  it('', function () {
  53
+    args = childParser.parseArgs(['--foo', 'fooarg', 'gbararg', '--xfoo']);
  54
+    assert.equal(args.foo, 'fooarg');
  55
+  });
  56
+
  57
+  it('child throws error if both xclusive options are given', function () {
  58
+    assert.throws(
  59
+      function () {
  60
+        args = childParser.parseArgs(['--xfoo', '--xbar']);
  61
+      },
  62
+      /Not allowed with argument/
  63
+    );
59 64
   });
60 65
 });
61 66
 
107  test/choices.js
... ...
@@ -1,4 +1,4 @@
1  
-/*global describe, it, beforeEach*/
  1
+/*global describe, it*/
2 2
 
3 3
 
4 4
 'use strict';
@@ -7,62 +7,65 @@ var assert = require('assert');
7 7
 
8 8
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
9 9
 
10  
-describe('ArgumentParser', function () {
11  
-  describe('sub-commands', function () {
12  
-    var parser;
13  
-    var args;
  10
+describe('sub-commands', function () {
  11
+  var parser;
  12
+  var args;
14 13
 
15  
-    beforeEach(function () {
16  
-      parser = new ArgumentParser({debug: true});
17  
-    });
  14
+  it("should store correct choice(choices defined as string)", function () {
  15
+    parser = new ArgumentParser({ debug: true });
  16
+    parser.addArgument(['--foo'], {choices: 'abc'});
18 17
 
19  
-    it("should store correct choice(choices defined as string)", function () {
20  
-      parser.addArgument(['--foo'], {choices: 'abc'});
21  
-      args = parser.parseArgs('--foo a'.split(' '));
22  
-      assert.equal(args.foo, 'a');
23  
-    });
  18
+    args = parser.parseArgs('--foo a'.split(' '));
  19
+    assert.equal(args.foo, 'a');
  20
+  });
  21
+
  22
+  it("should drop down with 'Invalid choice' error for incorrect choices(choices defined as string)", function () {
  23
+    parser = new ArgumentParser({ debug: true });
  24
+    parser.addArgument(['--foo'], {choices: 'abc'});
24 25
 
25  
-    it("should drop down with 'Invalid choice' error for incorrect choices(choices defined as string)", function () {
26  
-      parser.addArgument(['--foo'], {choices: 'abc'});
27  
-      assert.throws(
28  
-        function () {
29  
-          args = parser.parseArgs('--foo e'.split(' '));
30  
-          console.dir(args);
31  
-        },
32  
-        /Invalid choice:/
33  
-      );
34  
-      assert.throws(
35  
-        function () {
36  
-          args = parser.parseArgs('--foo 0'.split(' '));
37  
-          console.dir(args);
38  
-        },
39  
-        /Invalid choice:/
40  
-      );
41  
-    });
  26
+    assert.throws(
  27
+      function () {
  28
+        args = parser.parseArgs('--foo e'.split(' '));
  29
+        console.dir(args);
  30
+      },
  31
+      /Invalid choice:/
  32
+    );
  33
+    assert.throws(
  34
+      function () {
  35
+        args = parser.parseArgs('--foo 0'.split(' '));
  36
+        console.dir(args);
  37
+      },
  38
+      /Invalid choice:/
  39
+    );
  40
+  });
42 41
 
43 42
 
44  
-    it("should store correct choice(choices defined as array)", function () {
45  
-      parser.addArgument(['--foo'], {choices: ['a', 'abc', 'd']});
46  
-      args = parser.parseArgs('--foo abc'.split(' '));
47  
-      assert.equal(args.foo, 'abc');
48  
-    });
  43
+  it("should store correct choice(choices defined as array)", function () {
  44
+    parser = new ArgumentParser({ debug: true });
  45
+    parser.addArgument(['--foo'], {choices: ['a', 'abc', 'd']});
49 46
 
50  
-    it("should drop down with 'Invalid choice' error for incorrect choices(choices defined as array)", function () {
51  
-      parser.addArgument(['--foo'], {choices: ['a', 'abc', 'd']});
52  
-      assert.throws(
53  
-        function () {
54  
-          args = parser.parseArgs('--foo e'.split(' '));
55  
-          console.dir(args);
56  
-        },
57  
-        /Invalid choice:/
58  
-      );
59  
-      assert.throws(
60  
-        function () {
61  
-          args = parser.parseArgs('--foo 0'.split(' '));
62  
-          console.dir(args);
63  
-        },
64  
-        /Invalid choice:/
65  
-      );
66  
-    });
  47
+    args = parser.parseArgs('--foo abc'.split(' '));
  48
+    assert.equal(args.foo, 'abc');
  49
+  });
  50
+
  51
+  it("should drop down with 'Invalid choice' error for incorrect choices(choices defined as array)", function () {
  52
+    parser = new ArgumentParser({ debug: true });
  53
+    parser.addArgument(['--foo'], {choices: ['a', 'abc', 'd']});
  54
+
  55
+    assert.throws(
  56
+      function () {
  57
+        args = parser.parseArgs('--foo e'.split(' '));
  58
+        console.dir(args);
  59
+      },
  60
+      /Invalid choice:/
  61
+    );
  62
+    assert.throws(
  63
+      function () {
  64
+        args = parser.parseArgs('--foo 0'.split(' '));
  65
+        console.dir(args);
  66
+      },
  67
+      /Invalid choice:/
  68
+    );
67 69
   });
68 70
 });
  71
+
85  test/constant.js
@@ -6,49 +6,48 @@ var assert = require('assert');
6 6
 
7 7
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
8 8
 
9  
-describe('ArgumentParser', function () {
10  
-  describe('constant actions', function () {
11  
-    var parser;
12  
-    var args;
13  
-
14  
-    beforeEach(function () {
15  
-      parser = new ArgumentParser({debug: true});
16  
-    });
17  
-
18  
-    it("storeConst should store constant as given", function () {
19  
-      parser.addArgument(['-a'], {action: 'storeConst', dest:   'answer',
20  
-            help:   'store constant', constant: 42});
21  
-      args = parser.parseArgs('-a'.split(' '));
22  
-      assert.equal(args.answer, '42');
23  
-    });
24  
-
25  
-    it("storeConst should give error if constant not given (or misspelled)", function () {
26  
-      assert.throws(
27  
-        function () {
28  
-            parser.addArgument(['-a'], {action: 'storeConst', dest:   'answer',
29  
-                help:   'store constant', const: 42});
30  
-          },
31  
-        /constant option is required for storeAction/
32  
-        );
33  
-    });
34  
-    
35  
-    it("appendConst should append constant as given", function () {
36  
-      parser.addArgument([ '--str' ], {action: 'appendConst', dest:   'types',
37  
-        help:   'append constant "str" to types', constant: 'str'});
38  
-      parser.addArgument([ '--int' ], {action: 'appendConst', dest:   'types',
39  
-        help:   'append constant "int" to types', constant: 'int'});
40  
-      args = parser.parseArgs('--str --int'.split(' '));
41  
-      assert.deepEqual(args.types, [ 'str', 'int' ]);
42  
-    });
43  
-    
44  
-    it("appendConst should give error if constant not given (or misspelled)", function () {
45  
-      assert.throws(
46  
-        function () {
47  
-            parser.addArgument(['-a'], {action: 'appendConst', dest:   'answer',
48  
-                help:   'store constant', const: 42});
49  
-          },
50  
-        /constant option is required for appendAction/
  9
+describe('constant actions', function () {
  10
+  var parser;
  11
+  var args;
  12
+
  13
+  beforeEach(function () {
  14
+    parser = new ArgumentParser({debug: true});
  15
+  });
  16
+
  17
+  it("storeConst should store constant as given", function () {
  18
+    parser.addArgument(['-a'], {action: 'storeConst', dest:   'answer',
  19
+          help:   'store constant', constant: 42});
  20
+    args = parser.parseArgs('-a'.split(' '));
  21
+    assert.equal(args.answer, '42');
  22
+  });
  23
+
  24
+  it("storeConst should give error if constant not given (or misspelled)", function () {
  25
+    assert.throws(
  26
+      function () {
  27
+          parser.addArgument(['-a'], {action: 'storeConst', dest:   'answer',
  28
+              help:   'store constant', const: 42});
  29
+        },
  30
+      /constant option is required for storeAction/
51 31
       );
52  
-    });
  32
+  });
  33
+
  34
+  it("appendConst should append constant as given", function () {
  35
+    parser.addArgument([ '--str' ], {action: 'appendConst', dest:   'types',
  36
+      help:   'append constant "str" to types', constant: 'str'});
  37
+    parser.addArgument([ '--int' ], {action: 'appendConst', dest:   'types',
  38
+      help:   'append constant "int" to types', constant: 'int'});
  39
+    args = parser.parseArgs('--str --int'.split(' '));
  40
+    assert.deepEqual(args.types, [ 'str', 'int' ]);
  41
+  });
  42
+
  43
+  it("appendConst should give error if constant not given (or misspelled)", function () {
  44
+    assert.throws(
  45
+      function () {
  46
+          parser.addArgument(['-a'], {action: 'appendConst', dest:   'answer',
  47
+              help:   'store constant', const: 42});
  48
+        },
  49
+      /constant option is required for appendAction/
  50
+    );
53 51
   });
54 52
 });
  53
+
64  test/helpargs.js
@@ -5,40 +5,36 @@
5 5
 var assert = require('assert');
6 6
 
7 7
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
8  
-describe('ArgumentParser', function () {
9  
-  describe('....', function () {
10  
-    var parser;
11  
-    var args;
12  
-    
13  
-    it("TestParserDefault42", function () {
14  
-      // Test actions with a parser-level default of 42
15  
-      parser = new ArgumentParser({debug: true, argumentDefault: 42, version: '1.0'});
16  
-      parser.addArgument(['foo'], {nargs: '?'});
17  
-      parser.addArgument(['bar'], {nargs: '*'});
18  
-      parser.addArgument(['--baz'], {action: 'storeTrue'});
19  
-
20  
-      args = parser.parseArgs([]);
21  
-      assert.deepEqual(args, {bar: 42, foo: 42, baz: 42 });
22  
-      // problem is with 42 being assigned as default to help
23  
-    });
24  
-    
25  
-    it("TestOptionalsAlternatePrefixCharsAddedHelp", function () {
26  
-      /* When ``-`` not in prefix_chars, default operators created for help
27  
-      *  should use the prefix_chars in use rather than - or --
28  
-      *  http://bugs.python.org/issue9444
29  
-      */
30  
-      parser = new ArgumentParser({debug: true, prefixChars: '+:/', addHelp: true});
31  
-      parser.addArgument(['+f'], {action: 'storeTrue'});
32  
-      parser.addArgument(['::bar']);
33  
-      parser.addArgument(['/baz'], {action: 'storeConst', constant: 42});
34  
-      // parser.printHelp()
35  
-      args = parser.parseArgs([]);
36  
-      assert.deepEqual(args, {f: false, bar: null, baz: null});
37  
-      //
38  
-    });
  8
+
  9
+describe('....', function () {
  10
+  var parser;
  11
+  var args;
  12
+
  13
+  it("TestParserDefault42", function () {
  14
+    // Test actions with a parser-level default of 42
  15
+    parser = new ArgumentParser({debug: true, argumentDefault: 42, version: '1.0'});
  16
+    parser.addArgument(['foo'], {nargs: '?'});
  17
+    parser.addArgument(['bar'], {nargs: '*'});
  18
+    parser.addArgument(['--baz'], {action: 'storeTrue'});
  19
+
  20
+    args = parser.parseArgs([]);
  21
+    assert.deepEqual(args, {bar: 42, foo: 42, baz: 42 });
  22
+    // problem is with 42 being assigned as default to help
39 23
   });
40  
-});
41 24
 
42  
-/*
  25
+  it("TestOptionalsAlternatePrefixCharsAddedHelp", function () {
  26
+    /* When ``-`` not in prefix_chars, default operators created for help
  27
+    *  should use the prefix_chars in use rather than - or --
  28
+    *  http://bugs.python.org/issue9444
  29
+    */
  30
+    parser = new ArgumentParser({debug: true, prefixChars: '+:/', addHelp: true});
  31
+    parser.addArgument(['+f'], {action: 'storeTrue'});
  32
+    parser.addArgument(['::bar']);
  33
+    parser.addArgument(['/baz'], {action: 'storeConst', constant: 42});
  34
+    // parser.printHelp()
  35
+    args = parser.parseArgs([]);
  36
+    assert.deepEqual(args, {f: false, bar: null, baz: null});
  37
+    //
  38
+  });
  39
+});
43 40
 
44  
-*/
26  test/namespace.js
@@ -5,19 +5,19 @@
5 5
 var assert = require('assert');
6 6
 
7 7
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
8  
-describe('ArgumentParser', function () {
9  
-  describe('....', function () {
10  
-    var parser;
11  
-    var args;
12  
-        
13  
-    it("TestPositionalsNargsOptional", function () {
14  
-      // Tests an Optional Positional
15  
-      parser = new ArgumentParser({debug: true});
16  
-      parser.addArgument(['foo'], {nargs: '?'});
17 8
 
18  
-      args = parser.parseArgs([]);
19  
-      assert.deepEqual(args, {foo: null});
20  
-      // sample case where null value is not in the namespace
21  
-    });
  9
+describe('....', function () {
  10
+  var parser;
  11
+  var args;
  12
+
  13
+  it("TestPositionalsNargsOptional", function () {
  14
+    // Tests an Optional Positional
  15
+    parser = new ArgumentParser({debug: true});
  16
+    parser.addArgument(['foo'], {nargs: '?'});
  17
+
  18
+    args = parser.parseArgs([]);
  19
+    assert.deepEqual(args, {foo: null});
  20
+    // sample case where null value is not in the namespace
22 21
   });
23 22
 });
  23
+
96  test/negarg.js
... ...
@@ -1,4 +1,4 @@
1  
-/*global describe, it, beforeEach*/
  1
+/*global describe, it*/
2 2
 // adapted from the Python argparse documentation
3 3
 // section "args with -"
4 4
 
@@ -7,53 +7,53 @@
7 7
 var assert = require('assert');
8 8
 
9 9
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
10  
-describe('ArgumentParser', function () {
11  
-  describe('base', function () {
12  
-    var parser;
13  
-    var args;
14  
-    beforeEach(function () {
15  
-      parser = new ArgumentParser({debug: true});
16  
-      //parser.addArgument([ '-f', '--foo' ]);
17  
-    });
18  
-
19  
-    it("No negative number options; neg number is positional argument", function () {
20  
-      parser.addArgument(['-x'], {dest: 'x'});
21  
-      parser.addArgument(['foo'], {nargs: '?'});
22  
-      // no negative number options, so -1 is a positional argument
23  
-      args = parser.parseArgs(['-x', '-1']);
24  
-      // Namespace(foo=None, x='-1')
25  
-      assert.equal(args.x, '-1');
26  
-      // no negative number options, so -1 and -5 are positional arguments
27  
-      args = parser.parseArgs(['-x', '-1', '-5']);
28  
-      // Namespace(foo='-5', x='-1') order not determined
29  
-      assert.equal(args.x, '-1');
30  
-      assert.equal(args.foo, '-5');
31  
-    });
32  
-    it("negative number options present, so any neg number is an option", function () {
33  
-      parser.addArgument(['-1'], {dest: 'one'});
34  
-      parser.addArgument(['foo'], {nargs: '?'});
35  
-      // negative number options present, so -1 is an option
36  
-      args = parser.parseArgs(['-1', 'X']);
37  
-      // Namespace(foo=None, one='X')
38  
-      assert.equal(args.one, 'X');
39  
-      // negative number options present, so -2 is an option
40  
-      assert.throws(
41  
-        function () {
42  
-          parser.parseArgs(['-2']);
43  
-        },
44  
-        /Unrecognized arguments: -2/
45  
-      );
46  
-      // negative number options present, so both -1s are options
47  
-      assert.throws(
48  
-        function () {
49  
-          parser.parseArgs(['-1', '-1']);
50  
-        },
51  
-        /argument "-1": Expected one argument/
52  
-      );
53  
-      args = parser.parseArgs(['--', '-f']);
54  
-      // Namespace(foo='-f', one=None)
55  
-      assert.equal(args.foo, '-f');
56  
-    });
  10
+
  11
+describe('base', function () {
  12
+  var parser;
  13
+  var args;
  14
+
  15
+  it("No negative number options; neg number is positional argument", function () {
  16
+    parser = new ArgumentParser({debug: true});
  17
+    parser.addArgument(['-x'], {dest: 'x'});
  18
+    parser.addArgument(['foo'], {nargs: '?'});
  19
+
  20
+    // no negative number options, so -1 is a positional argument
  21
+    args = parser.parseArgs(['-x', '-1']);
  22
+    // Namespace(foo=None, x='-1')
  23
+    assert.equal(args.x, '-1');
  24
+    // no negative number options, so -1 and -5 are positional arguments
  25
+    args = parser.parseArgs(['-x', '-1', '-5']);
  26
+    // Namespace(foo='-5', x='-1') order not determined
  27
+    assert.equal(args.x, '-1');
  28
+    assert.equal(args.foo, '-5');
  29
+  });
  30
+
  31
+  it("negative number options present, so any neg number is an option", function () {
  32
+    parser = new ArgumentParser({debug: true});
  33
+    parser.addArgument(['-1'], {dest: 'one'});
  34
+    parser.addArgument(['foo'], {nargs: '?'});
  35
+
  36
+    // negative number options present, so -1 is an option
  37
+    args = parser.parseArgs(['-1', 'X']);
  38
+    // Namespace(foo=None, one='X')
  39
+    assert.equal(args.one, 'X');
  40
+    // negative number options present, so -2 is an option
  41
+    assert.throws(
  42
+      function () {
  43
+        parser.parseArgs(['-2']);
  44
+      },
  45
+      /Unrecognized arguments: -2/
  46
+    );
  47
+    // negative number options present, so both -1s are options
  48
+    assert.throws(
  49
+      function () {
  50
+        parser.parseArgs(['-1', '-1']);
  51
+      },
  52
+      /argument "-1": Expected one argument/
  53
+    );
  54
+    args = parser.parseArgs(['--', '-f']);
  55
+    // Namespace(foo='-f', one=None)
  56
+    assert.equal(args.foo, '-f');
57 57
   });
58 58
 });
59 59
 
38  test/optionalstar.js
@@ -5,28 +5,24 @@
5 5
 var assert = require('assert');
6 6
 
7 7
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
8  
-describe('ArgumentParser', function () {
9  
-  describe('....', function () {
10  
-    var parser;
11  
-    var args;
12 8
 
13  
-    it("TestOptionalsNargsZeroOrMore(ParserTestCase", function () {
14  
-      // Tests specifying an args for an Optional that accepts zero or more
15  
-      parser = new ArgumentParser({debug: true});
16  
-      parser.addArgument(['-x'], {nargs: '*'});
17  
-      parser.addArgument(['-y'], {nargs: '*', defaultValue: 'spam'});
18  
-      
19  
-      args = parser.parseArgs([]);
20  
-      assert.deepEqual(args, {x: null, y: 'spam'});
21  
-      args = parser.parseArgs('-x a b'.split(' '));
22  
-      assert.deepEqual(args, {x: ['a', 'b'], y: 'spam'});
23  
-      args = parser.parseArgs('-y'.split(' '));
24  
-      assert.deepEqual(args, {x: null, y: []});
25  
-      // problem is y not getting its default
26  
-    });
  9
+describe('....', function () {
  10
+  var parser;
  11
+  var args;
  12
+
  13
+  it("TestOptionalsNargsZeroOrMore(ParserTestCase", function () {
  14
+    // Tests specifying an args for an Optional that accepts zero or more
  15
+    parser = new ArgumentParser({debug: true});
  16
+    parser.addArgument(['-x'], {nargs: '*'});
  17
+    parser.addArgument(['-y'], {nargs: '*', defaultValue: 'spam'});
  18
+
  19
+    args = parser.parseArgs([]);
  20
+    assert.deepEqual(args, {x: null, y: 'spam'});
  21
+    args = parser.parseArgs('-x a b'.split(' '));
  22
+    assert.deepEqual(args, {x: ['a', 'b'], y: 'spam'});
  23
+    args = parser.parseArgs('-y'.split(' '));
  24
+    assert.deepEqual(args, {x: null, y: []});
  25
+    // problem is y not getting its default
27 26
   });
28 27
 });
29 28
 
30  
-/*
31  
-
32  
-*/
53  test/parents.js
@@ -7,40 +7,39 @@ var assert = require('assert');
7 7
 
8 8
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
9 9
 
10  
-describe('ArgumentParser', function () {
11  
-  describe('sub-commands', function () {
12  
-    var parent_parser;
13  
-    var args;
  10
+describe('sub-commands', function () {
  11
+  var parent_parser;
  12
+  var args;
14 13
 
15  
-    beforeEach(function () {
16  
-      parent_parser = new ArgumentParser({debug: true, addHelp: false});
17  
-      parent_parser.addArgument(['--parent']);
  14
+  beforeEach(function () {
  15
+    parent_parser = new ArgumentParser({debug: true, addHelp: false});
  16
+    parent_parser.addArgument(['--parent']);
  17
+  });
  18
+
  19
+  it("should parse args from parents parser", function () {
  20
+    var parser = new ArgumentParser({
  21
+      parents: [ parent_parser ],
18 22
     });
  23
+    parser.addArgument(['-f', '--foo']);
19 24
 
20  
-    it("should parse args from parents parser", function () {
21  
-      var parser = new ArgumentParser({
22  
-        parents: [ parent_parser ],
23  
-      });
24  
-      parser.addArgument(['-f', '--foo']);
  25
+    args = parser.parseArgs('-f 1 --parent 2'.split(' '));
  26
+    assert.equal(args.foo, 1);
  27
+    assert.equal(args.parent, 2);
25 28
 
26  
-      args = parser.parseArgs('-f 1 --parent 2'.split(' '));
27  
-      assert.equal(args.foo, 1);
28  
-      assert.equal(args.parent, 2);
  29
+    args = parser.parseArgs('-f 1'.split(' '));
  30
+    assert.equal(args.foo, 1);
  31
+    assert.strictEqual(args.parent, null);
  32
+  });
29 33
 
30  
-      args = parser.parseArgs('-f 1'.split(' '));
31  
-      assert.equal(args.foo, 1);
32  
-      assert.strictEqual(args.parent, null);
  34
+  it("should throw error if has same args as parent", function () {
  35
+    var parser = new ArgumentParser({
  36
+      parents: [ parent_parser ],
33 37
     });
  38
+    parser.addArgument(['-f', '--foo']);
34 39
 
35  
-    it("should throw error if has same args as parent", function () {
36  
-      var parser = new ArgumentParser({
37  
-        parents: [ parent_parser ],
38  
-      });
39  
-      parser.addArgument(['-f', '--foo']);
40  
-
41  
-      assert.throws(function () {
42  
-        parent_parser.addArgument(['--parent']);
43  
-      });
  40
+    assert.throws(function () {
  41
+      parent_parser.addArgument(['--parent']);
44 42
     });
45 43
   });
46 44
 });
  45
+
29  test/positionalappend.js
@@ -5,24 +5,19 @@
5 5
 var assert = require('assert');
6 6
 
7 7
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
8  
-describe('ArgumentParser', function () {
9  
-  describe('....', function () {
10  
-    var parser;
11  
-    var args;
12  
-    
13  
-    it("TestPositionalsActionAppend", function () {
14  
-      // Test the 'append' action
15  
-      parser = new ArgumentParser({debug: true});
16  
-      parser.addArgument(['spam'], {action: 'append'});
17  
-      parser.addArgument(['spam'], {action: 'append', nargs: 2});
18 8
 
19  
-      args = parser.parseArgs('a b c'.split(' '));
20  
-      assert.deepEqual(args, {spam: [ 'a', [ 'b', 'c' ] ]});
21  
-      //
22  
-    });
  9
+describe('....', function () {
  10
+  var parser;
  11
+  var args;
  12
+
  13
+  it("TestPositionalsActionAppend", function () {
  14
+    // Test the 'append' action
  15
+    parser = new ArgumentParser({debug: true});
  16
+    parser.addArgument(['spam'], {action: 'append'});
  17
+    parser.addArgument(['spam'], {action: 'append', nargs: 2});
  18
+
  19
+    args = parser.parseArgs('a b c'.split(' '));
  20
+    assert.deepEqual(args, {spam: [ 'a', [ 'b', 'c' ] ]});
23 21
   });
24 22
 });
25 23
 
26  
-/*
27  
-
28  
-*/
133  test/sub_commands.js
@@ -7,82 +7,81 @@ var assert = require('assert');
7 7
 
8 8
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
9 9
 
10  
-describe('ArgumentParser', function () {
11  
-  describe('sub-commands', function () {
12  
-    var parser;
13  
-    var args;
14  
-    var c1;
15  
-    var c2;
  10
+describe('sub-commands', function () {
  11
+  var parser;
  12
+  var args;
  13
+  var c1;
  14
+  var c2;
16 15
 
17  
-    beforeEach(function () {
18  
-      parser = new ArgumentParser({debug: true});
19  
-      var subparsers = parser.addSubparsers({
20  
-        title: 'subcommands',
21  
-        dest: 'subcommand_name'
22  
-      });
23  
-      c1 = subparsers.addParser('c1', {aliases: ['co']});
24  
-      c1.addArgument([ '-f', '--foo' ], {});
25  
-      c1.addArgument([ '-b', '--bar' ], {});
26  
-      c2 = subparsers.addParser('c2', {});
27  
-      c2.addArgument([ '--baz' ], {});
  16
+  beforeEach(function () {
  17
+    parser = new ArgumentParser({debug: true});
  18
+    var subparsers = parser.addSubparsers({
  19
+      title: 'subcommands',
  20
+      dest: 'subcommand_name'
28 21
     });
  22
+    c1 = subparsers.addParser('c1', {aliases: ['co']});
  23
+    c1.addArgument([ '-f', '--foo' ], {});
  24
+    c1.addArgument([ '-b', '--bar' ], {});
  25
+    c2 = subparsers.addParser('c2', {});
  26
+    c2.addArgument([ '--baz' ], {});
  27
+  });
29 28
 
30  
-    it("should store command name", function () {
31  
-      args = parser.parseArgs('c1 --foo 5'.split(' '));
32  
-      assert.equal(args.subcommand_name, 'c1');
33  
-    });
  29
+  it("should store command name", function () {
  30
+    args = parser.parseArgs('c1 --foo 5'.split(' '));
  31
+    assert.equal(args.subcommand_name, 'c1');
  32
+  });
34 33
 
35  
-    it("should store command arguments", function () {
36  
-      args = parser.parseArgs('c1 --foo 5 -b4'.split(' '));
37  
-      assert.equal(args.foo, 5);
38  
-      assert.equal(args.bar, 4);
39  
-    });
  34
+  it("should store command arguments", function () {
  35
+    args = parser.parseArgs('c1 --foo 5 -b4'.split(' '));
  36
+    assert.equal(args.foo, 5);
  37
+    assert.equal(args.bar, 4);
  38
+  });
40 39
 
41  
-    it("should have same behavior for alias and original command", function () {
42  
-      args = parser.parseArgs('c1 --foo 5 -b4'.split(' '));
43  
-      var aliasArgs = parser.parseArgs('co --foo 5 -b4'.split(' '));
44  
-      assert.equal(args.foo, aliasArgs.foo);
45  
-      assert.equal(args.bar, aliasArgs.bar);
46  
-    });
  40
+  it("should have same behavior for alias and original command", function () {
  41
+    args = parser.parseArgs('c1 --foo 5 -b4'.split(' '));
  42
+    var aliasArgs = parser.parseArgs('co --foo 5 -b4'.split(' '));
  43
+    assert.equal(args.foo, aliasArgs.foo);
  44
+    assert.equal(args.bar, aliasArgs.bar);
  45
+  });
47 46
 
48  
-    it("should have different behavior for different commands", function () {
49  
-      assert.doesNotThrow(function () {
50  
-        parser.parseArgs('c1 --foo 5 -b4'.split(' '));
51  
-      });
52  
-      assert.throws(function () {
53  
-        parser.parseArgs('c2 --foo 5 -b4'.split(' '));
54  
-      });
55  
-      assert.doesNotThrow(function () {
56  
-        parser.parseArgs('c2 --baz 1'.split(' '));
57  
-      });
58  
-      assert.throws(function () {
59  
-        parser.parseArgs('c1 --baz 1'.split(' '));
60  
-      });
  47
+  it("should have different behavior for different commands", function () {
  48
+    assert.doesNotThrow(function () {
  49
+      parser.parseArgs('c1 --foo 5 -b4'.split(' '));
61 50
     });
62  
-
63  
-    it("should drop down with 'Invalid choice' error if parse unrecognized command", function () {
64  
-      assert.throws(
65  
-        function () {parser.parseArgs('command --baz 1'.split(' ')); },
66  
-        /Invalid choice:/
67  
-      );
  51
+    assert.throws(function () {
  52
+      parser.parseArgs('c2 --foo 5 -b4'.split(' '));
68 53
     });
69  
-
70  
-    it("should drop down with empty args ('too few arguments' error)", function () {
71  
-      assert.throws(
72  
-        function () {parser.parseArgs([]); },
73  
-        /too few arguments/
74  
-      );
  54
+    assert.doesNotThrow(function () {
  55
+      parser.parseArgs('c2 --baz 1'.split(' '));
75 56
     });
76  
-
77  
-    it("should support #setDefaults", function () {
78  
-      c1.setDefaults({spam: 1});
79  
-      c2.setDefaults({eggs: 2});
80  
-      args = parser.parseArgs(['c1']);
81  
-      assert.equal(args.spam, 1);
82  
-      assert.strictEqual(args.eggs, undefined);
83  
-      args = parser.parseArgs(['c2']);
84  
-      assert.equal(args.eggs, 2);
85  
-      assert.strictEqual(args.spam, undefined);
  57
+    assert.throws(function () {
  58
+      parser.parseArgs('c1 --baz 1'.split(' '));
86 59
     });
87 60
   });
  61
+
  62
+  it("should drop down with 'Invalid choice' error if parse unrecognized command", function () {
  63
+    assert.throws(
  64
+      function () {parser.parseArgs('command --baz 1'.split(' ')); },
  65
+      /Invalid choice:/
  66
+    );
  67
+  });
  68
+
  69
+  it("should drop down with empty args ('too few arguments' error)", function () {
  70
+    assert.throws(
  71
+      function () {parser.parseArgs([]); },
  72
+      /too few arguments/
  73
+    );
  74
+  });
  75
+
  76
+  it("should support #setDefaults", function () {
  77
+    c1.setDefaults({spam: 1});
  78
+    c2.setDefaults({eggs: 2});
  79
+    args = parser.parseArgs(['c1']);
  80
+    assert.equal(args.spam, 1);
  81
+    assert.strictEqual(args.eggs, undefined);
  82
+    args = parser.parseArgs(['c2']);
  83
+    assert.equal(args.eggs, 2);
  84
+    assert.strictEqual(args.spam, undefined);
  85
+  });
88 86
 });
  87
+
350  test/testgroup.js
@@ -6,179 +6,183 @@
6 6
 var assert = require('assert');
7 7
 
8 8
 var ArgumentParser = require('../lib/argparse').ArgumentParser;
9  
-describe('ArgumentParser', function () {
10  
-  describe('group', function () {
11  
-    var parser;
12  
-    var args;
13  
-    var group;
14  
-    var group1;
15  
-    var group2;
16  
-    beforeEach(function () {