runner.test('err-invalid-definition: invalid type values', function () {
  var argv = ['--one', 'something'];
  try {
    cliArgs([{ name: 'one', type: 'string' }], argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'INVALID_TYPE');
  }

  try {
    cliArgs([{ name: 'one', type: 234 }], argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'INVALID_TYPE');
  }

  try {
    cliArgs([{ name: 'one', type: {} }], argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'INVALID_TYPE');
  }

  a.doesNotThrow(function () {
    cliArgs([{ name: 'one', type: function type() {} }], argv);
  }, /invalid/i);
});
test('name-alias-mix: one of each', function () {
  var argv = [ '--one', '-t', '--three' ]
  var result = cliArgs(optionDefinitions, argv)
  a.strictEqual(result.one, true)
  a.strictEqual(result.two, true)
  a.strictEqual(result.three, true)
  a.strictEqual(result.four, undefined)
})
runner.test('option=value notation: two plus a regular notation', function () {
  var optionDefinitions = [{ name: 'one' }, { name: 'two' }, { name: 'three' }];

  var argv = ['--one=1', '--two', '2', '--three=3'];
  var result = cliArgs(optionDefinitions, argv);
  a.strictEqual(result.one, '1');
  a.strictEqual(result.two, '2');
  a.strictEqual(result.three, '3');
});
runner.test('simple', function () {
  var commands = [ 'eat', 'sleep' ]

  var clc = commandLineCommands(commands, [ 'eat', '--food', 'peas' ])
  a.strictEqual(clc.command, 'eat')
  a.deepEqual(clc.argv, [ '--food', 'peas' ])

  clc = commandLineCommands(commands, [ 'sleep', '--hours', '2' ])
  a.strictEqual(clc.command, 'sleep')
  a.deepEqual(clc.argv, [ '--hours', '2' ])
})
runner.test('option=value notation: value contains "="', function () {
  var optionDefinitions = [{ name: 'url' }, { name: 'two' }, { name: 'three' }];

  var result = cliArgs(optionDefinitions, ['--url=my-url?q=123', '--two', '2', '--three=3']);
  a.strictEqual(result.url, 'my-url?q=123');
  a.strictEqual(result.two, '2');
  a.strictEqual(result.three, '3');

  result = cliArgs(optionDefinitions, ['--url=my-url?q=123=1']);
  a.strictEqual(result.url, 'my-url?q=123=1');

  result = cliArgs({ name: 'my-url' }, ['--my-url=my-url?q=123=1']);
  a.strictEqual(result['my-url'], 'my-url?q=123=1');
});
Example #6
0
runner.test('.isFunction(value)', function () {
  a.strictEqual(type.isFunction(true), false)
  a.strictEqual(type.isFunction({}), false)
  a.strictEqual(type.isFunction(0), false)
  a.strictEqual(type.isFunction('1'), false)
  a.strictEqual(type.isFunction(1.1), false)
  a.strictEqual(type.isFunction(NaN), false)
  a.strictEqual(type.isFunction(Infinity), false)
  a.strictEqual(type.isFunction(function () {}), true)
  a.strictEqual(type.isFunction(Date), true)
})
Example #7
0
		s.then(function () {
			assert.strictEqual(refs, 0);
			assert(s.isFree());
			assert.throws(() => {
				s.waitFor(timer(1));
			}, Error);
			done();
		});
Example #8
0
		}).catch(function (err) {
			//console.log(err);
			//console.log(sched.opts.console.out);
			assert.strictEqual(data.text, 'ab');
			timer(2).then(function () {
				assert.strictEqual(data.text, 'ab');
				done();
			});
		}).catch(done);
Example #9
0
	test('enum ui', function (done) {
		var tree = parse_tree(ui_text),
		    s = '';
		tree.enum(function (path, args) {
			s += ('        '.slice(0, path.length-1))+path.join('.')+' '+(args || '');
		});
		assert.strictEqual(to_str, tree.toString());
		done();
	});
