num.js 909 B

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