-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- split one big file to separate rules tests
- Loading branch information
Alexej Yaroshevich
committed
Nov 8, 2014
1 parent
3d9648b
commit 165ed20
Showing
5 changed files
with
347 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
describe('rules/validate-jsdoc', function () { | ||
var checker = global.checker({ | ||
additionalRules: ['lib/rules/validate-jsdoc.js'] | ||
}); | ||
|
||
describe('check-redudant-returns', function() { | ||
|
||
checker.rules({checkRedundantReturns: true}); | ||
checker.cases([ | ||
/* jshint ignore:start */ | ||
{ | ||
it: 'should report redundant @returns for function', | ||
errors: 3, | ||
code: function () { | ||
/** | ||
* @return {string} | ||
*/ | ||
function funcName() { | ||
// dummy | ||
} | ||
|
||
/** | ||
* @returns {String} | ||
*/ | ||
function funcName() { | ||
var x = function () { return 1; } | ||
} | ||
|
||
/** | ||
* @returns {String} | ||
*/ | ||
function funcName() { | ||
return; | ||
} | ||
} | ||
}, { | ||
it: 'should not report redundant @returns for function', | ||
code: function () { | ||
/** | ||
* @returns {String} | ||
*/ | ||
function funcName() { | ||
var x = function () { return 1; } | ||
if (true) { return x; } | ||
} | ||
} | ||
} | ||
/* jshint ignore:end */ | ||
]); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
describe('rules/validate-jsdoc', function () { | ||
var checker = global.checker({ | ||
additionalRules: ['lib/rules/validate-jsdoc.js'] | ||
}); | ||
|
||
describe('check-return-types', function () { | ||
|
||
checker.rules({checkReturnTypes: true}); | ||
checker.cases([ | ||
/* jshint ignore:start */ | ||
{ | ||
it: 'should neither throw nor report', | ||
code: function () { | ||
/** | ||
* @return {{a: number, b: string}} | ||
*/ | ||
function foo() { | ||
return {}; | ||
} | ||
} | ||
}, { | ||
it: 'should report invalid @returns type in function', | ||
errors: 1, | ||
code: function() { | ||
/** | ||
* @returns {Object} | ||
*/ | ||
function funcName() { | ||
return ""; | ||
} | ||
} | ||
}, { | ||
it: 'should not report valid resulting type with object type in method', | ||
code: function() { | ||
Cls.prototype = { | ||
/** | ||
* @return {{bar: number}} | ||
*/ | ||
run: function (xxx) { | ||
return {}; | ||
} | ||
}; | ||
} | ||
}, { | ||
it: 'should not report valid resulting type with object type in function', | ||
code: function() { | ||
/** | ||
* @return {Object} | ||
*/ | ||
function funcName() { | ||
return new Object(); | ||
} | ||
} | ||
}, { | ||
it: 'should not report comparition jsdoc type to any expression in function', | ||
code: function() { | ||
/** | ||
* @return {Object} | ||
*/ | ||
function funcName() { | ||
return Object.create(); | ||
} | ||
/** | ||
* @return {string} | ||
*/ | ||
function funcName() { | ||
return makeMyDay("zxc"); | ||
} | ||
} | ||
}, { | ||
it: 'should not report valid resulting array type for function', | ||
code: function() { | ||
/** | ||
* @return {Array} | ||
*/ | ||
function funcName() { | ||
return [1, 2]; | ||
} | ||
/** | ||
* @return {Array} | ||
*/ | ||
function funcName() { | ||
return new Array("zxc"); | ||
} | ||
} | ||
}, { | ||
it: 'should not report valid resulting regexp type for function', | ||
code: function() { | ||
/** | ||
* @return {RegExp} | ||
*/ | ||
function funcName() { | ||
return /[a-z]+/i; | ||
} | ||
/** | ||
* @return {RegExp} | ||
*/ | ||
function funcName() { | ||
return new RegExp("[a-z]+", "i"); | ||
} | ||
} | ||
}, { | ||
it: 'should not report valid resulting array.<String> and Object[] for function', | ||
code: function() { | ||
/** | ||
* @return {String[]} | ||
*/ | ||
function funcName() { | ||
return ["a", "b", "c"]; | ||
} | ||
/** | ||
* @return {Object[]} | ||
*/ | ||
function funcName() { | ||
return [{}, {}]; | ||
} | ||
/** | ||
* @return {Array.<Number>} | ||
*/ | ||
function funcName() { | ||
return [1, 2, 3]; | ||
} | ||
} | ||
}, { | ||
it: 'should not throw exception on `@returns {null|undefined}` directive. issue #7', | ||
code: function() { | ||
/** | ||
* @return {null} | ||
*/ | ||
function funcName() { | ||
return null; | ||
} | ||
/** | ||
* @return {undefined} | ||
*/ | ||
function funcName() { | ||
return undefined; | ||
} | ||
/** | ||
* @return {null|undefined} | ||
*/ | ||
function funcName(flag) { | ||
if (flag) { | ||
return null; | ||
} | ||
return undefined; | ||
} | ||
} | ||
}, { | ||
it: 'should report on `@returns {null|undefined}` vs (string|number|regexp). issue #7', | ||
errors: 3, | ||
code: function() { | ||
/** | ||
* @return {null|undefined} | ||
*/ | ||
function funcName(flag) { | ||
if (flag) { | ||
return /qwe/i; | ||
} else { | ||
return 2; | ||
} | ||
return ""; | ||
} | ||
} | ||
}, { | ||
it: 'should report on `@returns {null|undefined}` vs (array|object). issue #7', | ||
errors: 2, | ||
code: function() { | ||
/** | ||
* @return {null|undefined} | ||
*/ | ||
function funcName(flag) { | ||
if (flag) { | ||
return []; | ||
} | ||
return {q: 1}; | ||
} | ||
} | ||
}, { | ||
it: 'should not report on `@returns {string|null}` vs (null). issue #8', | ||
code: function() { | ||
/** | ||
* @return {string|null} | ||
*/ | ||
function funcName(flag) { | ||
if (!this.something) { | ||
return null; | ||
} | ||
} | ||
/** | ||
* @return {?string} | ||
*/ | ||
function funcName(flag) { | ||
if (!this.something) { | ||
return null; | ||
} | ||
} | ||
} | ||
}, { | ||
it: 'should not report on `@returns {?number}` vs (null|number). issue #8', | ||
code: function() { | ||
/** | ||
* @return {number|null} | ||
*/ | ||
function funcName(flag) { | ||
if (!this.something) { | ||
return null; | ||
} | ||
return 3; | ||
} | ||
/** | ||
* @return {?number} | ||
*/ | ||
function funcName(flag) { | ||
if (!this.something) { | ||
return null; | ||
} | ||
return 3; | ||
} | ||
} | ||
}, { | ||
it: 'should not report on `@returns {foo.Bar}`. issue #16', | ||
code: function() { | ||
module.exports = { | ||
/** | ||
* @return {foo.Bar} | ||
*/ | ||
foo: function () { | ||
return new foo.Bar(); | ||
}, | ||
/** | ||
* @return {foo.Bar.Baz} | ||
*/ | ||
bar: function () { | ||
return new foo.Bar.Baz(); | ||
}, | ||
/** | ||
* @return {foo.Bar.Baz|foo.Bar.Baz.Moo} | ||
*/ | ||
baz: function (t) { | ||
if (t) { | ||
return new foo.Bar.Baz.Moo(); | ||
} | ||
return new foo.Bar.Baz(); | ||
} | ||
}; | ||
} | ||
} | ||
/* jshint ignore:end */ | ||
]); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe('rules/validate-jsdoc', function () { | ||
var checker = global.checker({ | ||
additionalRules: ['lib/rules/validate-jsdoc.js'] | ||
}); | ||
|
||
describe('require-return-types', function() { | ||
|
||
checker.rules({requireReturnTypes: true}); | ||
checker.cases([ | ||
/* jshint ignore:start */ | ||
{ | ||
it: 'should report invalid @returns', | ||
errors: 1, | ||
code: function() { | ||
var x = 1; | ||
/** | ||
* @return | ||
*/ | ||
function funcName() { | ||
// dummy | ||
} | ||
} | ||
}, { | ||
it: 'should not report valid jsdoc with object type in method', | ||
code: function() { | ||
Cls.prototype = { | ||
/** | ||
* @return {{bar: number}} | ||
*/ | ||
run: function (xxx) { | ||
return {}; | ||
} | ||
}; | ||
} | ||
} | ||
/* jshint ignore:end */ | ||
]); | ||
|
||
}); | ||
}); |
Oops, something went wrong.