]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-self-compare.js
first commit
[pve-eslint.git] / eslint / tests / lib / rules / no-self-compare.js
1 /**
2 * @fileoverview Tests for no-self-compare rule.
3 * @author Ilya Volodin
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-self-compare"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("no-self-compare", rule, {
22 valid: [
23 "if (x === y) { }",
24 "if (1 === 2) { }",
25 "y=x*x",
26 "foo.bar.baz === foo.bar.qux"
27 ],
28 invalid: [
29 { code: "if (x === x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
30 { code: "if (x !== x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
31 { code: "if (x > x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
32 { code: "if ('x' > 'x') { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
33 { code: "do {} while (x === x)", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
34 { code: "x === x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
35 { code: "x !== x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
36 { code: "x == x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
37 { code: "x != x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
38 { code: "x > x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
39 { code: "x < x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
40 { code: "x >= x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
41 { code: "x <= x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] },
42 { code: "foo.bar().baz.qux >= foo.bar ().baz .qux", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }
43 ]
44 });