Permalink
Jump to Line
Branch:
master
Switch branches/tags
dollar-ignores
feature/new-rule-require-new-lines-in-array
gh-pages
issues/1242
issues/1271-related
master
mdevils/cst
Nothing to show
Nothing to show
Fetching contributors…
![]()
Cannot retrieve contributors at this time
| var Checker = require('../../../lib/checker'); | |
| var expect = require('chai').expect; | |
| describe('rules/disallow-padding-newlines-before-keywords', function() { | |
| var checker; | |
| beforeEach(function() { | |
| checker = new Checker(); | |
| checker.registerDefaultRules(); | |
| }); | |
| describe('array value', function() { | |
| beforeEach(function() { | |
| checker.configure({ | |
| disallowPaddingNewlinesBeforeKeywords: ['if', 'for', 'return', 'switch', 'case', 'break', 'throw'] | |
| }); | |
| }); | |
| // Test simple case (including return statement check) | |
| it('should report on matching return statement', function() { | |
| expect(checker.checkString( | |
| 'function x() { var a;\n\nreturn; }' | |
| )).to.have.one.validation.error.from('disallowPaddingNewlinesBeforeKeywords'); | |
| }); | |
| // Test cases for if statements | |
| it('should report on matching if statement', function() { | |
| expect(checker.checkString( | |
| 'function x() { var a = true;\n\nif (a) { a = !a; }; }' | |
| )).to.have.one.validation.error.from('disallowPaddingNewlinesBeforeKeywords'); | |
| }); | |
| // Test case for 'for' statement | |
| it('should report on matching for statement', function() { | |
| expect(checker.checkString( | |
| 'function x() { var a = true;\n\nfor (var i = 0; i < 10; i++) { a = !a; }; }' | |
| )).to.have.one.validation.error.from('disallowPaddingNewlinesBeforeKeywords'); | |
| }); | |
| // Test case for 'switch', 'case' and 'break' statement | |
| it('should report on matching switch, case and break statements', function() { | |
| expect(checker.checkString( | |
| 'function x() { var y = true;\n\nswitch ("Oranges") { case "Oranges": ' + | |
| 'y = !y;\n\nbreak;\n\ncase "Apples": y = !y;\n\nbreak; default: y = !y; } }' | |
| )).to.have.error.count.equal(4); | |
| }); | |
| // Test case for 'throw' statement | |
| it('should report on matching throw statement', function() { | |
| expect(checker.checkString( | |
| 'function x() {try { var a;\n\nthrow 0; } ' + | |
| 'catch (e) { var b = 0;\n\nthrow e; } }' | |
| )).to.have.error.count.equal(2); | |
| }); | |
| it('should report on multiple matching keywords', function() { | |
| expect(checker.checkString( | |
| 'function x(a) { var b = 0;\n\nif (!a) { return false; };\n\n' + | |
| 'for (var i = 0; i < b; i++) { if (!a[i]) return false; }\n\nreturn true; }' | |
| )).to.have.error.count.equal(3); | |
| }); | |
| }); | |
| describe('true value', function() { | |
| beforeEach(function() { | |
| checker.configure({ | |
| disallowPaddingNewlinesBeforeKeywords: true | |
| }); | |
| }); | |
| it('should report on matching return statement', function() { | |
| expect(checker.checkString( | |
| 'function x() { var a;\n\nreturn; }' | |
| )).to.have.one.validation.error.from('disallowPaddingNewlinesBeforeKeywords'); | |
| }); | |
| }); | |
| }); |