Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Apr 12, 2015
1 parent 38bbab1 commit e04a4a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/utils.js
Expand Up @@ -274,7 +274,7 @@ exports.categorizeCloseParen = function(token, file) {

// Closing parentheses for other statements must be followed by a statement
var nextNode = file.getNodeByRange(nextToken.range[0]);
while (nextNode && nextNode.range[0] >= token.range[1]) {
while (nextNode.range[0] >= token.range[1]) {
if (ANY_STATEMENT_TYPE_RE.test(nextNode.type)) {
return 'Statement';
}
Expand Down
32 changes: 27 additions & 5 deletions test/specs/rules/require-spaces-inside-parenthesized-expression.js
Expand Up @@ -25,22 +25,26 @@ describe('rules/require-spaces-inside-parenthesized-expression', function() {
assert(checker.checkString('if ( 1 + 2)\n 3').isEmpty());
assert(checker.checkString('function my( a, b) { }').isEmpty());
assert(checker.checkString('my( a, b)').isEmpty());
assert(checker.checkString('do {} while (false)').isEmpty());
});

it('should report required space in both cases', function() {
assert(checker.checkString('(1 + 2) * 3').getErrorCount() === 2);
assert(checker.checkString('if (1 + 2)\n 3').isEmpty());
assert(checker.checkString('function my(a, b) { }').isEmpty());
assert(checker.checkString('my(a, b)').isEmpty());
assert(checker.checkString('function ret0() { return(0); }').getErrorCount() === 2);
assert(checker.checkString('id = function(v) { return(v); }').getErrorCount() === 2);
assert(checker.checkString('(my(a), 1)').getErrorCount() === 2);
assert(checker.checkString('do {} while (false)').isEmpty());
assert(checker.checkString('switch (a) { case(b): c }').getErrorCount() === 2);
assert(checker.checkString('(a)\n{ fn(); }').getErrorCount() === 2);
});

it('should not report with spaces', function() {
assert(checker.checkString('( 1 + 2 ) * 3').isEmpty());
assert(checker.checkString('function ret0() { return( 0 ); }').isEmpty());
assert(checker.checkString('id = function(v) { return( v ); }').isEmpty());
assert(checker.checkString('( my(a), 1 )').isEmpty());
assert(checker.checkString('switch (a) { case( b ): c }').isEmpty());
assert(checker.checkString('( a )\n{ fn(); }').isEmpty());
});

it('should not report with closing parentheses on new line', function() {
Expand All @@ -62,13 +66,13 @@ describe('rules/require-spaces-inside-parenthesized-expression', function() {
it('should report nested parentheses', function() {
assert(checker.checkString('((1, 2))').getErrorCount() === 4);
assert(checker.checkString('if ((1 + 2))\n 3').getErrorCount() === 2);
assert(checker.checkString('(my)((a))').getErrorCount() === 4);
assert(checker.checkString('(my)((a),(b))').getErrorCount() === 6);
});

it('should not report with nested spaces', function() {
assert(checker.checkString('( ( 1, 2 ) )').isEmpty());
assert(checker.checkString('if (( 1 + 2 ))\n 3').isEmpty());
assert(checker.checkString('( my )(( a ))').isEmpty());
assert(checker.checkString('( my )(( a ),( b ))').isEmpty());
});
});

Expand Down Expand Up @@ -102,4 +106,22 @@ describe('rules/require-spaces-inside-parenthesized-expression', function() {
assert(checker.checkString('( function() {}, {})').isEmpty());
});
});

describe('invalid configuration', function() {
it('should not accept objects without at least one valid key', function() {
assert.throws(function() {
checker.configure({ requireSpacesInsideParenthesizedExpression: {} });
},
assert.AssertionError
);
});

it('should not accept non-boolean non-objects', function() {
assert.throws(function() {
checker.configure({ requireSpacesInsideParenthesizedExpression: 'true' });
},
assert.AssertionError
);
});
});
});

0 comments on commit e04a4a9

Please sign in to comment.