num.js 792 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var parse = require('../');
  3. var test = require('tape');
  4. test('nums', function (t) {
  5. var argv = parse([
  6. '-x', '1234',
  7. '-y', '5.67',
  8. '-z', '1e7',
  9. '-w', '10f',
  10. '--hex', '0xdeadbeef',
  11. '789',
  12. ]);
  13. t.deepEqual(argv, {
  14. x: 1234,
  15. y: 5.67,
  16. z: 1e7,
  17. w: '10f',
  18. hex: 0xdeadbeef,
  19. _: [789],
  20. });
  21. t.deepEqual(typeof argv.x, 'number');
  22. t.deepEqual(typeof argv.y, 'number');
  23. t.deepEqual(typeof argv.z, 'number');
  24. t.deepEqual(typeof argv.w, 'string');
  25. t.deepEqual(typeof argv.hex, 'number');
  26. t.deepEqual(typeof argv._[0], 'number');
  27. t.end();
  28. });
  29. test('already a number', function (t) {
  30. var argv = parse(['-x', 1234, 789]);
  31. t.deepEqual(argv, { x: 1234, _: [789] });
  32. t.deepEqual(typeof argv.x, 'number');
  33. t.deepEqual(typeof argv._[0], 'number');
  34. t.end();
  35. });