Example #10
0
			.then(function () {
			assert.strictEqual(opts.gen, "init-before-global");
			return Promise.all([
				fs.readFile(src+'/job.js', 'utf8'),
				fs.readFile(dist+'/job.js', 'utf8')
			]).spread(function (s, d) {
				assert.strictEqual(d, s.toUpperCase());
				done();
			});
		}).catch(done);
runner.test('err-invalid-definition: throws when no definition.name specified', function () {
  var optionDefinitions = [{ something: 'one' }, { something: 'two' }];
  var argv = ['--one', '--two'];
  try {
    cliArgs(optionDefinitions, argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'NAME_MISSING');
  }
});
runner.test('no command specified', function () {
  var clc
  var commands = [ ]

  /* throws if null not specified */
  a.throws(function () {
    clc = commandLineCommands(commands, [ ])
  })

  /* null specified */
  commands = [ null ]
  clc = commandLineCommands(commands, [ ])
  a.strictEqual(clc.command, null)
  a.deepEqual(clc.argv, [ ])

  clc = commandLineCommands(commands, [ '--flag' ])
  a.strictEqual(clc.command, null)
  a.deepEqual(clc.argv, [ '--flag' ])
})
Example #13
0
runner.test('.isPlainObject(value)', function () {
  a.strictEqual(type.isPlainObject({ clive: 'hater' }), true, '{} is true')
  a.strictEqual(type.isPlainObject(new Date()), false, 'new Date() is false')
  a.strictEqual(type.isPlainObject([ 0, 1 ]), false, 'Array is false')
  a.strictEqual(type.isPlainObject(/test/), false, 'RegExp is false')
  a.strictEqual(type.isPlainObject(1), false, '1 is false')
  a.strictEqual(type.isPlainObject('one'), false, "'one' is false")
  a.strictEqual(type.isPlainObject(null), false, 'null is false')
})
Example #14
0
runner.test('.isNumber(value)', function () {
  a.strictEqual(type.isNumber(0), true)
  a.strictEqual(type.isNumber(1), true)
  a.strictEqual(type.isNumber(1.1), true)
  a.strictEqual(type.isNumber(0xff), true)
  a.strictEqual(type.isNumber(6.2e5), true)
  a.strictEqual(type.isNumber(NaN), false)
  a.strictEqual(type.isNumber(Infinity), false)
})
runner.test('err-invalid-definition: duplicate alias', function () {
  var optionDefinitions = [{ name: 'one', alias: 'a' }, { name: 'two', alias: 'a' }];
  var argv = ['--one', 'red'];

  try {
    cliArgs(optionDefinitions, argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'DUPLICATE_ALIAS');
  }
});
runner.test('err-invalid-definition: multiple defaultOption', function () {
  var optionDefinitions = [{ name: 'one', defaultOption: true }, { name: 'two', defaultOption: true }];
  var argv = ['--one', 'red'];

  try {
    cliArgs(optionDefinitions, argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'DUPLICATE_DEFAULT_OPTION');
  }
});
runner.test('err-invalid-definition: duplicate name', function () {
  var optionDefinitions = [{ name: 'colours' }, { name: 'colours' }];
  var argv = ['--colours', 'red'];

  try {
    cliArgs(optionDefinitions, argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'DUPLICATE_NAME');
  }
});
runner.test('err-invalid-definition: throws if dev set an alias of "-"', function () {
  var optionDefinitions = [{ name: 'colours', alias: '-' }];
  var argv = ['--colours', 'red'];

  try {
    cliArgs(optionDefinitions, argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'INVALID_ALIAS');
  }
});
runner.test('err-invalid-definition: multi-character alias', function () {
  var optionDefinitions = [{ name: 'one', alias: 'aa' }];
  var argv = ['--one', 'red'];

  try {
    cliArgs(optionDefinitions, argv);
    a.fail();
  } catch (err) {
    a.strictEqual(err.name, 'INVALID_ALIAS');
  }
});
Example #20
0
	test('check arguments passing', function (done) {
		var p = pluginsInject({}),
		    A = 'werewr',
		    B = 5.5;
		p.install('a', {'a':function (a,b) {
			assert.strictEqual(a, A);
			assert.strictEqual(b, B);
			return 5;
		} });
		assert.strictEqual(p.process(['a','a'], A, B), 5);
		done();
	});
