Improve code quality and write tests

This commit is contained in:
Shivam Mathur
2019-09-20 08:11:20 +05:30
parent db44db4b97
commit 43178a7254
3597 changed files with 255478 additions and 785554 deletions

168
node_modules/argv/test/test-core.js generated vendored Normal file
View File

@ -0,0 +1,168 @@
munit( 'Root.Options', function( assert ) {
argv.clear().option([
{
name: 'bool',
short: 'b',
type: 'boolean'
},
{
name: 'path',
short: 'p',
type: 'path'
},
{
name: 'int',
short: 'i',
type: 'int'
},
{
name: 'float',
short: 'f',
type: 'float'
},
{
name: 'csv',
short: 'c',
type: 'csv'
},
{
name: 'list',
short: 'l',
type: 'list'
},
{
name: 'listpath',
short: 't',
type: 'list,path'
},
{
name: 'csvcombo',
type: 'csv,int'
},
{
name: 'bool2',
short: 'x',
type: 'boolean'
},
{
name: 'bool3',
short: 'y',
type: 'boolean'
},
{
name: 'bool4',
short: 'z',
type: 'boolean'
}
]);
// Tests
[
{
name: 'basic',
args: '-b false --path=/a/b/c -i 123.456 --float=123.456 -c a,b,c -l a -l b -l c',
options: {
bool: false,
path: '/a/b/c',
'int': 123,
'float': 123.456,
csv: [ 'a', 'b', 'c' ],
list: [ 'a', 'b', 'c' ]
}
},
{
name: 'path-relative',
args: '-p a/b/c',
options: {
path: process.cwd() + '/a/b/c'
}
},
{
name: 'path-home',
args: '-p ~/a/b/c',
options: {
path: process.env.HOME + '/a/b/c'
}
},
{
name: 'listpath',
args: '-t ~/a/b/c -t /a/b/c -t a/b/c',
options: {
listpath: [
process.env.HOME + '/a/b/c',
'/a/b/c',
process.cwd() + '/a/b/c'
]
}
},
{
name: 'csvcombo',
args: '--csvcombo=123,456.99,0.00001',
options: {
csvcombo: [ 123, 456, 0 ]
}
},
{
name: 'targets',
args: 'targ1 -p /a/b/c targ2 targ3 --bool targ4',
targets: [ 'targ1', 'targ2', 'targ3', 'targ4' ],
options: {
path: '/a/b/c',
bool: true
}
},
{
name: 'bool-target-test',
args: 'targ1 -b targ2',
targets: [ 'targ1', 'targ2' ],
options: {
bool: true
}
},
{
name: 'bool-multi-option',
args: 'targ1 -bxy targ2 -z targ3',
targets: [ 'targ1', 'targ2', 'targ3' ],
options: {
bool: true,
bool2: true,
bool3: true,
bool4: true
}
}
].forEach(function( object ) {
var args = argv.run( argv.isArray( object.args ) ? object.args : object.args.split( ' ' ) );
// Option parsing
assert.deepEqual( object.name + '::options', args.options, object.options );
// Target comparison
if ( object.targets ) {
assert.deepEqual( object.name + '::targets', args.targets, object.targets );
}
else {
assert.ok( object.name + '::targets', ! args.targets.length );
}
});
});

65
node_modules/argv/test/test-custom.js generated vendored Normal file
View File

@ -0,0 +1,65 @@
munit( 'Custom', function( assert ) {
// Add custom types
argv.type({
'special-int': function(){
return 777;
},
'special-float': function(){
return 777.777;
}
});
// Setup options
argv.clear().option([
{
name: 'foo',
type: 'special-int'
},
{
name: 'bar',
type: 'special-float'
}
]);
// Tests
[
{
name: 'types',
args: '--foo=123 --bar=456',
options: {
foo: 777,
bar: 777.777
}
}
].forEach(function( object ) {
var args = argv.run( argv.isArray( object.args ) ? object.args : object.args.split( ' ' ) );
// Option parsing
assert.deepEqual( object.name + '::options', args.options, object.options );
// Target comparison
if ( object.targets ) {
assert.deepEqual( object.name + '::targets', args.targets, object.targets );
}
else {
assert.ok( object.name + '::targets', ! args.targets.length );
}
});
// Deletion checks
assert.ok( 'Int Exists', argv.types[ 'special-int' ] );
assert.ok( 'Float Exists', argv.types[ 'special-float' ] );
argv.type( 'special-int', null );
argv.type( 'special-float', null );
assert.ok( 'Delete Int', ! argv.types[ 'special-int' ] );
assert.ok( 'Delete Float', ! argv.types[ 'special-float' ] );
});

118
node_modules/argv/test/test-mods.js generated vendored Normal file
View File

@ -0,0 +1,118 @@
munit( 'Modules', function( assert ) {
argv.clear().option([
{
name: 'bool',
short: 'a',
type: 'boolean'
},
{
name: 'bool2',
short: 'b',
type: 'boolean'
},
{
name: 'bool3',
short: 'c',
type: 'boolean'
},
{
name: 'path',
short: 'p',
type: 'path'
},
{
mod: 'mod',
options: [
{
name: 'bool',
short: 'a',
type: 'boolean'
},
{
name: 'bool2',
short: 'b',
type: 'boolean'
},
{
name: 'bool3',
short: 'c',
type: 'boolean'
},
{
name: 'path',
short: 'p',
type: 'path'
}
]
}
]);
[
{
name: 'root',
args: 'targ1 -p /a/b/c targ2 -abc targ3',
targets: [ 'targ1', 'targ2', 'targ3' ],
options: {
path: '/a/b/c',
bool: true,
bool2: true,
bool3: true
}
},
{
name: 'mod',
args: 'mod targ1 -ab',
mod: 'mod',
targets: [ 'targ1' ],
options: {
bool: true,
bool2: true
}
},
{
name: 'mod-path',
args: 'mod targ1 -p /a/b/c',
mod: 'mod',
targets: [ 'targ1' ],
options: {
path: '/a/b/c'
}
}
].forEach(function( object ) {
var args = argv.run( argv.isArray( object.args ) ? object.args : object.args.split( ' ' ) );
// Option parsing
assert.deepEqual( object.name + '::options', args.options, object.options );
// Mod comparison
if ( object.mod ) {
assert.equal( object.name + '::mod', args.mod, object.mod );
}
else {
assert.ok( object.name + '::mod', ! args.mod );
}
// Target comparison
if ( object.targets ) {
assert.deepEqual( object.name + '::targets', args.targets, object.targets );
}
else {
assert.ok( object.name + '::targets', ! args.targets.length );
}
});
});

12
node_modules/argv/test/test-version.js generated vendored Normal file
View File

@ -0,0 +1,12 @@
munit( 'Root.version', { priority: munit.PRIORITY_LOW }, function( assert ) {
argv.clear();
if ( argv.options.version ) {
delete argv.options.version;
}
assert.empty( 'Version Start', argv.options.version );
argv.version( "1.2.4" );
assert.exists( 'Version Option', argv.options.version );
argv.clear();
assert.exists( 'Version Option after Clear', argv.options.version );
});