Skip to content

Commit

Permalink
[[CHORE]] Improve test coverage for logical NOT
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Aug 20, 2019
1 parent d015657 commit d72ce61
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/jshint.js
Expand Up @@ -2632,12 +2632,10 @@ var JSHINT = (function() {
this.right = expression(context, 150);

if (!this.right) { // '!' followed by nothing? Give up.
/* istanbul ignore next */
quit("E041", this);
}

if (bang[this.right.id] === true) {
/* istanbul ignore next */
warning("W018", this, "!");
}
return this;
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -280,6 +280,53 @@ exports.relations = function (test) {
run.test(code, {esnext: true});
run.test(code, {moz: true});

TestRun(test, "No suitable expression following logical NOT.")
.addError(1, 7, "Expected an identifier and instead saw ';'.")
.addError(1, 6, "Unrecoverable syntax error. (100% scanned).")
.test("void !;");

TestRun(test, "Logical NOT in combination with 'infix' operators.")
.addError(3, 6, "Confusing use of '!'.")
.addError(4, 6, "Confusing use of '!'.")
.addError(5, 6, "Confusing use of '!'.")
.addError(6, 6, "Confusing use of '!'.")
.addError(7, 6, "Confusing use of '!'.")
.addError(8, 6, "Confusing use of '!'.")
.addError(9, 6, "Confusing use of '!'.")
.addError(10, 6, "Confusing use of '!'.")
.addError(11, 6, "Confusing use of '!'.")
.addError(12, 6, "Confusing use of '!'.")
.addError(13, 6, "Confusing use of '!'.")
.addError(14, 6, "Confusing use of '!'.")
.addError(15, 6, "Confusing use of '!'.")
.test([
"void !'-';",
"void !'+';",
"void !(0 < 0);",
"void !(0 <= 0);",
"void !(0 == 0);",
"void !(0 === 0);",
"void !(0 !== 0);",
"void !(0 != 0);",
"void !(0 > 0);",
"void !(0 >= 0);",
"void !(0 + 0);",
"void !(0 - 0);",
"void !(0 * 0);",
"void !(0 / 0);",
"void !(0 % 0);",
]);

TestRun(test, "Logical NOT in combination with other unary operators.")
.addError(3, 6, "Confusing use of '!'.")
.addError(4, 6, "Confusing use of '!'.")
.test([
"void !'-';",
"void !'+';",
"void !+0;",
"void !-0;"
]);

test.done();
};

Expand Down

0 comments on commit d72ce61

Please sign in to comment.