test.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var a = require('assert'),
  2. util = require('util'),
  3. parse = require('../lib/argsparser').parse;
  4. util.print('Run tests...\n');
  5. a.deepEqual(parse(), {node: __filename}, 'node script.js');
  6. a.deepEqual(parse(['-o']), {'-o': true}, 'node script.js -o');
  7. a.deepEqual(parse(['-o', 'true']), {'-o': true}, 'node script.js -o true');
  8. a.deepEqual(parse(['-o', 'false']), {'-o': false}, 'node script.js -o false');
  9. a.deepEqual(parse(['-o', '123']), {'-o': 123}, 'node script.js -o 123');
  10. a.deepEqual(parse(['--token', 'bla--bla']), {'--token': 'bla--bla'}, 'node script.js --token bla--bla');
  11. a.deepEqual(parse(['-o', '123.456']), {'-o': 123.456}, 'node script.js -o 123.456');
  12. a.deepEqual(parse(['-o', 'test']), {'-o': 'test'}, 'node script.js -o test');
  13. a.deepEqual(parse(['-a', 'testa', '-b', 'testb']), {'-a': 'testa', '-b': 'testb'}, 'node script.js -a testa -b testb');
  14. a.deepEqual(parse(['--a', 'testa', '--b', 'testb']), {'--a': 'testa', '--b': 'testb'}, 'node script.js --a testa --b testb ');
  15. a.deepEqual(parse(['-a', 'testa', '--b', 'testb']), {'-a': 'testa', '--b': 'testb'}, 'node script.js -a testa --b testb');
  16. a.deepEqual(parse(['--a', 'testa', '-b', 'testb']), {'--a': 'testa', '-b': 'testb'}, 'node script.js --a testa -b testb');
  17. a.deepEqual(parse(['-paths', '/test.js', '/test1.js']), {'-paths': ['/test.js', '/test1.js']}, 'node script.js -paths /test.js /test1.js');
  18. a.deepEqual(parse(['--paths', '/test.js', '/test1.js']), {'--paths': ['/test.js', '/test1.js']}, 'node script.js --paths /test.js /test1.js');
  19. a.deepEqual(parse(['--paths', '/test.js', '/test1.js', '-a', 'testa']), {'--paths': ['/test.js', '/test1.js'], '-a': 'testa'}, 'node script.js --paths /test.js /test1.js -a testa');
  20. a.deepEqual(parse(['--port', '80', '8080']), {'--port': [80, 8080]}, 'node server.js --port 80 8080');
  21. util.print('All tests ok\n');