Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

short.js 1.6KB

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