dash.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. var parse = require('../');
  3. var test = require('tape');
  4. test('-', function (t) {
  5. t.plan(6);
  6. t.deepEqual(parse(['-n', '-']), { n: '-', _: [] });
  7. t.deepEqual(parse(['--nnn', '-']), { nnn: '-', _: [] });
  8. t.deepEqual(parse(['-']), { _: ['-'] });
  9. t.deepEqual(parse(['-f-']), { f: '-', _: [] });
  10. t.deepEqual(
  11. parse(['-b', '-'], { boolean: 'b' }),
  12. { b: true, _: ['-'] }
  13. );
  14. t.deepEqual(
  15. parse(['-s', '-'], { string: 's' }),
  16. { s: '-', _: [] }
  17. );
  18. });
  19. test('-a -- b', function (t) {
  20. t.plan(2);
  21. t.deepEqual(parse(['-a', '--', 'b']), { a: true, _: ['b'] });
  22. t.deepEqual(parse(['--a', '--', 'b']), { a: true, _: ['b'] });
  23. });
  24. test('move arguments after the -- into their own `--` array', function (t) {
  25. t.plan(1);
  26. t.deepEqual(
  27. parse(['--name', 'John', 'before', '--', 'after'], { '--': true }),
  28. { name: 'John', _: ['before'], '--': ['after'] }
  29. );
  30. });
  31. test('--- option value', function (t) {
  32. // A multi-dash value is largely an edge case, but check the behaviour is as expected,
  33. // and in particular the same for short option and long option (as made consistent in Jan 2023).
  34. t.plan(2);
  35. t.deepEqual(parse(['-n', '---']), { n: '---', _: [] });
  36. t.deepEqual(parse(['--nnn', '---']), { nnn: '---', _: [] });
  37. });