Example #21
0
	test('check post compile', function (done) {
		var p = pluginsInject({}),
		    A = 'werewr',
		    B = 5.5;
		p.install('a', "var assert = require('core-assert');\n\
			module.exports = function (a,b) {\n\
			assert.strictEqual(a, 'werewr');\n\
			assert.strictEqual(b, 5.5);\n\
			return 5;\n\
		};\n");
		assert.strictEqual(p.process(['a'], A, B), 5);
		done();
	});
Example #22
0
File: test.js Project: 75lb/gfmt
runner.test('gmft()', function () {
  var fixture = require('./fixture/downloads')
  var result = gfmt(fixture)
  var expected =
'| date        | downloads |\n\
| ----------- | --------- |\n\
| 10 Jun 2015 | 100       |\n\
| 11 Jun 2015 | 120       |\n\
| 12 Jun 2015 | 150       |\n\
| 13 Jun 2015 | 120       |\n\
| 14 Jun 2015 | 110       |\n'
  a.strictEqual(result, expected)
})
Example #23
0
File: test.js Project: 75lb/gfmt
runner.test('ignoreEmptyColumns', function () {
  var data = [
      { "name": "Lloyd", "age": "" },
      { "name": "Roger", "age": " " },
      { "name": "Amir" },
      { "name": "Frank" },
      { "name": "Amy" }
  ]
  a.strictEqual(
    gfmt(data, { ignoreEmptyColumns: true }),
    '| name  |\n| ----- |\n| Lloyd |\n| Roger |\n| Amir  |\n| Frank |\n| Amy   |\n'
  )
})
Example #24
0
test('err-invalid-definition: throws if dev set a numeric alias', function () {
  var optionDefinitions = [
    { name: 'colours', alias: '1' }
  ]
  var argv = [ '--colours', 'red' ]

  try {
    cliArgs(optionDefinitions, argv)
    a.fail()
  } catch (err) {
    a.strictEqual(err.name, 'INVALID_ALIAS')
  }
})
Example #25
0
test('err-invalid-definition: value without option definition', function () {
  var optionDefinitions = [
    { name: 'one', type: Number }
  ]

  a.deepStrictEqual(
    cliArgs(optionDefinitions, [ '--one', '1' ]),
    { one: 1 }
  )

  try {
    cliArgs(optionDefinitions, [ '--one', '--two' ])
    a.fail()
  } catch (err) {
    a.strictEqual(err.name, 'UNKNOWN_OPTION')
  }

  try {
    cliArgs(optionDefinitions, [ '--one', '2', '--two', 'two' ])
    a.fail()
  } catch (err) {
    a.strictEqual(err.name, 'UNKNOWN_OPTION')
  }

  try {
    cliArgs(optionDefinitions, [ '-a', '2' ])
    a.fail()
  } catch (err) {
    a.strictEqual(err.name, 'UNKNOWN_OPTION')
  }

  try {
    cliArgs(optionDefinitions, [ '-sdf' ])
    a.fail()
  } catch (err) {
    a.strictEqual(err.name, 'UNKNOWN_OPTION', 'getOpts')
  }
})
Example #26
0
		job.then(function (data) {
			assert.strictEqual(data.text, 'abcd');
			done();
		}).catch(done);
Example #27
0
		}).catch(function (err) {
			assert.strictEqual(err, Promise.CANCEL_REASON);
			//console.log(sched.opts.console.out);
			done();
		}).catch(done);
Example #28
0
		}).catch(function (err) {
			//console.log(err);
			assert.strictEqual(err.code, 'ENOENT');
			//console.log(sched.opts.console.out);
			done();
		}).catch(done);
Example #29
0
		}).catch(function (err) {
			//console.log(err);
			//console.log(sched.opts.console.out);
			assert.strictEqual(data.text, 'abcd');
			done();
		}).catch(done);
runner.test('parse process.argv', function () {
  var commands = [ null ]
  var clc = commandLineCommands(commands)
  a.strictEqual(clc.command, null)
  a.deepEqual(clc.argv, [ '--files', 'test/test.js' ])
})