time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

short.js (1593B)


      1 var parse = require('../');
      2 var test = require('tape');
      3 
      4 test('numeric short args', function (t) {
      5     t.plan(2);
      6     t.deepEqual(parse([ '-n123' ]), { n: 123, _: [] });
      7     t.deepEqual(
      8         parse([ '-123', '456' ]),
      9         { 1: true, 2: true, 3: 456, _: [] }
     10     );
     11 });
     12 
     13 test('short', function (t) {
     14     t.deepEqual(
     15         parse([ '-b' ]),
     16         { b : true, _ : [] },
     17         'short boolean'
     18     );
     19     t.deepEqual(
     20         parse([ 'foo', 'bar', 'baz' ]),
     21         { _ : [ 'foo', 'bar', 'baz' ] },
     22         'bare'
     23     );
     24     t.deepEqual(
     25         parse([ '-cats' ]),
     26         { c : true, a : true, t : true, s : true, _ : [] },
     27         'group'
     28     );
     29     t.deepEqual(
     30         parse([ '-cats', 'meow' ]),
     31         { c : true, a : true, t : true, s : 'meow', _ : [] },
     32         'short group next'
     33     );
     34     t.deepEqual(
     35         parse([ '-h', 'localhost' ]),
     36         { h : 'localhost', _ : [] },
     37         'short capture'
     38     );
     39     t.deepEqual(
     40         parse([ '-h', 'localhost', '-p', '555' ]),
     41         { h : 'localhost', p : 555, _ : [] },
     42         'short captures'
     43     );
     44     t.end();
     45 });
     46  
     47 test('mixed short bool and capture', function (t) {
     48     t.same(
     49         parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
     50         {
     51             f : true, p : 555, h : 'localhost',
     52             _ : [ 'script.js' ]
     53         }
     54     );
     55     t.end();
     56 });
     57  
     58 test('short and long', function (t) {
     59     t.deepEqual(
     60         parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
     61         {
     62             f : true, p : 555, h : 'localhost',
     63             _ : [ 'script.js' ]
     64         }
     65     );
     66     t.end();
     67 });