comment-parser 0.3.2 → 0.5.0
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.
- package/.eslintignore +1 -0
- package/.eslintrc +11 -0
- package/.travis.yml +2 -4
- package/CHANGELOG.md +9 -0
- package/README.md +24 -5
- package/index.js +31 -34
- package/package.json +11 -6
- package/parser.js +180 -246
- package/parsers.js +100 -0
- package/tests/custom-parsers.spec.js +90 -99
- package/tests/files.spec.js +45 -46
- package/tests/fixtures/sample.js +15 -15
- package/tests/parse.js +18 -0
- package/tests/parse.spec.js +787 -534
- package/.jshintrc +0 -11
- package/.npmignore +0 -15
package/tests/parse.spec.js
CHANGED
|
@@ -1,42 +1,39 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
|
32
|
-
source
|
|
33
|
-
line
|
|
34
|
-
tags
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('should
|
|
39
|
-
expect(
|
|
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 () {
|
|
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 () {
|
|
40
37
|
/**
|
|
41
38
|
*
|
|
42
39
|
*
|
|
@@ -45,95 +42,176 @@ describe('Comment string parsing', function() {
|
|
|
45
42
|
* Description second line
|
|
46
43
|
*
|
|
47
44
|
*/
|
|
48
|
-
var a
|
|
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
|
|
60
|
+
*/
|
|
61
|
+
var a
|
|
62
|
+
})[0])
|
|
63
|
+
.eql({
|
|
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
|
|
49
79
|
})[0])
|
|
50
80
|
.eql({
|
|
51
|
-
description
|
|
52
|
-
source
|
|
53
|
-
line
|
|
54
|
-
tags
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
|
88
|
-
source
|
|
89
|
-
line
|
|
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
|
|
96
|
-
source
|
|
97
|
-
line
|
|
98
|
-
tags
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('should parse one line block', function() {
|
|
103
|
-
expect(
|
|
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
|
|
109
|
-
source
|
|
110
|
-
line
|
|
111
|
-
tags
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
it('should skip `/* */` comments', function() {
|
|
116
|
-
expect(
|
|
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(
|
|
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 preserve empty lines and indentation with `opts.trim = false`', function() {
|
|
136
|
-
expect(
|
|
213
|
+
it('should preserve empty lines and indentation with `opts.trim = false`', function () {
|
|
214
|
+
expect(parse(function () {
|
|
137
215
|
/**
|
|
138
216
|
*
|
|
139
217
|
*
|
|
@@ -142,473 +220,648 @@ describe('Comment string parsing', function() {
|
|
|
142
220
|
*
|
|
143
221
|
* third line
|
|
144
222
|
*/
|
|
145
|
-
var a
|
|
223
|
+
var a
|
|
146
224
|
}, {
|
|
147
225
|
trim: false
|
|
148
226
|
})[0])
|
|
149
227
|
.eql({
|
|
150
|
-
description
|
|
151
|
-
source
|
|
152
|
-
line
|
|
153
|
-
tags
|
|
154
|
-
})
|
|
155
|
-
})
|
|
156
|
-
|
|
157
|
-
it('should parse one line block with tag', function() {
|
|
158
|
-
expect(
|
|
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 () {
|
|
159
237
|
/** @tag */
|
|
160
|
-
var a
|
|
238
|
+
var a
|
|
161
239
|
})[0])
|
|
162
240
|
.to.eql({
|
|
163
|
-
description
|
|
164
|
-
line
|
|
165
|
-
source
|
|
166
|
-
tags
|
|
167
|
-
tag
|
|
168
|
-
type
|
|
169
|
-
name
|
|
170
|
-
description : '',
|
|
171
|
-
line : 1,
|
|
172
|
-
optional : false,
|
|
173
|
-
source : '@tag'
|
|
174
|
-
}]
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('should parse `@tag`', function() {
|
|
179
|
-
expect(parsed(function(){
|
|
180
|
-
/**
|
|
181
|
-
*
|
|
182
|
-
* @my-tag
|
|
183
|
-
*/
|
|
184
|
-
var a;
|
|
185
|
-
})[0])
|
|
186
|
-
.to.eql({
|
|
187
|
-
line : 1,
|
|
188
|
-
source : '@my-tag',
|
|
189
|
-
description : '',
|
|
190
|
-
tags: [{
|
|
191
|
-
line : 3,
|
|
192
|
-
tag : 'my-tag',
|
|
193
|
-
source : '@my-tag',
|
|
194
|
-
type : '',
|
|
195
|
-
name : '',
|
|
196
|
-
optional : false,
|
|
197
|
-
description : ''
|
|
198
|
-
}]
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('should parse `@tag {my.type}`', function() {
|
|
203
|
-
expect(parsed(function(){
|
|
204
|
-
/**
|
|
205
|
-
* @my-tag {my.type}
|
|
206
|
-
*/
|
|
207
|
-
var a;
|
|
208
|
-
})[0])
|
|
209
|
-
.to.eql({
|
|
210
|
-
line : 1,
|
|
211
|
-
source : '@my-tag {my.type}',
|
|
212
|
-
description : '',
|
|
213
|
-
tags: [{
|
|
214
|
-
line : 2,
|
|
215
|
-
tag : 'my-tag',
|
|
216
|
-
type : 'my.type',
|
|
217
|
-
name : '',
|
|
218
|
-
source : '@my-tag {my.type}',
|
|
219
|
-
optional : false,
|
|
220
|
-
description : ''
|
|
221
|
-
}]
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it('should parse tag with name only `@tag name`', function() {
|
|
226
|
-
expect(parsed(function(){
|
|
227
|
-
/**
|
|
228
|
-
* @my-tag name
|
|
229
|
-
*/
|
|
230
|
-
})[0])
|
|
231
|
-
.to.eql({
|
|
232
|
-
line : 1,
|
|
233
|
-
description : '',
|
|
234
|
-
source : '@my-tag name',
|
|
235
|
-
tags: [{
|
|
236
|
-
line : 2,
|
|
237
|
-
tag : 'my-tag',
|
|
238
|
-
type : '',
|
|
239
|
-
name : 'name',
|
|
240
|
-
source : '@my-tag name',
|
|
241
|
-
optional : false,
|
|
242
|
-
description : ''
|
|
243
|
-
}]
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('should parse tag with type and name `@tag {my.type} name`', function() {
|
|
248
|
-
expect(parsed(function(){
|
|
249
|
-
/**
|
|
250
|
-
* @my-tag {my.type} name
|
|
251
|
-
*/
|
|
252
|
-
})[0])
|
|
253
|
-
.to.eql({
|
|
254
|
-
line : 1,
|
|
255
|
-
source : '@my-tag {my.type} name',
|
|
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',
|
|
263
|
-
description : '',
|
|
264
|
-
optional : false
|
|
265
|
-
}]
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('should parse tag with type, name and description `@tag {my.type} name description`', function() {
|
|
270
|
-
expect(parsed(function(){
|
|
271
|
-
/**
|
|
272
|
-
* @my-tag {my.type} name description
|
|
273
|
-
*/
|
|
274
|
-
})[0])
|
|
275
|
-
.to.eql({
|
|
276
|
-
line : 1,
|
|
277
|
-
source : '@my-tag {my.type} name description',
|
|
278
|
-
description : '',
|
|
279
|
-
tags: [{
|
|
280
|
-
tag : 'my-tag',
|
|
281
|
-
line : 2,
|
|
282
|
-
type : 'my.type',
|
|
283
|
-
name : 'name',
|
|
284
|
-
source : '@my-tag {my.type} name description',
|
|
285
|
-
description : 'description',
|
|
286
|
-
optional : false
|
|
287
|
-
}]
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it('should parse tag with multiline description', function() {
|
|
292
|
-
expect(parsed(function(){
|
|
293
|
-
/**
|
|
294
|
-
* @my-tag {my.type} name description line 1
|
|
295
|
-
* description line 2
|
|
296
|
-
* description line 3
|
|
297
|
-
*/
|
|
298
|
-
})[0])
|
|
299
|
-
.to.eql({
|
|
300
|
-
line : 1,
|
|
301
|
-
source : '@my-tag {my.type} name description line 1\ndescription line 2\ndescription line 3',
|
|
302
|
-
description : '',
|
|
303
|
-
tags: [{
|
|
304
|
-
tag : 'my-tag',
|
|
305
|
-
line : 2,
|
|
306
|
-
type : 'my.type',
|
|
307
|
-
name : 'name',
|
|
308
|
-
source : '@my-tag {my.type} name description line 1\ndescription line 2\ndescription line 3',
|
|
309
|
-
description : 'description line 1\ndescription line 2\ndescription line 3',
|
|
310
|
-
optional : false
|
|
311
|
-
}]
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('should parse tag with type and optional name `@tag {my.type} [name]`', function() {
|
|
316
|
-
expect(parsed(function(){
|
|
317
|
-
/**
|
|
318
|
-
* @my-tag {my.type} [name]
|
|
319
|
-
*/
|
|
320
|
-
})[0])
|
|
321
|
-
.to.eql({
|
|
322
|
-
line : 1,
|
|
323
|
-
description : '',
|
|
324
|
-
source : '@my-tag {my.type} [name]',
|
|
325
|
-
tags: [{
|
|
326
|
-
tag : 'my-tag',
|
|
327
|
-
line : 2,
|
|
328
|
-
type : 'my.type',
|
|
329
|
-
name : 'name',
|
|
330
|
-
description : '',
|
|
331
|
-
source : '@my-tag {my.type} [name]',
|
|
332
|
-
optional : true
|
|
333
|
-
}]
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it('should parse tag with type and optional name with default value `@tag {my.type} [name=value]`', function() {
|
|
338
|
-
expect(parsed(function(){
|
|
339
|
-
/**
|
|
340
|
-
* @my-tag {my.type} [name=value]
|
|
341
|
-
*/
|
|
342
|
-
})[0])
|
|
343
|
-
.to.eql({
|
|
344
|
-
line : 1,
|
|
345
|
-
description : '',
|
|
346
|
-
source : '@my-tag {my.type} [name=value]',
|
|
347
|
-
tags: [{
|
|
348
|
-
tag : 'my-tag',
|
|
349
|
-
line : 2,
|
|
350
|
-
type : 'my.type',
|
|
351
|
-
name : 'name',
|
|
352
|
-
default : 'value',
|
|
353
|
-
source : '@my-tag {my.type} [name=value]',
|
|
354
|
-
description : '',
|
|
355
|
-
optional : true
|
|
356
|
-
}]
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it('should tolerate default value with whitespces `@tag {my.type} [name=John Doe]`', function() {
|
|
361
|
-
expect(parsed(function(){
|
|
362
|
-
/**
|
|
363
|
-
* @my-tag {my.type} [name=John Doe]
|
|
364
|
-
*/
|
|
365
|
-
})[0])
|
|
366
|
-
.to.eql({
|
|
367
|
-
line : 1,
|
|
368
|
-
description : '',
|
|
369
|
-
source : '@my-tag {my.type} [name=John Doe]',
|
|
370
|
-
tags: [{
|
|
371
|
-
tag : 'my-tag',
|
|
372
|
-
line : 2,
|
|
373
|
-
type : 'my.type',
|
|
374
|
-
name : 'name',
|
|
375
|
-
description : '',
|
|
376
|
-
source : '@my-tag {my.type} [name=John Doe]',
|
|
377
|
-
optional : true,
|
|
378
|
-
default : 'John Doe'
|
|
379
|
-
}]
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
it('should tolerate quoted default value `@tag [name="yay!"]`', function() {
|
|
384
|
-
expect(parsed(function(){
|
|
385
|
-
/**
|
|
386
|
-
* @tag {t} [name="yay!"]
|
|
387
|
-
*/
|
|
388
|
-
})[0])
|
|
389
|
-
.to.eql({
|
|
390
|
-
line: 1,
|
|
391
|
-
source: '@tag {t} [name="yay!"]',
|
|
241
|
+
description: '',
|
|
242
|
+
line: 1,
|
|
243
|
+
source: '@tag',
|
|
244
|
+
tags: [{
|
|
245
|
+
tag: 'tag',
|
|
246
|
+
type: '',
|
|
247
|
+
name: '',
|
|
392
248
|
description: '',
|
|
393
|
-
tags: [{
|
|
394
|
-
tag : 'tag',
|
|
395
|
-
line : 2,
|
|
396
|
-
type : 't',
|
|
397
|
-
name : 'name',
|
|
398
|
-
source : '@tag {t} [name="yay!"]',
|
|
399
|
-
default : 'yay!',
|
|
400
|
-
optional : true,
|
|
401
|
-
description : ''
|
|
402
|
-
}]
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it('should keep value as is if quotes are mismatched `@tag [name="yay\']`', function() {
|
|
407
|
-
expect(parsed(function(){
|
|
408
|
-
/**
|
|
409
|
-
* @tag {t} [name="yay!'] desc
|
|
410
|
-
*/
|
|
411
|
-
})[0])
|
|
412
|
-
.to.eql({
|
|
413
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,
|
|
414
603
|
description: '',
|
|
415
|
-
source : '@tag {t} [name="yay!\'] desc',
|
|
416
|
-
tags: [{
|
|
417
|
-
tag : 'tag',
|
|
418
|
-
line : 2,
|
|
419
|
-
type : 't',
|
|
420
|
-
name : 'name',
|
|
421
|
-
source : '@tag {t} [name="yay!\'] desc',
|
|
422
|
-
default : '"yay!\'',
|
|
423
|
-
optional : true,
|
|
424
|
-
description : 'desc'
|
|
425
|
-
}]
|
|
426
|
-
});
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
it('should parse rest 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
|
-
tags: [{
|
|
440
|
-
tag : 'tag',
|
|
441
|
-
line : 2,
|
|
442
|
-
type : 't',
|
|
443
|
-
name : '...name',
|
|
444
|
-
optional : false,
|
|
445
|
-
source : '@tag {t} ...name desc',
|
|
446
|
-
description : 'desc'
|
|
447
|
-
}]
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
it('should parse optional rest names `@tag [...name] desc`', function() {
|
|
452
|
-
expect(parsed(function(){
|
|
453
|
-
/**
|
|
454
|
-
* @tag {t} [...name] desc
|
|
455
|
-
*/
|
|
456
|
-
})[0])
|
|
457
|
-
.to.eql({
|
|
458
|
-
line : 1,
|
|
459
|
-
description : '',
|
|
460
|
-
source : '@tag {t} [...name] desc',
|
|
461
604
|
tags: [{
|
|
462
|
-
tag
|
|
463
|
-
line
|
|
464
|
-
type
|
|
465
|
-
name
|
|
466
|
-
optional
|
|
467
|
-
source
|
|
468
|
-
description
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
* @my-tag1
|
|
478
|
-
* @my-tag2
|
|
479
|
-
*/
|
|
480
|
-
})[0])
|
|
481
|
-
.to.eql({
|
|
482
|
-
line : 1,
|
|
483
|
-
description : 'Description',
|
|
484
|
-
source : 'Description\n@my-tag1\n@my-tag2',
|
|
485
|
-
tags : [{
|
|
486
|
-
tag : 'my-tag1',
|
|
487
|
-
line : 3,
|
|
488
|
-
type : '',
|
|
489
|
-
name : '',
|
|
490
|
-
optional : false,
|
|
491
|
-
source : '@my-tag1',
|
|
492
|
-
description : ''
|
|
493
|
-
}, {
|
|
494
|
-
tag : 'my-tag2',
|
|
495
|
-
line : 4,
|
|
496
|
-
type : '',
|
|
497
|
-
name : '',
|
|
498
|
-
optional : false,
|
|
499
|
-
source : '@my-tag2',
|
|
500
|
-
description : ''
|
|
501
|
-
}]
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
it('should parse nested tags', function() {
|
|
506
|
-
expect(parsed(function(){
|
|
507
|
-
/**
|
|
508
|
-
* Description
|
|
509
|
-
* @my-tag name
|
|
510
|
-
* @my-tag name.sub-name
|
|
511
|
-
* @my-tag name.sub-name.sub-sub-name
|
|
512
|
-
*/
|
|
513
|
-
}, {dotted_names: true})[0])
|
|
514
|
-
.to.eql({
|
|
515
|
-
line : 1,
|
|
516
|
-
description : 'Description',
|
|
517
|
-
source : "Description\n@my-tag name\n@my-tag name.sub-name\n@my-tag name.sub-name.sub-sub-name",
|
|
518
|
-
tags : [{
|
|
519
|
-
tag : 'my-tag',
|
|
520
|
-
line : 3,
|
|
521
|
-
type : '',
|
|
522
|
-
name : 'name',
|
|
523
|
-
source : '@my-tag name',
|
|
524
|
-
optional : false,
|
|
525
|
-
description : '',
|
|
526
|
-
tags : [{
|
|
527
|
-
tag : 'my-tag',
|
|
528
|
-
line : 4,
|
|
529
|
-
type : '',
|
|
530
|
-
name : 'sub-name',
|
|
531
|
-
optional : false,
|
|
532
|
-
source : '@my-tag name.sub-name',
|
|
533
|
-
description : '',
|
|
534
|
-
tags : [{
|
|
535
|
-
tag : 'my-tag',
|
|
536
|
-
line : 5,
|
|
537
|
-
type : '',
|
|
538
|
-
name : 'sub-sub-name',
|
|
539
|
-
optional : false,
|
|
540
|
-
source : '@my-tag name.sub-name.sub-sub-name',
|
|
541
|
-
description : ''
|
|
542
|
-
}]
|
|
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: ''
|
|
543
620
|
}]
|
|
544
621
|
}]
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
it('should parse complex types `@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
|
-
source : '@my-tag {{a: number}} name',
|
|
557
|
-
description : '',
|
|
558
|
-
tags: [{
|
|
559
|
-
tag : 'my-tag',
|
|
560
|
-
line : 2,
|
|
561
|
-
type : '{a: number}',
|
|
562
|
-
name : 'name',
|
|
563
|
-
source : '@my-tag {{a: number}} name',
|
|
564
|
-
optional : false,
|
|
565
|
-
description : ''
|
|
566
|
-
}]
|
|
567
|
-
});
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
it('should gracefully fail on syntax errors `@tag {{a: type} name`', function() {
|
|
571
|
-
expect(parsed(function(){
|
|
572
|
-
/**
|
|
573
|
-
* @my-tag {{a: number} name
|
|
574
|
-
*/
|
|
575
|
-
})[0])
|
|
576
|
-
.to.eql({
|
|
577
|
-
line : 1,
|
|
578
|
-
description : '',
|
|
579
|
-
source : '@my-tag {{a: number} name',
|
|
580
|
-
tags: [{
|
|
581
|
-
tag : 'my-tag',
|
|
582
|
-
line : 2,
|
|
583
|
-
type : '',
|
|
584
|
-
name : '',
|
|
585
|
-
description : '',
|
|
586
|
-
source : '@my-tag {{a: number} name',
|
|
587
|
-
optional : false,
|
|
588
|
-
errors : ['parse_type: Invalid `{type}`, unpaired curlies']
|
|
589
|
-
}]
|
|
590
|
-
});
|
|
591
|
-
});
|
|
622
|
+
}]
|
|
623
|
+
})
|
|
624
|
+
})
|
|
592
625
|
|
|
593
|
-
it('
|
|
594
|
-
expect(
|
|
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 () {
|
|
595
673
|
/**
|
|
596
674
|
* @my-tag {String} name description with $ char
|
|
597
675
|
*/
|
|
598
676
|
})[0])
|
|
599
677
|
.to.eql({
|
|
600
|
-
line
|
|
601
|
-
source
|
|
602
|
-
description
|
|
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
|
+
|
|
789
|
+
it('should parse multiline without star as same line respecting `opts.join = true`', function () {
|
|
790
|
+
expect(parse(function () {
|
|
791
|
+
/**
|
|
792
|
+
* @tag name
|
|
793
|
+
* description
|
|
794
|
+
same line
|
|
795
|
+
*/
|
|
796
|
+
}, {
|
|
797
|
+
join: true
|
|
798
|
+
})[0])
|
|
799
|
+
.to.eql({
|
|
800
|
+
line: 1,
|
|
801
|
+
description: '',
|
|
802
|
+
source: '@tag name\ndescription\nsame line',
|
|
803
|
+
tags: [{
|
|
804
|
+
tag: 'tag',
|
|
805
|
+
line: 2,
|
|
806
|
+
type: '',
|
|
807
|
+
name: 'name',
|
|
808
|
+
description: 'description same line',
|
|
809
|
+
source: '@tag name\ndescription same line',
|
|
810
|
+
optional: false
|
|
811
|
+
}]
|
|
812
|
+
})
|
|
813
|
+
})
|
|
814
|
+
|
|
815
|
+
it('should parse multiline without star as same line respecting `opts.join = "\\t"`', function () {
|
|
816
|
+
expect(parse(function () {
|
|
817
|
+
/**
|
|
818
|
+
* @tag name
|
|
819
|
+
* description
|
|
820
|
+
same line
|
|
821
|
+
*/
|
|
822
|
+
}, {
|
|
823
|
+
join: '\t'
|
|
824
|
+
})[0])
|
|
825
|
+
.to.eql({
|
|
826
|
+
line: 1,
|
|
827
|
+
description: '',
|
|
828
|
+
source: '@tag name\ndescription\nsame line',
|
|
829
|
+
tags: [{
|
|
830
|
+
tag: 'tag',
|
|
831
|
+
line: 2,
|
|
832
|
+
type: '',
|
|
833
|
+
name: 'name',
|
|
834
|
+
description: 'description\tsame line',
|
|
835
|
+
source: '@tag name\ndescription\tsame line',
|
|
836
|
+
optional: false
|
|
837
|
+
}]
|
|
838
|
+
})
|
|
839
|
+
})
|
|
840
|
+
|
|
841
|
+
it('should parse multiline without star as same line with intent respecting `opts.join = 1` and `opts.trim = false`', function () {
|
|
842
|
+
expect(parse(function () {
|
|
843
|
+
/**
|
|
844
|
+
* @tag name
|
|
845
|
+
* description
|
|
846
|
+
intent same line
|
|
847
|
+
*/
|
|
848
|
+
}, {
|
|
849
|
+
join: 1,
|
|
850
|
+
trim: false
|
|
851
|
+
})[0])
|
|
852
|
+
.to.eql({
|
|
853
|
+
line: 1,
|
|
854
|
+
description: '',
|
|
855
|
+
source: '\n@tag name\ndescription\n intent same line\n',
|
|
603
856
|
tags: [{
|
|
604
|
-
tag
|
|
605
|
-
line
|
|
606
|
-
type
|
|
607
|
-
name
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
857
|
+
tag: 'tag',
|
|
858
|
+
line: 2,
|
|
859
|
+
type: '',
|
|
860
|
+
name: 'name',
|
|
861
|
+
description: 'description intent same line\n',
|
|
862
|
+
source: '@tag name\ndescription intent same line\n',
|
|
863
|
+
optional: false
|
|
611
864
|
}]
|
|
612
|
-
})
|
|
613
|
-
})
|
|
614
|
-
})
|
|
865
|
+
})
|
|
866
|
+
})
|
|
867
|
+
})
|