comment-parser 0.3.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,570 +1,788 @@
1
- var fs = require('fs');
2
- var expect = require('chai').expect;
3
- var parse = require('../index');
4
-
5
- describe('Comment string parsing', function() {
6
-
7
- /**
8
- * Source lines numeration:
9
- *
10
- * 0 function() {
11
- * 1 // source with comments
12
- * 2 }
13
- *
14
- */
1
+ /* eslint no-unused-vars:off */
15
2
 
16
- function parsed(func, opts) {
17
- var str = func.toString();
18
- return parse(str.slice(
19
- str.indexOf('{') + 1,
20
- str.lastIndexOf('}')
21
- ), opts);
22
- }
3
+ var expect = require('chai').expect
4
+ var parse = require('./parse')
23
5
 
24
- it('should parse doc block with description', function() {
25
- expect(parsed(function(){
6
+ describe('Comment string parsing', function () {
7
+ it('should parse doc block with description', function () {
8
+ expect(parse(function () {
26
9
  /**
27
10
  * Description
28
11
  */
29
12
  })[0])
30
13
  .to.eql({
31
- description : 'Description',
32
- source : 'Description',
33
- line : 1,
34
- tags : []
35
- });
36
- });
37
-
38
- it('should skip surrounding empty lines while preserving line numbers', function() {
39
- expect(parsed(function(){
14
+ description: 'Description',
15
+ source: 'Description',
16
+ line: 1,
17
+ tags: []
18
+ })
19
+ })
20
+
21
+ it('should parse doc block with no mid stars', function () {
22
+ expect(parse(function () {
40
23
  /**
24
+ Description
25
+ */
26
+ })[0])
27
+ .to.eql({
28
+ description: 'Description',
29
+ source: 'Description',
30
+ line: 1,
31
+ tags: []
32
+ })
33
+ })
34
+
35
+ it('should skip surrounding empty lines while preserving line numbers', function () {
36
+ expect(parse(function () {
37
+ /**
38
+ *
41
39
  *
42
- *
43
40
  * Description first line
44
41
  *
45
42
  * Description second line
46
- *
43
+ *
44
+ */
45
+ var a
46
+ })[0])
47
+ .eql({
48
+ description: 'Description first line\n\nDescription second line',
49
+ source: 'Description first line\n\nDescription second line',
50
+ line: 1,
51
+ tags: []
52
+ })
53
+ })
54
+
55
+ it('should accept a description on the first line', function () {
56
+ expect(parse(function () {
57
+ /** Description first line
58
+ *
59
+ * Description second line
47
60
  */
48
- var a;
61
+ var a
49
62
  })[0])
50
63
  .eql({
51
- description : 'Description first line\n\nDescription second line',
52
- source : 'Description first line\n\nDescription second line',
53
- line : 1,
54
- tags : []
55
- });
56
- });
64
+ description: 'Description first line\n\nDescription second line',
65
+ source: 'Description first line\n\nDescription second line',
66
+ line: 1,
67
+ tags: []
68
+ })
69
+ })
70
+
71
+ it('should parse not starred middle lines with `opts.trim = true`', function () {
72
+ expect(parse(function () {
73
+ /**
74
+ Description text
75
+ @tag tagname Tag description
76
+ */
77
+ }, {
78
+ trim: true
79
+ })[0])
80
+ .eql({
81
+ description: 'Description text',
82
+ source: 'Description text\n@tag tagname Tag description',
83
+ line: 1,
84
+ tags: [{
85
+ tag: 'tag',
86
+ name: 'tagname',
87
+ optional: false,
88
+ description: 'Tag description',
89
+ type: '',
90
+ line: 3,
91
+ source: '@tag tagname Tag description'
92
+ }]
93
+ })
94
+ })
57
95
 
58
- it('should skip empty blocks', function() {
96
+ it('should parse not starred middle lines with `opts.trim = false`', function () {
97
+ expect(parse(function () {
98
+ /**
99
+ Description text
100
+ @tag tagname Tag description
101
+ */
102
+ }, {
103
+ trim: false
104
+ })[0])
105
+ .eql({
106
+ description: '\nDescription text',
107
+ source: '\nDescription text\n@tag tagname Tag description\n',
108
+ line: 1,
109
+ tags: [{
110
+ tag: 'tag',
111
+ name: 'tagname',
112
+ optional: false,
113
+ description: 'Tag description\n',
114
+ type: '',
115
+ line: 3,
116
+ source: '@tag tagname Tag description\n'
117
+ }]
118
+ })
119
+ })
59
120
 
60
- expect(parsed(function(){
121
+ it('should accept comment close on a non-empty', function () {
122
+ expect(parse(function () {
123
+ /**
124
+ * Description first line
125
+ *
126
+ * Description second line */
127
+ var a
128
+ })[0])
129
+ .eql({
130
+ description: 'Description first line\n\nDescription second line',
131
+ source: 'Description first line\n\nDescription second line',
132
+ line: 1,
133
+ tags: []
134
+ })
135
+ })
136
+
137
+ it('should skip empty blocks', function () {
138
+ expect(parse(function () {
61
139
  /**
62
- *
140
+ *
63
141
  */
64
- var a;
142
+ var a
65
143
  }).length)
66
- .to.eq(0);
67
- });
144
+ .to.eq(0)
145
+ })
68
146
 
69
- it('should parse multiple doc blocks', function() {
70
- var p = parsed(function(){
147
+ it('should parse multiple doc blocks', function () {
148
+ var p = parse(function () {
71
149
  /**
72
150
  * Description first line
73
151
  */
74
- var a;
152
+ var a
75
153
 
76
154
  /**
77
155
  * Description second line
78
156
  */
79
- var b;
80
- });
157
+ var b
158
+ })
81
159
 
82
160
  expect(p.length)
83
- .to.eq(2);
161
+ .to.eq(2)
84
162
 
85
163
  expect(p[0])
86
164
  .to.eql({
87
- description : 'Description first line',
88
- source : 'Description first line',
89
- line : 1,
90
- tags : []
91
- });
165
+ description: 'Description first line',
166
+ source: 'Description first line',
167
+ line: 1,
168
+ tags: []
169
+ })
92
170
 
93
171
  expect(p[1])
94
172
  .to.eql({
95
- description : 'Description second line',
96
- source : 'Description second line',
97
- line : 6,
98
- tags : []
99
- });
100
- });
101
-
102
- it('should parse one line block', function() {
103
- expect(parsed(function(){
173
+ description: 'Description second line',
174
+ source: 'Description second line',
175
+ line: 6,
176
+ tags: []
177
+ })
178
+ })
179
+
180
+ it('should parse one line block', function () {
181
+ expect(parse(function () {
104
182
  /** Description */
105
- var a;
183
+ var a
106
184
  })[0])
107
185
  .to.eql({
108
- description : 'Description',
109
- source : 'Description',
110
- line : 1,
111
- tags : []
112
- });
113
- });
114
-
115
- it('should skip `/* */` comments', function() {
116
- expect(parsed(function(){
186
+ description: 'Description',
187
+ source: 'Description',
188
+ line: 1,
189
+ tags: []
190
+ })
191
+ })
192
+
193
+ it('should skip `/* */` comments', function () {
194
+ expect(parse(function () {
117
195
  /*
118
196
  *
119
197
  */
120
- var a;
198
+ var a
121
199
  }).length)
122
- .to.eq(0);
123
- });
200
+ .to.eq(0)
201
+ })
124
202
 
125
- it('should skip `/*** */` comments', function() {
126
- expect(parsed(function(){
127
- /*
203
+ it('should skip `/*** */` comments', function () {
204
+ expect(parse(function () {
205
+ /***
128
206
  *
129
207
  */
130
- var a;
208
+ var a
131
209
  }).length)
132
- .to.eq(0);
133
- });
210
+ .to.eq(0)
211
+ })
134
212
 
135
- it('should parse one line block with tag', function() {
136
- expect(parsed(function(){
213
+ it('should preserve empty lines and indentation with `opts.trim = false`', function () {
214
+ expect(parse(function () {
215
+ /**
216
+ *
217
+ *
218
+ * Description first line
219
+ * second line
220
+ *
221
+ * third line
222
+ */
223
+ var a
224
+ }, {
225
+ trim: false
226
+ })[0])
227
+ .eql({
228
+ description: '\n\n\n Description first line\n second line\n\n third line\n',
229
+ source: '\n\n\n Description first line\n second line\n\n third line\n',
230
+ line: 1,
231
+ tags: []
232
+ })
233
+ })
234
+
235
+ it('should parse one line block with tag', function () {
236
+ expect(parse(function () {
137
237
  /** @tag */
138
- var a;
238
+ var a
139
239
  })[0])
140
240
  .to.eql({
141
- description : '',
142
- line : 1,
143
- source : '@tag',
144
- tags : [{
145
- tag : 'tag',
146
- type : '',
147
- name : '',
148
- description : '',
149
- line : 1,
150
- optional : false,
151
- source : '@tag'
152
- }]
153
- });
154
- });
155
-
156
- it('should parse `@tag`', function() {
157
- expect(parsed(function(){
158
- /**
159
- *
160
- * @my-tag
161
- */
162
- var a;
163
- })[0])
164
- .to.eql({
165
- line : 1,
166
- source : '@my-tag',
167
- description : '',
168
- tags: [{
169
- line : 3,
170
- tag : 'my-tag',
171
- source : '@my-tag',
172
- type : '',
173
- name : '',
174
- optional : false,
175
- description : ''
176
- }]
177
- });
178
- });
179
-
180
- it('should parse `@tag {my.type}`', function() {
181
- expect(parsed(function(){
182
- /**
183
- * @my-tag {my.type}
184
- */
185
- var a;
186
- })[0])
187
- .to.eql({
188
- line : 1,
189
- source : '@my-tag {my.type}',
190
- description : '',
191
- tags: [{
192
- line : 2,
193
- tag : 'my-tag',
194
- type : 'my.type',
195
- name : '',
196
- source : '@my-tag {my.type}',
197
- optional : false,
198
- description : ''
199
- }]
200
- });
201
- });
202
-
203
- it('should parse tag with name only `@tag name`', function() {
204
- expect(parsed(function(){
205
- /**
206
- * @my-tag name
207
- */
208
- })[0])
209
- .to.eql({
210
- line : 1,
211
- description : '',
212
- source : '@my-tag name',
213
- tags: [{
214
- line : 2,
215
- tag : 'my-tag',
216
- type : '',
217
- name : 'name',
218
- source : '@my-tag name',
219
- optional : false,
220
- description : ''
221
- }]
222
- });
223
- });
224
-
225
- it('should parse tag with type and name `@tag {my.type} name`', function() {
226
- expect(parsed(function(){
227
- /**
228
- * @my-tag {my.type} name
229
- */
230
- })[0])
231
- .to.eql({
232
- line : 1,
233
- source : '@my-tag {my.type} name',
234
- description : '',
235
- tags: [{
236
- tag : 'my-tag',
237
- line : 2,
238
- type : 'my.type',
239
- name : 'name',
240
- source : '@my-tag {my.type} name',
241
- description : '',
242
- optional : false
243
- }]
244
- });
245
- });
246
-
247
- it('should parse tag with type, name and description `@tag {my.type} name description`', function() {
248
- expect(parsed(function(){
249
- /**
250
- * @my-tag {my.type} name description
251
- */
252
- })[0])
253
- .to.eql({
254
- line : 1,
255
- source : '@my-tag {my.type} name description',
256
- description : '',
257
- tags: [{
258
- tag : 'my-tag',
259
- line : 2,
260
- type : 'my.type',
261
- name : 'name',
262
- source : '@my-tag {my.type} name description',
263
- description : 'description',
264
- optional : false
265
- }]
266
- });
267
- });
268
-
269
- it('should parse tag with multiline description', function() {
270
- expect(parsed(function(){
271
- /**
272
- * @my-tag {my.type} name description line 1
273
- * description line 2
274
- * description line 3
275
- */
276
- })[0])
277
- .to.eql({
278
- line : 1,
279
- source : '@my-tag {my.type} name description line 1\ndescription line 2\ndescription line 3',
280
- description : '',
281
- tags: [{
282
- tag : 'my-tag',
283
- line : 2,
284
- type : 'my.type',
285
- name : 'name',
286
- source : '@my-tag {my.type} name description line 1\ndescription line 2\ndescription line 3',
287
- description : 'description line 1\ndescription line 2\ndescription line 3',
288
- optional : false
289
- }]
290
- });
291
- });
292
-
293
- it('should parse tag with type and optional name `@tag {my.type} [name]`', function() {
294
- expect(parsed(function(){
295
- /**
296
- * @my-tag {my.type} [name]
297
- */
298
- })[0])
299
- .to.eql({
300
- line : 1,
301
- description : '',
302
- source : '@my-tag {my.type} [name]',
303
- tags: [{
304
- tag : 'my-tag',
305
- line : 2,
306
- type : 'my.type',
307
- name : 'name',
308
- description : '',
309
- source : '@my-tag {my.type} [name]',
310
- optional : true
311
- }]
312
- });
313
- });
314
-
315
- it('should parse tag with type and optional name with default value `@tag {my.type} [name=value]`', function() {
316
- expect(parsed(function(){
317
- /**
318
- * @my-tag {my.type} [name=value]
319
- */
320
- })[0])
321
- .to.eql({
322
- line : 1,
323
- description : '',
324
- source : '@my-tag {my.type} [name=value]',
325
- tags: [{
326
- tag : 'my-tag',
327
- line : 2,
328
- type : 'my.type',
329
- name : 'name',
330
- default : 'value',
331
- source : '@my-tag {my.type} [name=value]',
332
- description : '',
333
- optional : true
334
- }]
335
- });
336
- });
337
-
338
- it('should tolerate default value with whitespces `@tag {my.type} [name=John Doe]`', function() {
339
- expect(parsed(function(){
340
- /**
341
- * @my-tag {my.type} [name=John Doe]
342
- */
343
- })[0])
344
- .to.eql({
345
- line : 1,
346
- description : '',
347
- source : '@my-tag {my.type} [name=John Doe]',
348
- tags: [{
349
- tag : 'my-tag',
350
- line : 2,
351
- type : 'my.type',
352
- name : 'name',
353
- description : '',
354
- source : '@my-tag {my.type} [name=John Doe]',
355
- optional : true,
356
- default : 'John Doe'
357
- }]
358
- });
359
- });
360
-
361
- it('should tolerate quoted default value `@tag [name="yay!"]`', function() {
362
- expect(parsed(function(){
363
- /**
364
- * @tag {t} [name="yay!"]
365
- */
366
- })[0])
367
- .to.eql({
368
- line: 1,
369
- source: '@tag {t} [name="yay!"]',
241
+ description: '',
242
+ line: 1,
243
+ source: '@tag',
244
+ tags: [{
245
+ tag: 'tag',
246
+ type: '',
247
+ name: '',
370
248
  description: '',
371
- tags: [{
372
- tag : 'tag',
373
- line : 2,
374
- type : 't',
375
- name : 'name',
376
- source : '@tag {t} [name="yay!"]',
377
- default : 'yay!',
378
- optional : true,
379
- description : ''
380
- }]
381
- });
382
- });
383
-
384
- it('should keep value as is if quotes are mismatched `@tag [name="yay\']`', function() {
385
- expect(parsed(function(){
386
- /**
387
- * @tag {t} [name="yay!'] desc
388
- */
389
- })[0])
390
- .to.eql({
391
249
  line: 1,
250
+ optional: false,
251
+ source: '@tag'
252
+ }]
253
+ })
254
+ })
255
+
256
+ it('should parse `@tag`', function () {
257
+ expect(parse(function () {
258
+ /**
259
+ *
260
+ * @my-tag
261
+ */
262
+ var a
263
+ })[0])
264
+ .to.eql({
265
+ line: 1,
266
+ source: '@my-tag',
267
+ description: '',
268
+ tags: [{
269
+ line: 3,
270
+ tag: 'my-tag',
271
+ source: '@my-tag',
272
+ type: '',
273
+ name: '',
274
+ optional: false,
275
+ description: ''
276
+ }]
277
+ })
278
+ })
279
+
280
+ it('should parse `@tag {my.type}`', function () {
281
+ expect(parse(function () {
282
+ /**
283
+ * @my-tag {my.type}
284
+ */
285
+ var a
286
+ })[0])
287
+ .to.eql({
288
+ line: 1,
289
+ source: '@my-tag {my.type}',
290
+ description: '',
291
+ tags: [{
292
+ line: 2,
293
+ tag: 'my-tag',
294
+ type: 'my.type',
295
+ name: '',
296
+ source: '@my-tag {my.type}',
297
+ optional: false,
298
+ description: ''
299
+ }]
300
+ })
301
+ })
302
+
303
+ it('should parse tag with name only `@tag name`', function () {
304
+ expect(parse(function () {
305
+ /**
306
+ * @my-tag name
307
+ */
308
+ })[0])
309
+ .to.eql({
310
+ line: 1,
311
+ description: '',
312
+ source: '@my-tag name',
313
+ tags: [{
314
+ line: 2,
315
+ tag: 'my-tag',
316
+ type: '',
317
+ name: 'name',
318
+ source: '@my-tag name',
319
+ optional: false,
320
+ description: ''
321
+ }]
322
+ })
323
+ })
324
+
325
+ it('should parse tag with type and name `@tag {my.type} name`', function () {
326
+ expect(parse(function () {
327
+ /**
328
+ * @my-tag {my.type} name
329
+ */
330
+ })[0])
331
+ .to.eql({
332
+ line: 1,
333
+ source: '@my-tag {my.type} name',
334
+ description: '',
335
+ tags: [{
336
+ tag: 'my-tag',
337
+ line: 2,
338
+ type: 'my.type',
339
+ name: 'name',
340
+ source: '@my-tag {my.type} name',
341
+ description: '',
342
+ optional: false
343
+ }]
344
+ })
345
+ })
346
+
347
+ it('should parse tag with type, name and description `@tag {my.type} name description`', function () {
348
+ expect(parse(function () {
349
+ /**
350
+ * @my-tag {my.type} name description
351
+ */
352
+ })[0])
353
+ .to.eql({
354
+ line: 1,
355
+ source: '@my-tag {my.type} name description',
356
+ description: '',
357
+ tags: [{
358
+ tag: 'my-tag',
359
+ line: 2,
360
+ type: 'my.type',
361
+ name: 'name',
362
+ source: '@my-tag {my.type} name description',
363
+ description: 'description',
364
+ optional: false
365
+ }]
366
+ })
367
+ })
368
+
369
+ it('should parse tag with multiline description', function () {
370
+ expect(parse(function () {
371
+ /**
372
+ * @my-tag {my.type} name description line 1
373
+ * description line 2
374
+ * description line 3
375
+ */
376
+ })[0])
377
+ .to.eql({
378
+ line: 1,
379
+ source: '@my-tag {my.type} name description line 1\ndescription line 2\ndescription line 3',
380
+ description: '',
381
+ tags: [{
382
+ tag: 'my-tag',
383
+ line: 2,
384
+ type: 'my.type',
385
+ name: 'name',
386
+ source: '@my-tag {my.type} name description line 1\ndescription line 2\ndescription line 3',
387
+ description: 'description line 1\ndescription line 2\ndescription line 3',
388
+ optional: false
389
+ }]
390
+ })
391
+ })
392
+
393
+ it('should parse tag with type and optional name `@tag {my.type} [name]`', function () {
394
+ expect(parse(function () {
395
+ /**
396
+ * @my-tag {my.type} [name]
397
+ */
398
+ })[0])
399
+ .to.eql({
400
+ line: 1,
401
+ description: '',
402
+ source: '@my-tag {my.type} [name]',
403
+ tags: [{
404
+ tag: 'my-tag',
405
+ line: 2,
406
+ type: 'my.type',
407
+ name: 'name',
408
+ description: '',
409
+ source: '@my-tag {my.type} [name]',
410
+ optional: true
411
+ }]
412
+ })
413
+ })
414
+
415
+ it('should parse tag with type and optional name with default value `@tag {my.type} [name=value]`', function () {
416
+ expect(parse(function () {
417
+ /**
418
+ * @my-tag {my.type} [name=value]
419
+ */
420
+ })[0])
421
+ .to.eql({
422
+ line: 1,
423
+ description: '',
424
+ source: '@my-tag {my.type} [name=value]',
425
+ tags: [{
426
+ tag: 'my-tag',
427
+ line: 2,
428
+ type: 'my.type',
429
+ name: 'name',
430
+ default: 'value',
431
+ source: '@my-tag {my.type} [name=value]',
432
+ description: '',
433
+ optional: true
434
+ }]
435
+ })
436
+ })
437
+
438
+ it('should tolerate default value with whitespces `@tag {my.type} [name=John Doe]`', function () {
439
+ expect(parse(function () {
440
+ /**
441
+ * @my-tag {my.type} [name=John Doe]
442
+ */
443
+ })[0])
444
+ .to.eql({
445
+ line: 1,
446
+ description: '',
447
+ source: '@my-tag {my.type} [name=John Doe]',
448
+ tags: [{
449
+ tag: 'my-tag',
450
+ line: 2,
451
+ type: 'my.type',
452
+ name: 'name',
453
+ description: '',
454
+ source: '@my-tag {my.type} [name=John Doe]',
455
+ optional: true,
456
+ default: 'John Doe'
457
+ }]
458
+ })
459
+ })
460
+
461
+ it('should tolerate quoted default value `@tag [name="yay!"]`', function () {
462
+ expect(parse(function () {
463
+ /**
464
+ * @tag {t} [name="yay!"]
465
+ */
466
+ })[0])
467
+ .to.eql({
468
+ line: 1,
469
+ source: '@tag {t} [name="yay!"]',
470
+ description: '',
471
+ tags: [{
472
+ tag: 'tag',
473
+ line: 2,
474
+ type: 't',
475
+ name: 'name',
476
+ source: '@tag {t} [name="yay!"]',
477
+ default: 'yay!',
478
+ optional: true,
479
+ description: ''
480
+ }]
481
+ })
482
+ })
483
+
484
+ it('should keep value as is if quotes are mismatched `@tag [name="yay\']`', function () {
485
+ expect(parse(function () {
486
+ /**
487
+ * @tag {t} [name="yay!'] desc
488
+ */
489
+ })[0])
490
+ .to.eql({
491
+ line: 1,
492
+ description: '',
493
+ source: '@tag {t} [name="yay!\'] desc',
494
+ tags: [{
495
+ tag: 'tag',
496
+ line: 2,
497
+ type: 't',
498
+ name: 'name',
499
+ source: '@tag {t} [name="yay!\'] desc',
500
+ default: '"yay!\'',
501
+ optional: true,
502
+ description: 'desc'
503
+ }]
504
+ })
505
+ })
506
+
507
+ it('should parse rest names `@tag ...name desc`', function () {
508
+ expect(parse(function () {
509
+ /**
510
+ * @tag {t} ...name desc
511
+ */
512
+ })[0])
513
+ .to.eql({
514
+ line: 1,
515
+ description: '',
516
+ source: '@tag {t} ...name desc',
517
+ tags: [{
518
+ tag: 'tag',
519
+ line: 2,
520
+ type: 't',
521
+ name: '...name',
522
+ optional: false,
523
+ source: '@tag {t} ...name desc',
524
+ description: 'desc'
525
+ }]
526
+ })
527
+ })
528
+
529
+ it('should parse optional rest names `@tag [...name] desc`', function () {
530
+ expect(parse(function () {
531
+ /**
532
+ * @tag {t} [...name] desc
533
+ */
534
+ })[0])
535
+ .to.eql({
536
+ line: 1,
537
+ description: '',
538
+ source: '@tag {t} [...name] desc',
539
+ tags: [{
540
+ tag: 'tag',
541
+ line: 2,
542
+ type: 't',
543
+ name: '...name',
544
+ optional: true,
545
+ source: '@tag {t} [...name] desc',
546
+ description: 'desc'
547
+ }]
548
+ })
549
+ })
550
+
551
+ it('should parse multiple tags', function () {
552
+ expect(parse(function () {
553
+ /**
554
+ * Description
555
+ * @my-tag1
556
+ * @my-tag2
557
+ */
558
+ })[0])
559
+ .to.eql({
560
+ line: 1,
561
+ description: 'Description',
562
+ source: 'Description\n@my-tag1\n@my-tag2',
563
+ tags: [{
564
+ tag: 'my-tag1',
565
+ line: 3,
566
+ type: '',
567
+ name: '',
568
+ optional: false,
569
+ source: '@my-tag1',
570
+ description: ''
571
+ }, {
572
+ tag: 'my-tag2',
573
+ line: 4,
574
+ type: '',
575
+ name: '',
576
+ optional: false,
577
+ source: '@my-tag2',
578
+ description: ''
579
+ }]
580
+ })
581
+ })
582
+
583
+ it('should parse nested tags', function () {
584
+ expect(parse(function () {
585
+ /**
586
+ * Description
587
+ * @my-tag name
588
+ * @my-tag name.sub-name
589
+ * @my-tag name.sub-name.sub-sub-name
590
+ */
591
+ }, {dotted_names: true})[0])
592
+ .to.eql({
593
+ line: 1,
594
+ description: 'Description',
595
+ source: 'Description\n@my-tag name\n@my-tag name.sub-name\n@my-tag name.sub-name.sub-sub-name',
596
+ tags: [{
597
+ tag: 'my-tag',
598
+ line: 3,
599
+ type: '',
600
+ name: 'name',
601
+ source: '@my-tag name',
602
+ optional: false,
392
603
  description: '',
393
- source : '@tag {t} [name="yay!\'] desc',
394
- tags: [{
395
- tag : 'tag',
396
- line : 2,
397
- type : 't',
398
- name : 'name',
399
- source : '@tag {t} [name="yay!\'] desc',
400
- default : '"yay!\'',
401
- optional : true,
402
- description : 'desc'
403
- }]
404
- });
405
- });
406
-
407
- it('should parse rest names `@tag ...name desc`', function() {
408
- expect(parsed(function(){
409
- /**
410
- * @tag {t} ...name desc
411
- */
412
- })[0])
413
- .to.eql({
414
- line : 1,
415
- description : '',
416
- source : '@tag {t} ...name desc',
417
- tags: [{
418
- tag : 'tag',
419
- line : 2,
420
- type : 't',
421
- name : '...name',
422
- optional : false,
423
- source : '@tag {t} ...name desc',
424
- description : 'desc'
425
- }]
426
- });
427
- });
428
-
429
- it('should parse optionalrest names `@tag [...name] desc`', function() {
430
- expect(parsed(function(){
431
- /**
432
- * @tag {t} [...name] desc
433
- */
434
- })[0])
435
- .to.eql({
436
- line : 1,
437
- description : '',
438
- source : '@tag {t} [...name] desc',
439
604
  tags: [{
440
- tag : 'tag',
441
- line : 2,
442
- type : 't',
443
- name : '...name',
444
- optional : true,
445
- source : '@tag {t} [...name] desc',
446
- description : 'desc'
447
- }]
448
- });
449
- });
450
-
451
- it('should parse multiple tags', function() {
452
- expect(parsed(function(){
453
- /**
454
- * Description
455
- * @my-tag1
456
- * @my-tag2
457
- */
458
- })[0])
459
- .to.eql({
460
- line : 1,
461
- description : 'Description',
462
- source : 'Description\n@my-tag1\n@my-tag2',
463
- tags : [{
464
- tag : 'my-tag1',
465
- line : 3,
466
- type : '',
467
- name : '',
468
- optional : false,
469
- source : '@my-tag1',
470
- description : ''
471
- }, {
472
- tag : 'my-tag2',
473
- line : 4,
474
- type : '',
475
- name : '',
476
- optional : false,
477
- source : '@my-tag2',
478
- description : ''
479
- }]
480
- });
481
- });
482
-
483
- it('should parse nested tags', function() {
484
- expect(parsed(function(){
485
- /**
486
- * Description
487
- * @my-tag name
488
- * @my-tag name.sub-name
489
- * @my-tag name.sub-name.sub-sub-name
490
- */
491
- }, {dotted_names: true})[0])
492
- .to.eql({
493
- line : 1,
494
- description : 'Description',
495
- source : "Description\n@my-tag name\n@my-tag name.sub-name\n@my-tag name.sub-name.sub-sub-name",
496
- tags : [{
497
- tag : 'my-tag',
498
- line : 3,
499
- type : '',
500
- name : 'name',
501
- source : '@my-tag name',
502
- optional : false,
503
- description : '',
504
- tags : [{
505
- tag : 'my-tag',
506
- line : 4,
507
- type : '',
508
- name : 'sub-name',
509
- optional : false,
510
- source : '@my-tag name.sub-name',
511
- description : '',
512
- tags : [{
513
- tag : 'my-tag',
514
- line : 5,
515
- type : '',
516
- name : 'sub-sub-name',
517
- optional : false,
518
- source : '@my-tag name.sub-name.sub-sub-name',
519
- description : ''
520
- }]
605
+ tag: 'my-tag',
606
+ line: 4,
607
+ type: '',
608
+ name: 'sub-name',
609
+ optional: false,
610
+ source: '@my-tag name.sub-name',
611
+ description: '',
612
+ tags: [{
613
+ tag: 'my-tag',
614
+ line: 5,
615
+ type: '',
616
+ name: 'sub-sub-name',
617
+ optional: false,
618
+ source: '@my-tag name.sub-name.sub-sub-name',
619
+ description: ''
521
620
  }]
522
621
  }]
523
- });
524
- });
525
-
526
- it('should parse complex types `@tag {{a: type}} name`', function() {
527
- expect(parsed(function(){
528
- /**
529
- * @my-tag {{a: number}} name
530
- */
531
- })[0])
532
- .to.eql({
533
- line : 1,
534
- source : '@my-tag {{a: number}} name',
535
- description : '',
536
- tags: [{
537
- tag : 'my-tag',
538
- line : 2,
539
- type : '{a: number}',
540
- name : 'name',
541
- source : '@my-tag {{a: number}} name',
542
- optional : false,
543
- description : ''
544
- }]
545
- });
546
- });
547
-
548
- it('should gracefully fail on syntax errors `@tag {{a: type} name`', function() {
549
- expect(parsed(function(){
550
- /**
551
- * @my-tag {{a: number} name
552
- */
553
- })[0])
554
- .to.eql({
555
- line : 1,
556
- description : '',
557
- source : '@my-tag {{a: number} name',
558
- tags: [{
559
- tag : 'my-tag',
560
- line : 2,
561
- type : '',
562
- name : '',
563
- description : '',
564
- source : '@my-tag {{a: number} name',
565
- optional : false,
566
- errors : ['parse_type: Invalid `{type}`, unpaired curlies']
567
- }]
568
- });
569
- });
570
- });
622
+ }]
623
+ })
624
+ })
625
+
626
+ it('should parse complex types `@tag {{a: type}} name`', function () {
627
+ expect(parse(function () {
628
+ /**
629
+ * @my-tag {{a: number}} name
630
+ */
631
+ })[0])
632
+ .to.eql({
633
+ line: 1,
634
+ source: '@my-tag {{a: number}} name',
635
+ description: '',
636
+ tags: [{
637
+ tag: 'my-tag',
638
+ line: 2,
639
+ type: '{a: number}',
640
+ name: 'name',
641
+ source: '@my-tag {{a: number}} name',
642
+ optional: false,
643
+ description: ''
644
+ }]
645
+ })
646
+ })
647
+
648
+ it('should gracefully fail on syntax errors `@tag {{a: type} name`', function () {
649
+ expect(parse(function () {
650
+ /**
651
+ * @my-tag {{a: number} name
652
+ */
653
+ })[0])
654
+ .to.eql({
655
+ line: 1,
656
+ description: '',
657
+ source: '@my-tag {{a: number} name',
658
+ tags: [{
659
+ tag: 'my-tag',
660
+ line: 2,
661
+ type: '',
662
+ name: '',
663
+ description: '',
664
+ source: '@my-tag {{a: number} name',
665
+ optional: false,
666
+ errors: ['parse_type: Invalid `{type}`, unpaired curlies']
667
+ }]
668
+ })
669
+ })
670
+
671
+ it('should parse $ in description`', function () {
672
+ expect(parse(function () {
673
+ /**
674
+ * @my-tag {String} name description with $ char
675
+ */
676
+ })[0])
677
+ .to.eql({
678
+ line: 1,
679
+ source: '@my-tag {String} name description with $ char',
680
+ description: '',
681
+ tags: [{
682
+ tag: 'my-tag',
683
+ line: 2,
684
+ type: 'String',
685
+ name: 'name',
686
+ source: '@my-tag {String} name description with $ char',
687
+ optional: false,
688
+ description: 'description with $ char'
689
+ }]
690
+ })
691
+ })
692
+
693
+ it('should parse doc block with bound forced to the left', function () {
694
+ expect(parse(function () {
695
+ /**
696
+ * Description text
697
+ * @tag tagname Tag description
698
+ */
699
+ })[0])
700
+ .to.eql({
701
+ description: 'Description text',
702
+ source: 'Description text\n@tag tagname Tag description',
703
+ line: 1,
704
+ tags: [{
705
+ tag: 'tag',
706
+ name: 'tagname',
707
+ optional: false,
708
+ description: 'Tag description',
709
+ type: '',
710
+ line: 3,
711
+ source: '@tag tagname Tag description'
712
+ }]
713
+ })
714
+ })
715
+
716
+ it('should parse doc block with bound forced to the right', function () {
717
+ expect(parse(function () {
718
+ /**
719
+ * Description text
720
+ * @tag tagname Tag description
721
+ */
722
+ })[0])
723
+ .to.eql({
724
+ description: 'Description text',
725
+ source: 'Description text\n@tag tagname Tag description',
726
+ line: 1,
727
+ tags: [{
728
+ tag: 'tag',
729
+ name: 'tagname',
730
+ optional: false,
731
+ description: 'Tag description',
732
+ type: '',
733
+ line: 3,
734
+ source: '@tag tagname Tag description'
735
+ }]
736
+ })
737
+ })
738
+
739
+ it('should parse doc block with soft bound', function () {
740
+ expect(parse(function () {
741
+ /**
742
+ Description text
743
+ another line
744
+ @tag tagname Tag description
745
+ */
746
+ })[0])
747
+ .to.eql({
748
+ description: 'Description text\nanother line',
749
+ source: 'Description text\nanother line\n@tag tagname Tag description',
750
+ line: 1,
751
+ tags: [{
752
+ tag: 'tag',
753
+ name: 'tagname',
754
+ optional: false,
755
+ description: 'Tag description',
756
+ type: '',
757
+ line: 4,
758
+ source: '@tag tagname Tag description'
759
+ }]
760
+ })
761
+ })
762
+
763
+ it('should parse doc block with soft bound respecting `opts.trim = false`', function () {
764
+ expect(parse(function () {
765
+ /**
766
+ Description text
767
+ another line
768
+ @tag tagname Tag description
769
+ */
770
+ }, {
771
+ trim: false
772
+ })[0])
773
+ .to.eql({
774
+ description: '\nDescription text\n another line',
775
+ source: '\nDescription text\n another line\n@tag tagname Tag description\n',
776
+ line: 1,
777
+ tags: [{
778
+ tag: 'tag',
779
+ name: 'tagname',
780
+ optional: false,
781
+ description: 'Tag description\n',
782
+ type: '',
783
+ line: 4,
784
+ source: '@tag tagname Tag description\n'
785
+ }]
786
+ })
787
+ })
788
+ })