|
| 1 | +const RuleTester = require('eslint').RuleTester; |
| 2 | +const rule = require('../use-double-negation-instead-of-boolean'); |
| 3 | +const message = require('../CONST').MESSAGE.USE_DOUBLE_NEGATION_INSTEAD_OF_BOOLEAN; |
| 4 | + |
| 5 | +const ruleTester = new RuleTester({ |
| 6 | + parserOptions: { |
| 7 | + ecmaVersion: 6, |
| 8 | + sourceType: 'module', |
| 9 | + }, |
| 10 | +}); |
| 11 | + |
| 12 | +ruleTester.run('use-double-negation-instead-of-Boolean()', rule, { |
| 13 | + valid: [ |
| 14 | + { |
| 15 | + code: '!!test', |
| 16 | + }, |
| 17 | + { |
| 18 | + code: '!!(test1 || test2)', |
| 19 | + }, |
| 20 | + { |
| 21 | + code: '!!(test1 && test2)', |
| 22 | + }, |
| 23 | + { |
| 24 | + code: '!!(test1 && (test2 || test3))', |
| 25 | + }, |
| 26 | + { |
| 27 | + code: '!!(test1 || test2 && test3)', |
| 28 | + }, |
| 29 | + { |
| 30 | + code: '!!test ? "" : "example"', |
| 31 | + }, |
| 32 | + ], |
| 33 | + invalid: [ |
| 34 | + { |
| 35 | + code: 'Boolean(test)', |
| 36 | + output: '!!test', |
| 37 | + errors: [{ |
| 38 | + message, |
| 39 | + }], |
| 40 | + }, |
| 41 | + { |
| 42 | + code: 'Boolean(test1 || test2)', |
| 43 | + output: '!!(test1 || test2)', |
| 44 | + errors: [{ |
| 45 | + message, |
| 46 | + }], |
| 47 | + }, |
| 48 | + { |
| 49 | + code: 'Boolean(test1 && test2)', |
| 50 | + output: '!!(test1 && test2)', |
| 51 | + errors: [{ |
| 52 | + message, |
| 53 | + }], |
| 54 | + }, |
| 55 | + { |
| 56 | + code: 'Boolean(test1 && (test2 || test3))', |
| 57 | + output: '!!(test1 && (test2 || test3))', |
| 58 | + errors: [{ |
| 59 | + message, |
| 60 | + }], |
| 61 | + }, |
| 62 | + { |
| 63 | + code: 'Boolean(test1 || test2 && test3)', |
| 64 | + output: '!!(test1 || test2 && test3)', |
| 65 | + errors: [{ |
| 66 | + message, |
| 67 | + }], |
| 68 | + }, |
| 69 | + { |
| 70 | + code: 'Boolean(test) ? "" : "example"', |
| 71 | + output: '!!test ? "" : "example"', |
| 72 | + errors: [{ |
| 73 | + message, |
| 74 | + }], |
| 75 | + }, |
| 76 | + ], |
| 77 | +}); |
0 commit comments