Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Clone in Desktop Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

74 lines (55 sloc) 2.89 KB
var Checker = require('../../../lib/checker');
var expect = require('chai').expect;
describe('rules/require-space-before-comma', function() {
var checker;
beforeEach(function() {
checker = new Checker();
checker.registerDefaultRules();
checker.configure({ requireSpaceBeforeComma: true });
});
it('should report error when no space is given', function() {
expect(checker.checkString('var a,b;')).to.have.one.validation.error.from('requireSpaceBeforeComma');
});
it('should report error when space is given after but not before comma', function() {
expect(checker.checkString('var a, b;')).to.have.one.validation.error.from('requireSpaceBeforeComma');
});
it('should allow space before comma in var declaration', function() {
expect(checker.checkString('var a ,b;')).to.have.no.errors();
});
it('should allow space before and after comma in var declaration', function() {
expect(checker.checkString('var a , b;')).to.have.no.errors();
});
it('should allow new line before comma in var declaration', function() {
expect(checker.checkString('var a\n,b\n,c;')).to.have.no.errors();
});
it('should report errors when no space is given in arrays', function() {
expect(checker.checkString('var a = [1,2,3,4];')).to.have.error.count.equal(3);
});
it('should report errors when space is given after but not before commas in arrays', function() {
expect(checker.checkString('var a = [1, 2, 3, 4];')).to.have.error.count.equal(3);
});
it('should allow space before comma in arrays', function() {
expect(checker.checkString('var a = [1 ,2 ,3 ,4];')).to.have.no.errors();
});
it('should allow space before and after comma in arrays', function() {
expect(checker.checkString('var a = [1 , 2 , 3 , 4];')).to.have.no.errors();
});
it('should allow new line before comma in arrays', function() {
expect(checker.checkString('var a = [1\n,2\n,3];')).to.have.no.errors();
});
it('should report errors when no space is given in objects', function() {
expect(checker.checkString('var a = {x:1,y:2,z:3};')).to.have.error.count.equal(2);
});
it('should report errors when space is given after but not before commas in objects', function() {
expect(checker.checkString('var a = {x:1, y:2, z:3};')).to.have.error.count.equal(2);
});
it('should allow space before comma in objects', function() {
expect(checker.checkString('var a = {x: 1 ,y: 2 ,z: 3};')).to.have.no.errors();
});
it('should allow space before and after comma in objects', function() {
expect(checker.checkString('var a = {x: 1 , y: 2 , z: 3};')).to.have.no.errors();
});
it('should allow new line before comma in objects', function() {
expect(checker.checkString('var a = {x: 1\n,y: 2\n,z: 3};')).to.have.no.errors();
});
});
Jump to Line
Something went wrong with that request. Please try again.