|
| 1 | +var Checker = require('../../../lib/checker'); |
| 2 | +var expect = require('chai').expect; |
| 3 | +var reportAndFix = require('../../lib/assertHelpers').reportAndFix; |
| 4 | + |
| 5 | +describe('rules/require-spaces-in-generator', function() { |
| 6 | + var checker; |
| 7 | + beforeEach(function() { |
| 8 | + checker = new Checker(); |
| 9 | + checker.registerDefaultRules(); |
| 10 | + }); |
| 11 | + |
| 12 | + describe('both true', function() { |
| 13 | + var rules = { |
| 14 | + requireSpacesInGenerator: { beforeStar: true, afterStar: true }, |
| 15 | + esnext: true |
| 16 | + }; |
| 17 | + |
| 18 | + beforeEach(function() { |
| 19 | + checker.configure(rules); |
| 20 | + }); |
| 21 | + |
| 22 | + reportAndFix({ |
| 23 | + name: 'should report missing space before and after the star with function declaration', |
| 24 | + rules: rules, |
| 25 | + errors: 2, |
| 26 | + input: 'function*asdf(){}', |
| 27 | + output: 'function * asdf(){}' |
| 28 | + }); |
| 29 | + |
| 30 | + reportAndFix({ |
| 31 | + name: 'should report missing space after the star with function declaration', |
| 32 | + rules: rules, |
| 33 | + errors: 1, |
| 34 | + input: 'function *asdf(){}', |
| 35 | + output: 'function * asdf(){}' |
| 36 | + }); |
| 37 | + |
| 38 | + reportAndFix({ |
| 39 | + name: 'should report missing space before the star with function declaration', |
| 40 | + rules: rules, |
| 41 | + errors: 1, |
| 42 | + input: 'function* asdf(){}', |
| 43 | + output: 'function * asdf(){}' |
| 44 | + }); |
| 45 | + |
| 46 | + reportAndFix({ |
| 47 | + name: 'should report missing space before and after the star', |
| 48 | + rules: rules, |
| 49 | + errors: 2, |
| 50 | + input: 'var x = function*(){}', |
| 51 | + output: 'var x = function * (){}' |
| 52 | + }); |
| 53 | + |
| 54 | + reportAndFix({ |
| 55 | + name: 'should report missing space after the star', |
| 56 | + rules: rules, |
| 57 | + errors: 1, |
| 58 | + input: 'var x = function *(){}', |
| 59 | + output: 'var x = function * (){}' |
| 60 | + }); |
| 61 | + |
| 62 | + reportAndFix({ |
| 63 | + name: 'should report missing space before the star', |
| 64 | + rules: rules, |
| 65 | + errors: 1, |
| 66 | + input: 'var x = function* (){}', |
| 67 | + output: 'var x = function * (){}' |
| 68 | + }); |
| 69 | + |
| 70 | + reportAndFix({ |
| 71 | + name: 'should report missing space before and after the star with named function', |
| 72 | + rules: rules, |
| 73 | + errors: 2, |
| 74 | + input: 'var x = function*asdf(){}', |
| 75 | + output: 'var x = function * asdf(){}' |
| 76 | + }); |
| 77 | + |
| 78 | + reportAndFix({ |
| 79 | + name: 'should report missing space after the star with named function', |
| 80 | + rules: rules, |
| 81 | + errors: 1, |
| 82 | + input: 'var x = function *asdf(){}', |
| 83 | + output: 'var x = function * asdf(){}' |
| 84 | + }); |
| 85 | + |
| 86 | + reportAndFix({ |
| 87 | + name: 'should report missing space before the star with named function', |
| 88 | + rules: rules, |
| 89 | + errors: 1, |
| 90 | + input: 'var x = function* asdf(){}', |
| 91 | + output: 'var x = function * asdf(){}' |
| 92 | + }); |
| 93 | + |
| 94 | + it('should not report missing spaces error', function() { |
| 95 | + expect(checker.checkString('var x = function * (){}')).to.have.no.errors(); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should not report missing spaces error with named function', function() { |
| 99 | + expect(checker.checkString('var x = function * asdf(){}')).to.have.no.errors(); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should not report missing spaces error with function delcaration', function() { |
| 103 | + expect(checker.checkString('function * asdf(){}')).to.have.no.errors(); |
| 104 | + }); |
| 105 | + |
| 106 | + it('should not report missing spaces error with async function', function() { |
| 107 | + expect(checker.checkString('var x = async function * (){}')).to.have.no.errors(); |
| 108 | + }); |
| 109 | + |
| 110 | + it('should skip async functions with named function', function() { |
| 111 | + expect(checker.checkString('var x = async function * asdf(){}')).to.have.no.errors(); |
| 112 | + }); |
| 113 | + |
| 114 | + it('should report missing space after star for async function', function() { |
| 115 | + var testExp = checker.checkString('var x = async function *(){}'); |
| 116 | + var reqTest = 'requireSpacesInGenerator'; |
| 117 | + expect(testExp).to.have.one.validation.error.from(reqTest); |
| 118 | + }); |
| 119 | + |
| 120 | + it('should report missing space after star for named async function', function() { |
| 121 | + var testExp = checker.checkString('var x = async function *asdf(){}'); |
| 122 | + var reqTest = 'requireSpacesInGenerator'; |
| 123 | + expect(testExp).to.have.one.validation.error.from(reqTest); |
| 124 | + }); |
| 125 | + }); |
| 126 | +}); |
0 commit comments