@@ -7,67 +7,179 @@ describe('rules/require-space-after-comma', function() {
77 beforeEach ( function ( ) {
88 checker = new Checker ( ) ;
99 checker . registerDefaultRules ( ) ;
10- checker . configure ( { requireSpaceAfterComma : true } ) ;
1110 } ) ;
1211
13- it ( 'should report error when no space is given' , function ( ) {
14- expect ( checker . checkString ( 'var a,b;' ) ) . to . have . one . validation . error . from ( 'requireSpaceAfterComma' ) ;
15- } ) ;
12+ describe ( 'option value true' , function ( ) {
1613
17- it ( 'should report error when space is given before but not after comma' , function ( ) {
18- expect ( checker . checkString ( 'var a ,b;' ) ) . to . have . one . validation . error . from ( ' requireSpaceAfterComma' ) ;
19- } ) ;
14+ beforeEach ( function ( ) {
15+ checker . configure ( { requireSpaceAfterComma : true } ) ;
16+ } ) ;
2017
21- it ( 'should allow space after comma in var declaration ' , function ( ) {
22- expect ( checker . checkString ( 'var a, b;' ) ) . to . have . no . errors ( ) ;
23- } ) ;
18+ it ( 'should report error when no space is given ' , function ( ) {
19+ expect ( checker . checkString ( 'var a,b;' ) ) . to . have . one . validation . error . from ( 'requireSpaceAfterComma' ) ;
20+ } ) ;
2421
25- it ( 'should allow space after and before comma in var declaration ' , function ( ) {
26- expect ( checker . checkString ( 'var a , b;' ) ) . to . have . no . errors ( ) ;
27- } ) ;
22+ it ( 'should report error when space is given before but not after comma ' , function ( ) {
23+ expect ( checker . checkString ( 'var a ,b;' ) ) . to . have . one . validation . error . from ( 'requireSpaceAfterComma' ) ;
24+ } ) ;
2825
29- it ( 'should allow new line after comma in var declaration' , function ( ) {
30- expect ( checker . checkString ( 'var a,\nb,\nc ;' ) ) . to . have . no . errors ( ) ;
31- } ) ;
26+ it ( 'should allow space after comma in var declaration' , function ( ) {
27+ expect ( checker . checkString ( 'var a, b ;' ) ) . to . have . no . errors ( ) ;
28+ } ) ;
3229
33- it ( 'should report errors when no space is given in arrays ' , function ( ) {
34- expect ( checker . checkString ( 'var a = [1,2,3,4] ;' ) ) . to . have . error . count . equal ( 3 ) ;
35- } ) ;
30+ it ( 'should allow space after and before comma in var declaration ' , function ( ) {
31+ expect ( checker . checkString ( 'var a , b ;' ) ) . to . have . no . errors ( ) ;
32+ } ) ;
3633
37- it ( 'should report errors when space is given before but not after commas in arrays ' , function ( ) {
38- expect ( checker . checkString ( 'var a = [1 ,2 ,3 ,4] ;' ) ) . to . have . error . count . equal ( 3 ) ;
39- } ) ;
34+ it ( 'should allow new line after comma in var declaration ' , function ( ) {
35+ expect ( checker . checkString ( 'var a,\nb,\nc ;' ) ) . to . have . no . errors ( ) ;
36+ } ) ;
4037
41- it ( 'should allow space after comma in arrays' , function ( ) {
42- expect ( checker . checkString ( 'var a = [1, 2, 3, 4];' ) ) . to . have . no . errors ( ) ;
43- } ) ;
38+ it ( 'should report errors when no space is given in arrays' , function ( ) {
39+ expect ( checker . checkString ( 'var a = [1,2,3, 4];' ) ) . to . have . error . count . equal ( 3 ) ;
40+ } ) ;
4441
45- it ( 'should allow space after and before comma in arrays' , function ( ) {
46- expect ( checker . checkString ( 'var a = [1 , 2 , 3 , 4];' ) ) . to . have . no . errors ( ) ;
47- } ) ;
42+ it ( 'should report errors when space is given before but not after commas in arrays' , function ( ) {
43+ expect ( checker . checkString ( 'var a = [1 ,2 ,3 ,4];' ) ) . to . have . error . count . equal ( 3 ) ;
44+ } ) ;
4845
49- it ( 'should allow new line after comma in arrays' , function ( ) {
50- expect ( checker . checkString ( 'var a = [1,\n2,\n3 ];' ) ) . to . have . no . errors ( ) ;
51- } ) ;
46+ it ( 'should allow space after comma in arrays' , function ( ) {
47+ expect ( checker . checkString ( 'var a = [1, 2, 3, 4 ];' ) ) . to . have . no . errors ( ) ;
48+ } ) ;
5249
53- it ( 'should report errors when no space is given in objects ' , function ( ) {
54- expect ( checker . checkString ( 'var a = {x:1,y:2,z:3} ;' ) ) . to . have . error . count . equal ( 2 ) ;
55- } ) ;
50+ it ( 'should allow space after and before comma in arrays ' , function ( ) {
51+ expect ( checker . checkString ( 'var a = [1 , 2 , 3 , 4] ;' ) ) . to . have . no . errors ( ) ;
52+ } ) ;
5653
57- it ( 'should report errors when space is given before but not after commas in objects ' , function ( ) {
58- expect ( checker . checkString ( 'var a = {x:1 ,y:2 ,z:3} ;' ) ) . to . have . error . count . equal ( 2 ) ;
59- } ) ;
54+ it ( 'should report error when no space is given after trailing comma in array ' , function ( ) {
55+ expect ( checker . checkString ( 'var a = [1, 2, 3, 4,] ;' ) ) . to . have . error . count . equal ( 1 ) ;
56+ } ) ;
6057
61- it ( 'should allow space after comma in objects' , function ( ) {
62- expect ( checker . checkString ( 'var a = {x: 1, y: 2, z: 3};' ) ) . to . have . no . errors ( ) ;
63- } ) ;
58+ it ( 'should allow new line after comma in arrays' , function ( ) {
59+ expect ( checker . checkString ( 'var a = [1,\n2,\n3];' ) ) . to . have . no . errors ( ) ;
60+ } ) ;
61+
62+ it ( 'should report errors when no space is given in objects' , function ( ) {
63+ expect ( checker . checkString ( 'var a = {x:1,y:2,z:3};' ) ) . to . have . error . count . equal ( 2 ) ;
64+ } ) ;
65+
66+ it ( 'should report error when no space is given after trailing comma in object' , function ( ) {
67+ expect ( checker . checkString ( 'var a = {x:1, y:2, z:3,};' ) ) . to . have . error . count . equal ( 1 ) ;
68+ } ) ;
69+
70+ it ( 'should report errors when space is given before but not after commas in objects' , function ( ) {
71+ expect ( checker . checkString ( 'var a = {x:1 ,y:2 ,z:3};' ) ) . to . have . error . count . equal ( 2 ) ;
72+ } ) ;
73+
74+ it ( 'should allow space after comma in objects' , function ( ) {
75+ expect ( checker . checkString ( 'var a = {x: 1, y: 2, z: 3};' ) ) . to . have . no . errors ( ) ;
76+ } ) ;
77+
78+ it ( 'should allow space after and before comma in objects' , function ( ) {
79+ expect ( checker . checkString ( 'var a = {x: 1 , y: 2 , z: 3};' ) ) . to . have . no . errors ( ) ;
80+ } ) ;
81+
82+ it ( 'should allow new line after comma in objects' , function ( ) {
83+ expect ( checker . checkString ( 'var a = {x: 1,\ny: 2,\nz: 3};' ) ) . to . have . no . errors ( ) ;
84+ } ) ;
85+
86+ it ( 'should report errors when no space is given after trailing comma in object in array' , function ( ) {
87+ expect ( checker . checkString ( 'var a = [{a:1, b:2,}, {c:3, d:4,},];' ) ) . to . have . error . count . equal ( 3 ) ;
88+ } ) ;
6489
65- it ( 'should allow space after and before comma in objects' , function ( ) {
66- expect ( checker . checkString ( 'var a = {x: 1 , y: 2 , z: 3};' ) ) . to . have . no . errors ( ) ;
6790 } ) ;
6891
69- it ( 'should allow new line after comma in objects' , function ( ) {
70- expect ( checker . checkString ( 'var a = {x: 1,\ny: 2,\nz: 3};' ) ) . to . have . no . errors ( ) ;
92+ describe ( 'option value "exceptTrailingCommas"' , function ( ) {
93+
94+ beforeEach ( function ( ) {
95+ checker . configure ( { requireSpaceAfterComma : { allExcept : [ 'trailing' ] } } ) ;
96+ } ) ;
97+
98+ it ( 'should report error when no space is given' , function ( ) {
99+ expect ( checker . checkString ( 'var a,b;' ) ) . to . have . one . validation . error . from ( 'requireSpaceAfterComma' ) ;
100+ } ) ;
101+
102+ it ( 'should report error when space is given before but not after comma' , function ( ) {
103+ expect ( checker . checkString ( 'var a ,b;' ) ) . to . have . one . validation . error . from ( 'requireSpaceAfterComma' ) ;
104+ } ) ;
105+
106+ it ( 'should allow space after comma in var declaration' , function ( ) {
107+ expect ( checker . checkString ( 'var a, b;' ) ) . to . have . no . errors ( ) ;
108+ } ) ;
109+
110+ it ( 'should allow space after and before comma in var declaration' , function ( ) {
111+ expect ( checker . checkString ( 'var a , b;' ) ) . to . have . no . errors ( ) ;
112+ } ) ;
113+
114+ it ( 'should allow new line after comma in var declaration' , function ( ) {
115+ expect ( checker . checkString ( 'var a,\nb,\nc;' ) ) . to . have . no . errors ( ) ;
116+ } ) ;
117+
118+ it ( 'should report errors when no space is given in arrays' , function ( ) {
119+ expect ( checker . checkString ( 'var a = [1,2,3,4];' ) ) . to . have . error . count . equal ( 3 ) ;
120+ } ) ;
121+
122+ it ( 'should report errors when space is given before but not after commas in arrays' , function ( ) {
123+ expect ( checker . checkString ( 'var a = [1 ,2 ,3 ,4];' ) ) . to . have . error . count . equal ( 3 ) ;
124+ } ) ;
125+
126+ it ( 'should allow space after comma in arrays' , function ( ) {
127+ expect ( checker . checkString ( 'var a = [1, 2, 3, 4];' ) ) . to . have . no . errors ( ) ;
128+ } ) ;
129+
130+ it ( 'should allow space after and before comma in arrays' , function ( ) {
131+ expect ( checker . checkString ( 'var a = [1 , 2 , 3 , 4];' ) ) . to . have . no . errors ( ) ;
132+ } ) ;
133+
134+ it ( 'should allow space after trailing comma in arrays' , function ( ) {
135+ expect ( checker . checkString ( 'var a = [1, 2, 3, 4, ];' ) ) . to . have . no . errors ( ) ;
136+ } ) ;
137+
138+ it ( 'should allow no space after trailing comma in arrays' , function ( ) {
139+ expect ( checker . checkString ( 'var a = [1, 2, 3, 4,];' ) ) . to . have . no . errors ( ) ;
140+ } ) ;
141+
142+ it ( 'should allow new line after comma in arrays' , function ( ) {
143+ expect ( checker . checkString ( 'var a = [1,\n2,\n3];' ) ) . to . have . no . errors ( ) ;
144+ } ) ;
145+
146+ it ( 'should report errors when no space is given in objects' , function ( ) {
147+ expect ( checker . checkString ( 'var a = {x:1,y:2,z:3};' ) ) . to . have . error . count . equal ( 2 ) ;
148+ } ) ;
149+
150+ it ( 'should allow when no space is given after trailing comma in object' , function ( ) {
151+ expect ( checker . checkString ( 'var a = {x:1, y:2, z:3,};' ) ) . to . have . no . errors ( ) ;
152+ } ) ;
153+
154+ it ( 'should report errors when space is given before but not after commas in objects' , function ( ) {
155+ expect ( checker . checkString ( 'var a = {x:1 ,y:2 ,z:3};' ) ) . to . have . error . count . equal ( 2 ) ;
156+ } ) ;
157+
158+ it ( 'should allow space after comma in objects' , function ( ) {
159+ expect ( checker . checkString ( 'var a = {x: 1, y: 2, z: 3};' ) ) . to . have . no . errors ( ) ;
160+ } ) ;
161+
162+ it ( 'should allow space after and before comma in objects' , function ( ) {
163+ expect ( checker . checkString ( 'var a = {x: 1 , y: 2 , z: 3};' ) ) . to . have . no . errors ( ) ;
164+ } ) ;
165+
166+ it ( 'should allow new line after comma in objects' , function ( ) {
167+ expect ( checker . checkString ( 'var a = {x: 1,\ny: 2,\nz: 3};' ) ) . to . have . no . errors ( ) ;
168+ } ) ;
169+
170+ it ( 'should allow when no space is given after trailing comma in object in array' , function ( ) {
171+ expect ( checker . checkString ( 'var a = [{a:1, b:2,}, {c:3, d:4,},];' ) ) . to . have . no . errors ( ) ;
172+ } ) ;
173+
71174 } ) ;
72175
176+ describe ( 'incorrect configuration' , function ( ) {
177+
178+ it ( 'should not accept options without a valid key' , function ( ) {
179+ expect ( function ( ) {
180+ checker . configure ( { requireSpaceAfterComma : { } } ) ;
181+ } ) . to . throw ( 'AssertionError' ) ;
182+ } ) ;
183+
184+ } ) ;
73185} ) ;
0 commit comments