tomparse 0.4.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.
- data/.index +2 -3
- data/HISTORY.md +11 -1
- data/lib/tomparse.yml +2 -3
- data/lib/tomparse/argument.rb +22 -3
- data/lib/tomparse/parser.rb +6 -4
- data/test/test_arguments.rb +217 -0
- metadata +4 -2
data/.index
CHANGED
@@ -3,7 +3,6 @@ revision: 2013
|
|
3
3
|
type: ruby
|
4
4
|
sources:
|
5
5
|
- var
|
6
|
-
- VERSION
|
7
6
|
authors:
|
8
7
|
- name: trans
|
9
8
|
email: transfire@gmail.com
|
@@ -58,11 +57,11 @@ paths:
|
|
58
57
|
created: '2012-03-04'
|
59
58
|
summary: TomDoc parser for Ruby
|
60
59
|
title: TomParse
|
60
|
+
version: 0.4.2
|
61
61
|
name: tomparse
|
62
62
|
description: ! 'TomParse provides no other functionality than to take a code comment
|
63
63
|
|
64
64
|
and parse it in to a convenient object-oriented structure in accordance
|
65
65
|
|
66
66
|
with TomDoc standard.'
|
67
|
-
|
68
|
-
date: '2013-02-14'
|
67
|
+
date: '2013-02-15'
|
data/HISTORY.md
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
## 0.4.2 / 2013-02-15
|
4
|
+
|
5
|
+
This release fixes description and argument parsing when
|
6
|
+
a visibility indicator is used.
|
7
|
+
|
8
|
+
Changes:
|
9
|
+
|
10
|
+
* Fix desc/arguments parsing given indicator.
|
11
|
+
|
12
|
+
|
3
13
|
## 0.4.1 / 2013-02-14
|
4
14
|
|
5
|
-
This release fixes
|
15
|
+
This release fixes example parsing.
|
6
16
|
|
7
17
|
Changes:
|
8
18
|
|
data/lib/tomparse.yml
CHANGED
@@ -3,7 +3,6 @@ revision: 2013
|
|
3
3
|
type: ruby
|
4
4
|
sources:
|
5
5
|
- var
|
6
|
-
- VERSION
|
7
6
|
authors:
|
8
7
|
- name: trans
|
9
8
|
email: transfire@gmail.com
|
@@ -58,11 +57,11 @@ paths:
|
|
58
57
|
created: '2012-03-04'
|
59
58
|
summary: TomDoc parser for Ruby
|
60
59
|
title: TomParse
|
60
|
+
version: 0.4.2
|
61
61
|
name: tomparse
|
62
62
|
description: ! 'TomParse provides no other functionality than to take a code comment
|
63
63
|
|
64
64
|
and parse it in to a convenient object-oriented structure in accordance
|
65
65
|
|
66
66
|
with TomDoc standard.'
|
67
|
-
|
68
|
-
date: '2013-02-14'
|
67
|
+
date: '2013-02-15'
|
data/lib/tomparse/argument.rb
CHANGED
@@ -2,6 +2,8 @@ module TomParse
|
|
2
2
|
|
3
3
|
# Encapsulate a method argument.
|
4
4
|
#
|
5
|
+
# TODO: Does not yet support default parameter.
|
6
|
+
#
|
5
7
|
class Argument
|
6
8
|
|
7
9
|
attr_accessor :name
|
@@ -24,7 +26,7 @@ module TomParse
|
|
24
26
|
#
|
25
27
|
# Returns Boolean.
|
26
28
|
def optional?
|
27
|
-
@
|
29
|
+
@optional
|
28
30
|
end
|
29
31
|
|
30
32
|
# Parse arguments section. Arguments occur subsequent to
|
@@ -60,8 +62,25 @@ module TomParse
|
|
60
62
|
last_indent = indent
|
61
63
|
end
|
62
64
|
|
63
|
-
|
64
|
-
@
|
65
|
+
# Look for `(optional)` at end of description. If found, mark argument
|
66
|
+
# as @optional and remove from description.
|
67
|
+
#if md = /(\(optional\)\s*)(?:\[|\.\Z|\Z)/.match(desc.last)
|
68
|
+
# @optional = true
|
69
|
+
# desc.last[*md.offset(1)] = ''
|
70
|
+
#end
|
71
|
+
|
72
|
+
# Join the desc lines back together and ensure no extraneous whitespace.
|
73
|
+
text = desc.join.strip
|
74
|
+
|
75
|
+
# If the description contains the word "optional" the argument is taken
|
76
|
+
# to be optional. Note, I think this probably should be `(optional)` to
|
77
|
+
# prevent false positives, but the spec suggests otherwise.
|
78
|
+
if /\boptional\b/ =~ text
|
79
|
+
@optional = true
|
80
|
+
end
|
81
|
+
|
82
|
+
@description = text
|
83
|
+
@options = opts
|
65
84
|
end
|
66
85
|
|
67
86
|
end
|
data/lib/tomparse/parser.rb
CHANGED
@@ -365,6 +365,8 @@ module TomParse
|
|
365
365
|
end
|
366
366
|
|
367
367
|
# Split the documentation up into proper sections.
|
368
|
+
# The method works by building up a list of linenos
|
369
|
+
# of where each section begins.
|
368
370
|
#
|
369
371
|
# Returns an array section strings. [Array<String>]
|
370
372
|
def smart_split(doc)
|
@@ -379,11 +381,11 @@ module TomParse
|
|
379
381
|
# Keep a copy of the lines for later use.
|
380
382
|
doc_lines = lines.dup
|
381
383
|
|
384
|
+
|
382
385
|
# The first line may have a `Public`/`Private`/`Deprecated` marker.
|
383
|
-
#
|
384
|
-
|
385
|
-
|
386
|
-
#lines.first.sub(/^[A-Z]\w+\:\s*/, '')
|
386
|
+
# So we just skip the first line.
|
387
|
+
lines.shift
|
388
|
+
index += 1
|
387
389
|
|
388
390
|
# The description is always the first section, but it may have
|
389
391
|
# multiple paragraphs. And the second section may be an arguments
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
testcase "Arguments" do
|
4
|
+
|
5
|
+
context "single line argument without heading" do
|
6
|
+
setup do
|
7
|
+
@comment = TomParse::TomDoc.new %{
|
8
|
+
# Duplicate some text an abitrary number of times.
|
9
|
+
#
|
10
|
+
# text - The String to be duplicated.
|
11
|
+
#
|
12
|
+
# Returns the duplicated String when the count is > 1.
|
13
|
+
}
|
14
|
+
end
|
15
|
+
test "knows args size" do
|
16
|
+
@comment.args.size.assert == 1
|
17
|
+
end
|
18
|
+
test "knows args name" do
|
19
|
+
@comment.args.first.name.assert == :text
|
20
|
+
end
|
21
|
+
test "knows args description" do
|
22
|
+
@comment.args.first.description.assert == "The String to be duplicated."
|
23
|
+
end
|
24
|
+
test "knows args optionality" do
|
25
|
+
@comment.args.first.refute.optional?
|
26
|
+
end
|
27
|
+
test "know description" do
|
28
|
+
@comment.description == "Duplicate some text an abitrary number of times."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "multi-line argument without heading" do
|
33
|
+
setup do
|
34
|
+
@comment = TomParse::TomDoc.new %{
|
35
|
+
# Duplicate some text an abitrary number of times.
|
36
|
+
#
|
37
|
+
# text - The String to be duplicated.
|
38
|
+
# And its description continues.
|
39
|
+
#
|
40
|
+
# Returns the duplicated String when the count is > 1.
|
41
|
+
}
|
42
|
+
end
|
43
|
+
test "knows args size" do
|
44
|
+
@comment.args.size.assert == 1
|
45
|
+
end
|
46
|
+
test "knows args name" do
|
47
|
+
@comment.args.first.name.assert == :text
|
48
|
+
end
|
49
|
+
test "knows args description" do
|
50
|
+
@comment.args.first.description.assert == "The String to be duplicated. And its description continues."
|
51
|
+
end
|
52
|
+
test "knows args optionality" do
|
53
|
+
@comment.args.first.refute.optional?
|
54
|
+
end
|
55
|
+
test "know description" do
|
56
|
+
@comment.description == "Duplicate some text an abitrary number of times."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "multiple arguments without heading" do
|
61
|
+
setup do
|
62
|
+
@comment = TomParse::TomDoc.new %{
|
63
|
+
# Duplicate some text an abitrary number of times.
|
64
|
+
#
|
65
|
+
# text - The String to be duplicated.
|
66
|
+
# And its description continues.
|
67
|
+
# num - The Number to be duplicated.
|
68
|
+
# And it continues too. (optional)
|
69
|
+
#
|
70
|
+
# Returns the duplicated String when the count is > 1.
|
71
|
+
}
|
72
|
+
end
|
73
|
+
test "knows args size" do
|
74
|
+
@comment.args.size.assert == 2
|
75
|
+
end
|
76
|
+
test "knows args name" do
|
77
|
+
@comment.args[0].name.assert == :text
|
78
|
+
@comment.args[1].name.assert == :num
|
79
|
+
end
|
80
|
+
test "knows args description" do
|
81
|
+
@comment.args[0].description.assert == "The String to be duplicated. And its description continues."
|
82
|
+
@comment.args[1].description.assert == "The Number to be duplicated. And it continues too. (optional)"
|
83
|
+
end
|
84
|
+
test "knows args optionality" do
|
85
|
+
@comment.args[0].refute.optional?
|
86
|
+
@comment.args[1].assert.optional?
|
87
|
+
end
|
88
|
+
test "know description" do
|
89
|
+
@comment.description == "Duplicate some text an abitrary number of times."
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "single line argument with heading" do
|
94
|
+
setup do
|
95
|
+
@comment = TomParse::TomDoc.new %{
|
96
|
+
# Duplicate some text an abitrary number of times.
|
97
|
+
#
|
98
|
+
# Arguments
|
99
|
+
# text - The String to be duplicated.
|
100
|
+
#
|
101
|
+
# Returns the duplicated String when the count is > 1.
|
102
|
+
}
|
103
|
+
end
|
104
|
+
test "knows args size" do
|
105
|
+
@comment.args.size.assert == 1
|
106
|
+
end
|
107
|
+
test "knows args name" do
|
108
|
+
@comment.args.first.name.assert == :text
|
109
|
+
end
|
110
|
+
test "knows args description" do
|
111
|
+
@comment.args.first.description.assert == "The String to be duplicated."
|
112
|
+
end
|
113
|
+
test "knows args optionality" do
|
114
|
+
@comment.args.first.refute.optional?
|
115
|
+
end
|
116
|
+
test "know description" do
|
117
|
+
@comment.description == "Duplicate some text an abitrary number of times."
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "multi-line argument with heading" do
|
122
|
+
setup do
|
123
|
+
@comment = TomParse::TomDoc.new %{
|
124
|
+
# Duplicate some text an abitrary number of times.
|
125
|
+
#
|
126
|
+
# Arguments
|
127
|
+
# text - The String to be duplicated.
|
128
|
+
# And its description continues.
|
129
|
+
#
|
130
|
+
# Returns the duplicated String when the count is > 1.
|
131
|
+
}
|
132
|
+
end
|
133
|
+
test "knows args size" do
|
134
|
+
@comment.args.size.assert == 1
|
135
|
+
end
|
136
|
+
test "knows args name" do
|
137
|
+
@comment.args.first.name.assert == :text
|
138
|
+
end
|
139
|
+
test "knows args description" do
|
140
|
+
@comment.args.first.description.assert == "The String to be duplicated. And its description continues."
|
141
|
+
end
|
142
|
+
test "knows args optionality" do
|
143
|
+
@comment.args.first.refute.optional?
|
144
|
+
end
|
145
|
+
test "know description" do
|
146
|
+
@comment.description == "Duplicate some text an abitrary number of times."
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "multiple arguments without heading" do
|
151
|
+
setup do
|
152
|
+
@comment = TomParse::TomDoc.new %{
|
153
|
+
# Duplicate some text an abitrary number of times.
|
154
|
+
#
|
155
|
+
# Arguments
|
156
|
+
# text - The String to be duplicated.
|
157
|
+
# And its description continues.
|
158
|
+
# num - The Number to be duplicated.
|
159
|
+
# And it continues too. (optional)
|
160
|
+
#
|
161
|
+
# Returns the duplicated String when the count is > 1.
|
162
|
+
}
|
163
|
+
end
|
164
|
+
test "knows args size" do
|
165
|
+
@comment.args.size.assert == 2
|
166
|
+
end
|
167
|
+
test "knows args name" do
|
168
|
+
@comment.args[0].name.assert == :text
|
169
|
+
@comment.args[1].name.assert == :num
|
170
|
+
end
|
171
|
+
test "knows args description" do
|
172
|
+
@comment.args[0].description.assert == "The String to be duplicated. And its description continues."
|
173
|
+
@comment.args[1].description.assert == "The Number to be duplicated. And it continues too. (optional)"
|
174
|
+
end
|
175
|
+
test "knows args optionality" do
|
176
|
+
@comment.args[0].refute.optional?
|
177
|
+
@comment.args[1].assert.optional?
|
178
|
+
end
|
179
|
+
test "know description" do
|
180
|
+
@comment.description == "Duplicate some text an abitrary number of times."
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when description has visibility indicator" do
|
185
|
+
setup do
|
186
|
+
@comment = TomParse::TomDoc.new %{
|
187
|
+
# Public: Duplicate some text an abitrary number of times.
|
188
|
+
#
|
189
|
+
# text - The String to be duplicated.
|
190
|
+
# And its description continues.
|
191
|
+
# num - The Number to be duplicated.
|
192
|
+
# And it continues too.
|
193
|
+
#
|
194
|
+
# Returns the duplicated String when the count is > 1.
|
195
|
+
}
|
196
|
+
end
|
197
|
+
test "knows args size" do
|
198
|
+
@comment.args.size.assert == 2
|
199
|
+
end
|
200
|
+
test "knows args name" do
|
201
|
+
@comment.args[0].name.assert == :text
|
202
|
+
@comment.args[1].name.assert == :num
|
203
|
+
end
|
204
|
+
test "knows args description" do
|
205
|
+
@comment.args[0].description.assert == "The String to be duplicated. And its description continues."
|
206
|
+
@comment.args[1].description.assert == "The Number to be duplicated. And it continues too."
|
207
|
+
end
|
208
|
+
test "knows args optionality" do
|
209
|
+
@comment.args[0].refute.optional?
|
210
|
+
@comment.args[1].refute.optional?
|
211
|
+
end
|
212
|
+
test "know description" do
|
213
|
+
@comment.description == "Duplicate some text an abitrary number of times."
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomparse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: citron
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/tomparse.rb
|
83
83
|
- lib/tomparse.yml
|
84
84
|
- test/helper.rb
|
85
|
+
- test/test_arguments.rb
|
85
86
|
- test/test_description.rb
|
86
87
|
- test/test_examples.rb
|
87
88
|
- test/test_prefixes.rb
|
@@ -126,4 +127,5 @@ test_files:
|
|
126
127
|
- test/test_tags.rb
|
127
128
|
- test/test_tomdoc.rb
|
128
129
|
- test/test_prefixes.rb
|
130
|
+
- test/test_arguments.rb
|
129
131
|
has_rdoc:
|