comment-parser 0.2.4 → 0.3.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.
@@ -1,154 +0,0 @@
1
- var fs = require('fs');
2
- var expect = require('chai').expect;
3
- var parse = require('../index');
4
-
5
- describe('Single comment string parsing', function() {
6
-
7
- function parsed(func, opts) {
8
- opts = opts || {};
9
- opts.raw_value = true;
10
- var str = func.toString();
11
- return parse(str.slice(
12
- str.indexOf('{') + 1,
13
- str.lastIndexOf('}')
14
- ).trim(), opts);
15
- }
16
-
17
- it('should return `@tag`', function() {
18
- expect(parsed(function(){
19
- /**
20
- * @my-tag
21
- */
22
- var a;
23
- })[0].tags[0].value)
24
- .to.eq('@my-tag');
25
- });
26
-
27
- it('should return `@tag {my.type}`', function() {
28
- expect(parsed(function(){
29
- /**
30
- * @my-tag {my.type}
31
- */
32
- var a;
33
- })[0].tags[0].value)
34
- .to.eq('@my-tag {my.type}');
35
- });
36
-
37
- it('should return `@tag {my.type} name`', function() {
38
- expect(parsed(function(){
39
- /**
40
- * @my-tag {my.type} name
41
- */
42
- var a;
43
- })[0].tags[0].value)
44
- .to.eq('@my-tag {my.type} name');
45
- });
46
-
47
- it('should return `@tag name`', function() {
48
- expect(parsed(function(){
49
- /**
50
- * @my-tag name
51
- */
52
- })[0].tags[0].value)
53
- .to.eq('@my-tag name');
54
- });
55
-
56
- it('should return `@tag {my.type} [name]`', function() {
57
- expect(parsed(function(){
58
- /**
59
- * @my-tag {my.type} [name]
60
- */
61
- })[0].tags[0].value)
62
- .to.eq('@my-tag {my.type} [name]');
63
- });
64
-
65
- it('should parse `@tag {my.type} [name=value]` and return value', function() {
66
- expect(parsed(function(){
67
- /**
68
- * @my-tag {my.type} [name=value]
69
- */
70
- })[0])
71
- .to.eql({
72
- description : '',
73
- line : 0,
74
- tags : [{
75
- tag : 'my-tag',
76
- type : 'my.type',
77
- name : 'name',
78
- description : '',
79
- optional : true,
80
- default : 'value',
81
- line : 1,
82
- value : '@my-tag {my.type} [name=value]'
83
- }]
84
- });
85
- });
86
-
87
- it('should parse multiple tags and set raw value for them', function() {
88
- expect(parsed(function(){
89
- /**
90
- * Description
91
- * @my-tag1
92
- * @my-tag2
93
- */
94
- })[0])
95
- .to.eql({
96
- description : 'Description',
97
- line : 1,
98
- tags : [{
99
- tag : 'my-tag1',
100
- type : '',
101
- name : '',
102
- description : '',
103
- line : 2,
104
- value : '@my-tag1'
105
- }, {
106
- tag : 'my-tag2',
107
- type : '',
108
- name : '',
109
- description : '',
110
- line : 3,
111
- value : '@my-tag2'
112
- }]
113
- });
114
- });
115
-
116
- it('should parse nested tags and return raw values', function() {
117
- expect(parsed(function(){
118
- /**
119
- * Description
120
- * @my-tag name
121
- * @my-tag name.sub-name
122
- * @my-tag name.sub-name.sub-sub-name
123
- */
124
- }, {dotted_names: true})[0])
125
- .to.eql({
126
- description : 'Description',
127
- line : 1,
128
- tags : [{
129
- tag : 'my-tag',
130
- type : '',
131
- name : 'name',
132
- description : '',
133
- line : 2,
134
- value : '@my-tag name',
135
- tags : [{
136
- tag : 'my-tag',
137
- type : '',
138
- name : 'sub-name',
139
- description : '',
140
- line : 3,
141
- value : '@my-tag name.sub-name',
142
- tags : [{
143
- tag : 'my-tag',
144
- type : '',
145
- name : 'sub-sub-name',
146
- description : '',
147
- line : 4,
148
- value : '@my-tag name.sub-name.sub-sub-name'
149
- }]
150
- }]
151
- }]
152
- });
153
- });
154
- });
@@ -1,190 +0,0 @@
1
- var fs = require('fs');
2
- var expect = require('chai').expect;
3
- var parse = require('../index');
4
-
5
- describe('Single comment string parsing', function() {
6
-
7
- function parsed(func, opts) {
8
- opts = opts || {};
9
- var str = func.toString();
10
- return parse(str.slice(
11
- str.indexOf('{') + 1,
12
- str.lastIndexOf('}')
13
- ).trim(), opts);
14
- }
15
-
16
- it('should locate description', function() {
17
- expect(parsed(function(){
18
- /**
19
- * Description first line
20
- *
21
- * Description second line
22
- */
23
- var a;
24
- })[0].line)
25
- .to.eq(1);
26
- });
27
-
28
- it('should locate omitted description as 1', function() {
29
- expect(parsed(function(){
30
- /**
31
- *
32
- */
33
- var a;
34
- })[0].line)
35
- .to.eq(1);
36
- });
37
-
38
- it('should locate multiple comments separately', function() {
39
- var p = parsed(function(){
40
- /**
41
- * Description first line :1
42
- */
43
- var a;
44
-
45
- /**
46
- * Description second line :6
47
- * @tag :7
48
- */
49
- var b;
50
-
51
- /** Description third line :11 */
52
- var c;
53
-
54
- /**
55
- * Description second line :15
56
- * @tag :16
57
- */
58
- var d;
59
- });
60
-
61
- expect(p.length)
62
- .to.eq(4);
63
-
64
- expect(p[0].line)
65
- .to.eq(1);
66
-
67
- expect(p[1].line)
68
- .to.eq(6);
69
-
70
- expect(p[1].tags[0].line)
71
- .to.eq(7);
72
-
73
- expect(p[2].line)
74
- .to.eq(11);
75
-
76
- expect(p[3].line)
77
- .to.eq(15);
78
-
79
- expect(p[3].tags[0].line)
80
- .to.eq(16);
81
- });
82
-
83
- it('should locate parsed `@tag {my.type} [name=value]`', function() {
84
- expect(parsed(function(){
85
- /**
86
- * @my-tag {my.type} [name=value]
87
- */
88
- })[0].tags[0].line)
89
- .to.eq(1);
90
- });
91
-
92
- it('should locate parsed multiple tags', function() {
93
- expect(parsed(function(){
94
- /**
95
- * Description
96
- * @my-tag1
97
- * @my-tag2
98
- */
99
- })[0])
100
- .to.eql({
101
- description : 'Description',
102
- line : 1,
103
- tags : [{
104
- tag : 'my-tag1',
105
- type : '',
106
- name : '',
107
- description : '',
108
- line : 2
109
- }, {
110
- tag : 'my-tag2',
111
- type : '',
112
- name : '',
113
- description : '',
114
- line : 3
115
- }]
116
- });
117
- });
118
-
119
- it('should locate parsed nested tags', function() {
120
- expect(parsed(function(){
121
- /**
122
- * Description
123
- * @my-tag name
124
- * @my-tag name.sub-name
125
- * @my-tag name.sub-name.sub-sub-name
126
- */
127
- })[0])
128
- .to.eql({
129
- description : 'Description',
130
- line : 1,
131
- tags : [{
132
- tag : 'my-tag',
133
- type : '',
134
- name : 'name',
135
- description : '',
136
- line : 2
137
- }, {
138
- tag : 'my-tag',
139
- type : '',
140
- name : 'name.sub-name',
141
- description : '',
142
- line : 3,
143
- }, {
144
- tag : 'my-tag',
145
- type : '',
146
- name : 'name.sub-name.sub-sub-name',
147
- description : '',
148
- line : 4
149
- }]
150
- });
151
- });
152
-
153
-
154
- it('should locate nested tags', function() {
155
- expect(parsed(function(){
156
- /**
157
- * Description
158
- * @my-tag name
159
- * @my-tag name.sub-name
160
- * @my-tag name.sub-name.sub-sub-name
161
- */
162
- }, {dotted_names: true})[0])
163
- .to.eql({
164
- description : 'Description',
165
- line : 1,
166
- tags : [{
167
- tag : 'my-tag',
168
- type : '',
169
- name : 'name',
170
- description : '',
171
- line : 2,
172
- tags : [{
173
- tag : 'my-tag',
174
- type : '',
175
- name : 'sub-name',
176
- description : '',
177
- line : 3,
178
- tags : [{
179
- tag : 'my-tag',
180
- type : '',
181
- name : 'sub-sub-name',
182
- description : '',
183
- line : 4
184
- }]
185
- }]
186
- }]
187
- });
188
- });
189
-
190
- });