inch 0.5.0.rc2 → 0.5.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cbc0d4c804e51d845b747f3e98dbb627e4cc03d
4
- data.tar.gz: 19b9076a8005cafc3e80c8f73fb906710c9277e9
3
+ metadata.gz: ad7ddc303f887e07ca647f76f002aafed4dc120e
4
+ data.tar.gz: 7c0c21ee7be201462be99951d70c7544e9a4bc52
5
5
  SHA512:
6
- metadata.gz: 74beefa52167ddb75d108ecc78c0cf3401cae9534796778fcfa12564a1f47dc86e87a5951a241134df1d8a00dd32b6be49667e55f341be8613a7028a8b221a31
7
- data.tar.gz: 71546c69d7edf6e0ed626c448bba5ab263d98d7e5358f3cdd8ccafa40d1acdfc9da136e46f8d06443a74cc7d018650f3012df5b1b9a5f917960ef3f294f7d8ac
6
+ metadata.gz: 582a2edf65d9d3d3bd8c95ffee5c55d94a07718a2cc94bcc9c594ffe2b106ed616755d15710ef575cdd312963e54cdd92893955d0c178eeb90a7c35940003f3c
7
+ data.tar.gz: b97da1277e2c3b2644ca49250288ff9031a4fee69463b11cbae485739d6aededf536f02e7892ed365d87067ffccc2c99a63eb97baf97d838a85429333a7b4924
data/config/defaults.rb CHANGED
@@ -64,6 +64,13 @@ Inch::Config.run do
64
64
  unconsidered_tag 0.2
65
65
  end
66
66
 
67
+ schema(:ClassVariableObject) do
68
+ docstring 1.0
69
+
70
+ # optional:
71
+ unconsidered_tag 0.2
72
+ end
73
+
67
74
  schema(:ClassObject) do
68
75
  docstring 1.0
69
76
 
@@ -42,11 +42,12 @@ module Inch
42
42
  end
43
43
 
44
44
  def mentions_return?
45
- last_line =~ /^Returns\ /
45
+ last_line =~ /^#{tomdoc_modifiers}Returns\ /
46
46
  end
47
47
 
48
48
  def describes_return?
49
- last_line =~ /^Returns\ (\w+\s){2,}/
49
+ last_line =~ /^#{tomdoc_modifiers}Returns\ (\w+\s){2,}/i ||
50
+ last_line =~ /^#{tomdoc_modifiers}Returns\ (nil|nothing)\.*/i
50
51
  end
51
52
 
52
53
  def to_s
@@ -121,6 +122,10 @@ module Inch
121
122
  end
122
123
  end
123
124
  end
125
+
126
+ def tomdoc_modifiers
127
+ /((Public|Private|Internal)\:\ )*/
128
+ end
124
129
  end
125
130
  end
126
131
  end
@@ -53,6 +53,7 @@ end
53
53
  require 'inch/code_object/provider/yard/object/base'
54
54
  require 'inch/code_object/provider/yard/object/namespace_object'
55
55
  require 'inch/code_object/provider/yard/object/class_object'
56
+ require 'inch/code_object/provider/yard/object/class_variable_object'
56
57
  require 'inch/code_object/provider/yard/object/constant_object'
57
58
  require 'inch/code_object/provider/yard/object/method_object'
58
59
  require 'inch/code_object/provider/yard/object/method_parameter_object'
@@ -0,0 +1,12 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ class ClassVariableObject < Base
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -32,6 +32,7 @@ end
32
32
  require 'inch/code_object/proxy/base'
33
33
  require 'inch/code_object/proxy/namespace_object'
34
34
  require 'inch/code_object/proxy/class_object'
35
+ require 'inch/code_object/proxy/class_variable_object'
35
36
  require 'inch/code_object/proxy/constant_object'
36
37
  require 'inch/code_object/proxy/method_object'
37
38
  require 'inch/code_object/proxy/method_parameter_object'
@@ -0,0 +1,8 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Proxy
4
+ class ClassVariableObject < Base
5
+ end
6
+ end
7
+ end
8
+ end
@@ -30,5 +30,6 @@ require 'inch/evaluation/role/method'
30
30
  require 'inch/evaluation/role/method_parameter'
31
31
  require 'inch/evaluation/role/namespace'
32
32
  require 'inch/evaluation/role/constant'
33
+ require 'inch/evaluation/role/class_variable'
33
34
 
34
35
  require 'inch/evaluation/proxy'
@@ -20,6 +20,7 @@ end
20
20
  require 'inch/evaluation/proxy/base'
21
21
  require 'inch/evaluation/proxy/namespace_object'
22
22
  require 'inch/evaluation/proxy/class_object'
23
+ require 'inch/evaluation/proxy/class_variable_object'
23
24
  require 'inch/evaluation/proxy/constant_object'
24
25
  require 'inch/evaluation/proxy/method_object'
25
26
  require 'inch/evaluation/proxy/module_object'
@@ -0,0 +1,19 @@
1
+ module Inch
2
+ module Evaluation
3
+ module Proxy
4
+ class ClassVariableObject < Base
5
+ protected
6
+
7
+ def relevant_roles
8
+ {
9
+ Role::ClassVariable::WithDoc => score_for(:docstring),
10
+ Role::ClassVariable::WithoutDoc => score_for(:docstring),
11
+ Role::ClassVariable::TaggedAsNodoc => nil,
12
+ Role::ClassVariable::Public => nil,
13
+ Role::ClassVariable::Private => nil,
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ module Inch
2
+ module Evaluation
3
+ module Role
4
+ # Roles assigned to class variables
5
+ module ClassVariable
6
+ class WithDoc < Object::WithDoc
7
+ applicable_if :has_doc?
8
+ end
9
+ class WithoutDoc < Object::WithoutDoc
10
+ applicable_unless :has_doc?
11
+ end
12
+
13
+ class TaggedAsNodoc < Object::TaggedAsNodoc
14
+ applicable_if :nodoc?
15
+ end
16
+ class InRoot < Object::InRoot
17
+ applicable_if :in_root?
18
+ end
19
+
20
+ class Public < Object::Public
21
+ applicable_if :public?
22
+
23
+ def priority
24
+ -1
25
+ end
26
+ end
27
+ class Private < Object::Private
28
+ applicable_if :private?
29
+
30
+ def priority
31
+ -3
32
+ end
33
+ end
34
+
35
+ class WithCodeExample < Object::WithCodeExample
36
+ applicable_if do |o|
37
+ o.has_code_example? && !o.has_multiple_code_examples?
38
+ end
39
+ end
40
+
41
+ class WithMultipleCodeExamples < Object::WithMultipleCodeExamples
42
+ applicable_if :has_multiple_code_examples?
43
+ end
44
+
45
+ class WithoutCodeExample < Object::WithoutCodeExample
46
+ applicable_unless :has_code_example?
47
+
48
+ def suggestion
49
+ nil
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/inch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Inch
2
- VERSION = "0.5.0.rc2"
2
+ VERSION = "0.5.0.rc3"
3
3
  end
@@ -1,4 +1,7 @@
1
1
  module Foo
2
+ # Determines :class_variable
3
+ @@class_variable = {Ace: 11, Jack: 10, Queen: 10, King: 10}
4
+
2
5
  # The problem here is that the @param tag is not given the name of the
3
6
  # parameter it documents.
4
7
  #
@@ -79,6 +79,48 @@ DOC
79
79
  assert docstring.describes_return?
80
80
  end
81
81
 
82
+ it "should understand 'Returns nil.'" do
83
+ text = <<-DOC
84
+ [...]
85
+ Returns nil.
86
+ DOC
87
+ docstring = described_class.new(text)
88
+ assert docstring.describes_return?
89
+ end
90
+
91
+ it "should understand 'Returns nil.' without fullstop and in lowercase" do
92
+ text = <<-DOC
93
+ [...]
94
+ returns nil
95
+ DOC
96
+ docstring = described_class.new(text)
97
+ assert docstring.describes_return?
98
+ end
99
+
100
+ it "should understand 'Returns nothing.'" do
101
+ text = <<-DOC
102
+ [...]
103
+ Returns nothing.
104
+ DOC
105
+ docstring = described_class.new(text)
106
+ assert docstring.describes_return?
107
+ end
108
+
109
+ it "should understand 'Returns nothing.' without fullstop and in lowercase" do
110
+ text = <<-DOC
111
+ [...]
112
+ returns nothing
113
+ DOC
114
+ docstring = described_class.new(text)
115
+ assert docstring.describes_return?
116
+ end
117
+
118
+ it "should understand 'Returns ...' with a visibility modifier in front of it" do
119
+ text = "Public: Returns the Integer color."
120
+ docstring = described_class.new(text)
121
+ assert docstring.mentions_return?
122
+ assert docstring.describes_return?
123
+ end
82
124
 
83
125
  #
84
126
  # PARAMETER MENTIONS
@@ -96,7 +138,7 @@ DOC
96
138
  end
97
139
 
98
140
 
99
- it "should work 2" do
141
+ it "should work 2 if correct" do
100
142
  text = <<-DOC
101
143
  Just because format is mentioned here, does not mean
102
144
  the first parameter is meant.
@@ -6,47 +6,55 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
6
6
  @objects = @codebase.objects
7
7
  end
8
8
 
9
- def test_transitive_tags_dont_matter
10
- m = @objects.find("InchTest::Deprecated::ClassMethods")
11
- assert_equal 0, m.score
12
- assert m.undocumented?
13
- end
9
+ describe "Scores" do
10
+ #
11
+ it "should not count tags that are transitive" do
12
+ m = @objects.find("InchTest::Deprecated::ClassMethods")
13
+ assert_equal 0, m.score
14
+ assert m.undocumented?
15
+ end
14
16
 
15
- def test_raising_method_with_comment
16
- m = @objects.find("InchTest#raising_method_with_comment")
17
- assert m.score > 0
18
- refute m.undocumented?
19
- end
17
+ it "counts a @raise tag" do
18
+ m = @objects.find("InchTest#raising_method_with_comment")
19
+ assert m.score > 0
20
+ refute m.undocumented?
21
+ end
20
22
 
21
- def test_raising_method
22
- m = @objects.find("InchTest#raising_method")
23
- assert_equal 0, m.score
24
- assert m.undocumented?
25
- end
23
+ it "should not count a call to `raise`" do
24
+ m = @objects.find("InchTest#raising_method")
25
+ assert_equal 0, m.score
26
+ assert m.undocumented?
27
+ end
26
28
 
27
- def test_yielding_method
28
- m = @objects.find("InchTest#yielding_method")
29
- assert_equal 0, m.score
30
- assert m.undocumented?
29
+ it "should not count a call to `yield`" do
30
+ m = @objects.find("InchTest#yielding_method")
31
+ assert_equal 0, m.score
32
+ assert m.undocumented?
33
+ end
31
34
  end
32
35
 
33
- def test_tagged_as_private
34
- %w( InchTest#method_with_private_tag
35
- InchTest#private_method_with_tomdoc).each do |fullname|
36
- m = @objects.find(fullname)
37
- assert m.tagged_as_private?
36
+ describe "Taggings" do
37
+ #
38
+ it "should recognize forms of @private-tags" do
39
+ %w( InchTest#method_with_private_tag
40
+ InchTest#private_method_with_tomdoc).each do |fullname|
41
+ m = @objects.find(fullname)
42
+ assert m.tagged_as_private?
43
+ end
38
44
  end
39
- end
40
45
 
41
- def test_tagged_as_internal_api
42
- %w( InchTest#private_api_with_yard
43
- InchTest#internal_api_with_tomdoc).each do |fullname|
44
- m = @objects.find(fullname)
45
- assert m.tagged_as_internal_api?
46
+ it "should recognize forms of internal-tags" do
47
+ # @api private in YARD
48
+ # Internal: in TomDoc
49
+ %w( InchTest#private_api_with_yard
50
+ InchTest#internal_api_with_tomdoc).each do |fullname|
51
+ m = @objects.find(fullname)
52
+ assert m.tagged_as_internal_api?
53
+ end
46
54
  end
47
55
  end
48
56
 
49
- def test_method_without_doc
57
+ it "should recognize undocumented methods without parameters" do
50
58
  m = @objects.find("Foo::Bar#method_without_doc")
51
59
  refute m.has_doc?
52
60
  refute m.has_parameters?
@@ -56,7 +64,7 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
56
64
  assert_equal 0, m.score
57
65
  end
58
66
 
59
- def test_method_with_missing_param_doc
67
+ it "should recognize missing parameter documentation" do
60
68
  m = @objects.find("Foo::Bar#method_with_missing_param_doc")
61
69
  assert m.has_doc?
62
70
  assert m.has_parameters?
@@ -67,327 +75,354 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
67
75
  assert p.mentioned?
68
76
  p = m.parameter(:param2)
69
77
  assert p.mentioned?
70
- p = m.parameter(:param3)
71
- refute p.mentioned?
72
-
73
- assert m.score
74
- end
75
78
 
76
- def test_method_with_wrong_doc
77
- m = @objects.find("Foo::Bar#method_with_wrong_doc")
78
- assert m.has_doc?
79
- assert m.has_parameters?
80
- assert m.return_mentioned?
81
-
82
- assert_equal 4, m.parameters.size
83
- p = m.parameter(:param1)
84
- assert p.mentioned? # mentioned in docs, correctly
85
- refute p.wrongly_mentioned?
86
- p = m.parameter(:param2)
87
- refute p.mentioned?
88
- refute p.wrongly_mentioned? # not mentioned in docs at all
79
+ # not mentioned
89
80
  p = m.parameter(:param3)
90
81
  refute p.mentioned?
91
- refute p.wrongly_mentioned? # not mentioned in docs at all
92
- p = m.parameter(:param4)
93
- assert p.mentioned?
94
- assert p.wrongly_mentioned? # mentioned in docs, but not present
95
82
 
96
83
  assert m.score
97
84
  end
98
85
 
99
- def test_method_with_full_doc
100
- m = @objects.find("Foo::Bar#method_with_full_doc")
101
- assert m.has_doc?
102
- assert m.has_parameters?
103
- assert m.return_mentioned?
86
+ describe "Documentation Styles" do
87
+ #
88
+ it "should handle YARD when no additional docstring is given" do
89
+ m = @objects.find("Foo::Bar#method_without_docstring")
90
+ refute m.has_doc?
91
+ assert m.has_parameters?
92
+ assert m.return_mentioned?
104
93
 
105
- assert_equal 2, m.parameters.size
106
- m.parameters.each do |param|
107
- assert param.mentioned?
108
- assert param.typed?
109
- assert param.described?
110
- refute param.wrongly_mentioned?
94
+ assert m.score
111
95
  end
112
96
 
113
- assert_equal 100, m.score
114
- end
97
+ it "should handle YARD when only @return is given" do
98
+ m = @objects.find("Foo::Bar#method_without_params_or_docstring")
99
+ refute m.has_doc?
100
+ refute m.has_parameters?
101
+ assert m.return_mentioned?
115
102
 
116
- def test_method_without_params_or_return_type
117
- m = @objects.find("Foo::Bar#method_without_params_or_return_type")
118
- assert m.has_doc?
119
- refute m.has_parameters?
120
- refute m.return_mentioned?
103
+ assert m.score
104
+ end
121
105
 
122
- assert m.score
123
- end
106
+ it "should handle RDoc" do
107
+ m = @objects.find("Foo::Bar#method_with_rdoc_doc")
108
+ assert m.has_doc?
109
+ assert m.has_parameters?
110
+ p = m.parameter(:param1)
111
+ assert p.mentioned? # mentioned in docs, correctly
112
+ refute m.return_mentioned?
124
113
 
125
- def test_method_without_docstring
126
- m = @objects.find("Foo::Bar#method_without_docstring")
127
- refute m.has_doc?
128
- assert m.has_parameters?
129
- assert m.return_mentioned?
114
+ assert m.score
115
+ end
130
116
 
131
- assert m.score
132
- end
117
+ it "should handle other RDoc styles" do
118
+ m = @objects.find("Foo::Bar#method_with_other_rdoc_doc")
119
+ assert m.has_doc?
120
+ assert m.has_parameters?
121
+ p = m.parameter(:param1)
122
+ assert p.mentioned? # mentioned in docs, correctly
123
+ p = m.parameter(:param2)
124
+ assert p.mentioned? # mentioned in docs, correctly
125
+ p = m.parameter(:param3)
126
+ assert p.mentioned? # mentioned in docs, correctly
127
+ refute m.return_mentioned?
128
+
129
+ assert m.score
130
+ end
133
131
 
134
- def test_method_without_params_or_docstring
135
- m = @objects.find("Foo::Bar#method_without_params_or_docstring")
136
- refute m.has_doc?
137
- refute m.has_parameters?
138
- assert m.return_mentioned?
132
+ it "should handle unstructured doc styles" do
133
+ m = @objects.find("Foo::Bar#method_with_unstructured_doc")
134
+ assert m.has_doc?
135
+ assert m.has_parameters?
136
+ p = m.parameter(:param1)
137
+ assert p.mentioned? # mentioned in docs, correctly
138
+ refute m.return_mentioned?
139
139
 
140
- assert m.score
141
- end
140
+ assert m.score
141
+ end
142
142
 
143
- def test_method_with_rdoc_doc
144
- m = @objects.find("Foo::Bar#method_with_rdoc_doc")
145
- assert m.has_doc?
146
- assert m.has_parameters?
147
- p = m.parameter(:param1)
148
- assert p.mentioned? # mentioned in docs, correctly
149
- refute m.return_mentioned?
143
+ it "should handle unstructured doc styles with an undocumented param" do
144
+ m = @objects.find("Foo::Bar#method_with_unstructured_doc_missing_params")
145
+ assert m.has_doc?
146
+ assert m.has_parameters?
147
+ p = m.parameter(:format)
148
+ refute p.mentioned? # mentioned in docs, correctly
149
+ refute m.return_mentioned?
150
150
 
151
- assert m.score
152
- end
151
+ assert m.score
152
+ end
153
153
 
154
- def test_method_with_other_rdoc_doc
155
- m = @objects.find("Foo::Bar#method_with_other_rdoc_doc")
156
- assert m.has_doc?
157
- assert m.has_parameters?
158
- p = m.parameter(:param1)
159
- assert p.mentioned? # mentioned in docs, correctly
160
- p = m.parameter(:param2)
161
- assert p.mentioned? # mentioned in docs, correctly
162
- p = m.parameter(:param3)
163
- assert p.mentioned? # mentioned in docs, correctly
164
- refute m.return_mentioned?
154
+ it "should handle methods (without parameters) that have only a docstring (text comment)" do
155
+ m = @objects.find("Foo::Bar#method_without_params_or_return_type")
156
+ assert m.has_doc?
157
+ refute m.has_parameters?
158
+ refute m.return_mentioned?
165
159
 
166
- assert m.score
160
+ assert m.score
161
+ end
167
162
  end
168
163
 
169
- def test_method_with_unstructured_doc
170
- m = @objects.find("Foo::Bar#method_with_unstructured_doc")
171
- assert m.has_doc?
172
- assert m.has_parameters?
173
- p = m.parameter(:param1)
174
- assert p.mentioned? # mentioned in docs, correctly
175
- refute m.return_mentioned?
164
+ describe "Getter/Setter Handling" do
176
165
 
177
- assert m.score
178
- end
166
+ it "should recognize a getter method" do
167
+ m = @objects.find("InchTest#getter")
168
+ assert m.getter?, "should be a getter"
169
+ refute m.setter?
170
+ refute m.has_doc?
171
+ assert_equal 0, m.score
172
+ end
179
173
 
180
- def test_method_with_unstructured_doc_missing_params
181
- m = @objects.find("Foo::Bar#method_with_unstructured_doc_missing_params")
182
- assert m.has_doc?
183
- assert m.has_parameters?
184
- p = m.parameter(:format)
185
- refute p.mentioned? # mentioned in docs, correctly
186
- refute m.return_mentioned?
174
+ it "should recognize a setter method" do
175
+ m = @objects.find("InchTest#attr_setter=")
176
+ refute m.getter?
177
+ assert m.setter?, "should be a setter"
178
+ refute m.has_doc?
179
+ assert_equal 0, m.score
180
+ end
187
181
 
188
- assert m.score
189
- end
182
+ it "should recognize a manually defined setter method" do
183
+ m = @objects.find("InchTest#manual_setter=")
184
+ refute m.getter?
185
+ assert m.setter?, "should be a setter"
186
+ refute m.has_doc?
187
+ assert_equal 0, m.score
188
+ end
190
189
 
191
- def test_question_mark_method
192
- m = @objects.find("InchTest#question_mark_method?")
193
- refute m.has_doc?
194
- refute m.has_parameters?
190
+ it "should recognize a getter in a manually defined getter/setter pair" do
191
+ m = @objects.find("InchTest#manual_getset")
192
+ assert m.getter?, "should be a getter"
193
+ refute m.setter?
194
+ refute m.has_doc?
195
+ assert_equal 0, m.score
196
+ end
195
197
 
196
- assert_equal 0, m.score
197
- end
198
+ it "should recognize a setter in a manually defined getter/setter pair" do
199
+ m = @objects.find("InchTest#manual_getset=")
200
+ refute m.getter?
201
+ assert m.setter?, "should be a setter"
202
+ refute m.has_doc?
203
+ assert_equal 0, m.score
204
+ end
198
205
 
199
- def test_question_mark_method_with_description
200
- m = @objects.find("InchTest#question_mark_method_with_description?")
201
- refute m.has_doc?
202
- refute m.has_parameters?
206
+ it "should recognize a getter in a getter/setter pair defined via attr_accessor" do
207
+ m = @objects.find("InchTest#attr_getset")
208
+ assert m.getter?, "should be a getter"
209
+ refute m.setter?
210
+ refute m.has_doc?
211
+ assert_equal 0, m.score
212
+ end
203
213
 
204
- assert m.score > 0
205
- assert m.score >= 50 # TODO: don't use magic numbers
206
- end
214
+ it "should recognize a setter in a getter/setter pair defined via attr_accessor" do
215
+ m = @objects.find("InchTest#attr_getset=")
216
+ refute m.getter?
217
+ assert m.setter?, "should be a setter"
218
+ refute m.has_doc?
219
+ assert_equal 0, m.score
220
+ end
207
221
 
208
- def test_method_with_description_and_parameters
209
- m = @objects.find("InchTest#method_with_description_and_parameters?")
210
- refute m.has_doc?
211
- assert m.has_parameters?
222
+ it "should recognize a getter in a getter/setter pair defined via Struct" do
223
+ m = @objects.find("InchTest::StructGetSet#struct_getset")
224
+ assert m.getter?, "should be a getter"
225
+ refute m.setter?
226
+ refute m.has_doc?
227
+ assert_equal 0, m.score
228
+ end
212
229
 
213
- assert m.score > 0
214
- end
230
+ it "should recognize a setter in a getter/setter pair defined via Struct" do
231
+ m = @objects.find("InchTest::StructGetSet#struct_getset=")
232
+ refute m.getter?
233
+ assert m.setter?, "should be a setter"
234
+ refute m.has_doc?
235
+ assert_equal 0, m.score
236
+ end
215
237
 
216
- def test_depth
217
- m = @objects.find("#root_method")
218
- assert_equal 1, m.depth
219
- m = @objects.find("InchTest#getter")
220
- assert_equal 2, m.depth
221
- m = @objects.find("Foo::Bar#method_without_doc")
222
- assert_equal 3, m.depth
223
- end
238
+ it "should recognize docs on a getter in a getter/setter pair defined via attr_accessor" do
239
+ m = @objects.find("Attributes#username")
240
+ refute_equal 0, m.score
241
+ refute m.undocumented?
242
+ end
224
243
 
225
- def test_getter
226
- m = @objects.find("InchTest#getter")
227
- assert m.getter?, "should be a getter"
228
- refute m.setter?
229
- refute m.has_doc?
230
- assert_equal 0, m.score
231
- end
244
+ it "should recognize docs on a setter in a getter/setter pair defined via attr_accessor" do
245
+ m = @objects.find("Attributes#username=")
246
+ refute_equal 0, m.score
247
+ refute m.undocumented?
248
+ end
232
249
 
233
- def test_setter
234
- m = @objects.find("InchTest#attr_setter=")
235
- refute m.getter?
236
- assert m.setter?, "should be a setter"
237
- refute m.has_doc?
238
- assert_equal 0, m.score
239
- end
250
+ it "should recognize splat parameter notation" do
251
+ # it should assign the same score whether the parameter is
252
+ # described with or without the splat (*) operator
253
+ m1 = @objects.find("Foo#method_with_splat_parameter")
254
+ m2 = @objects.find("Foo#method_with_splat_parameter2")
255
+ assert_equal 1, m1.parameters.size
256
+ assert_equal 1, m2.parameters.size
257
+ assert_equal m1.score, m2.score
258
+ end
240
259
 
241
- def test_setter2
242
- m = @objects.find("InchTest#manual_setter=")
243
- refute m.getter?
244
- assert m.setter?, "should be a setter"
245
- refute m.has_doc?
246
- assert_equal 0, m.score
260
+ it "should recognize alias methods and aliased methods" do
261
+ m1 = @objects.find("InchTest#_aliased_method")
262
+ m2 = @objects.find("InchTest#_alias_method")
263
+ assert_equal m1.score, m2.score
264
+ end
247
265
  end
248
266
 
249
- def test_manual_getset
250
- m = @objects.find("InchTest#manual_getset")
251
- assert m.getter?, "should be a getter"
252
- refute m.setter?
253
- refute m.has_doc?
254
- assert_equal 0, m.score
255
- end
267
+ describe "YARDs @!attribute directive on a class" do
268
+ #
269
+ it "should work as a reader" do
270
+ m = @objects.find("Attributes#email")
271
+ refute_equal 0, m.score
272
+ refute m.undocumented?
273
+ end
256
274
 
257
- def test_manual_getset2
258
- m = @objects.find("InchTest#manual_getset=")
259
- refute m.getter?
260
- assert m.setter?, "should be a setter"
261
- refute m.has_doc?
262
- assert_equal 0, m.score
275
+ it "should work as a writer" do
276
+ m = @objects.find("Attributes#email=")
277
+ refute_equal 0, m.score
278
+ #refute m.undocumented?
279
+ # NOTE: this is undocumented since there is no original_docstring
280
+ end
263
281
  end
264
282
 
265
- def test_attr_getset
266
- m = @objects.find("InchTest#attr_getset")
267
- assert m.getter?, "should be a getter"
268
- refute m.setter?
269
- refute m.has_doc?
270
- assert_equal 0, m.score
271
- end
283
+ describe "YARDs @overload tag on methods" do
284
+ #
285
+ it "should work with basic overloading" do
286
+ list = []
287
+ list << @objects.find("Overloading#rgb")
288
+ list << @objects.find("Overloading#rgba")
289
+ list << @objects.find("Overloading#change_color")
290
+ list << @objects.find("Overloading#mix")
291
+ list << @objects.find("Overloading#hooks")
292
+ list << @objects.find("Overloading#identifiers")
293
+ list << @objects.find("Overloading#params_only_in_overloads")
294
+ list.each do |m|
295
+ assert_equal 100, m.score, "#{m.fullname} did not get 100"
296
+ end
297
+ end
272
298
 
273
- def test_attr_getset2
274
- m = @objects.find("InchTest#attr_getset=")
275
- refute m.getter?
276
- assert m.setter?, "should be a setter"
277
- refute m.has_doc?
278
- assert_equal 0, m.score
279
- end
299
+ it "should work with a malformed @param tag in an overload tag" do
300
+ m = @objects.find("Overloading#missing_param_names")
301
+ refute m.has_doc? # it may be mentioned in the docs, but it's malformed.
302
+ end
280
303
 
281
- def test_struct_getset
282
- m = @objects.find("InchTest::StructGetSet#struct_getset")
283
- assert m.getter?, "should be a getter"
284
- refute m.setter?
285
- refute m.has_doc?
286
- assert_equal 0, m.score
287
- end
304
+ it "should work with several overload tags on the same method" do
305
+ m = @objects.find("Overloading#many_overloads")
306
+ assert_equal 1, count_roles(m, Inch::Evaluation::Role::Method::WithoutReturnDescription)
307
+ assert_equal 1, count_roles(m, Inch::Evaluation::Role::Method::WithoutReturnType)
308
+ assert_equal 1, count_roles(m, Inch::Evaluation::Role::MethodParameter::WithoutMention, 'block')
309
+ end
288
310
 
289
- def test_struct_getset2
290
- m = @objects.find("InchTest::StructGetSet#struct_getset=")
291
- refute m.getter?
292
- assert m.setter?, "should be a setter"
293
- refute m.has_doc?
294
- assert_equal 0, m.score
295
- end
311
+ it "should work if @param tags are only present in the @overload tags, but not on the actual method" do
312
+ m = @objects.find("Overloading#params_only_in_overloads")
313
+ unexpected_roles = [
314
+ Inch::Evaluation::Role::Object::WithoutCodeExample,
315
+ Inch::Evaluation::Role::MethodParameter::WithoutMention,
316
+ Inch::Evaluation::Role::MethodParameter::WithoutType,
317
+ ]
318
+ assert_roles m, [], unexpected_roles
319
+ end
296
320
 
297
- def test_splat_parameter_notation
298
- # it should assign the same score whether the parameter is
299
- # described with or without the splat (*) operator
300
- m1 = @objects.find("Foo#method_with_splat_parameter")
301
- m2 = @objects.find("Foo#method_with_splat_parameter2")
302
- assert_equal 1, m1.parameters.size
303
- assert_equal 1, m2.parameters.size
304
- assert_equal m1.score, m2.score
321
+ it "should work with one param missing in the overload tag" do
322
+ m = @objects.find("Overloading#one_param_missing_in_overload")
323
+ unexpected_roles = [
324
+ Inch::Evaluation::Role::Object::WithoutCodeExample,
325
+ ]
326
+ expected_roles = [
327
+ Inch::Evaluation::Role::MethodParameter::WithoutMention,
328
+ Inch::Evaluation::Role::MethodParameter::WithoutType,
329
+ ]
330
+ assert_roles m, expected_roles, unexpected_roles
331
+ end
305
332
  end
306
333
 
307
- def test_alias_method
308
- m1 = @objects.find("InchTest#_aliased_method")
309
- m2 = @objects.find("InchTest#_alias_method")
310
- assert_equal m1.score, m2.score
311
- end
334
+ describe "MISC" do
335
+ #
336
+ it "should recognize named parameters in Ruby 2.1" do
337
+ m = @objects.find("Foo#method_with_named_parameter")
338
+ unexpected_roles = [
339
+ Inch::Evaluation::Role::MethodParameter::WithoutMention,
340
+ Inch::Evaluation::Role::MethodParameter::WithoutType,
341
+ ]
342
+ assert_roles m, [], unexpected_roles
343
+ end
312
344
 
313
- def test_overloading1
314
- list = []
315
- list << @objects.find("Overloading#rgb")
316
- list << @objects.find("Overloading#rgba")
317
- list << @objects.find("Overloading#change_color")
318
- list << @objects.find("Overloading#mix")
319
- list << @objects.find("Overloading#hooks")
320
- list << @objects.find("Overloading#identifiers")
321
- list << @objects.find("Overloading#params_only_in_overloads")
322
- list.each do |m|
323
- assert_equal 100, m.score, "#{m.fullname} did not get 100"
345
+ it "should recognize wrong parameter documentation" do
346
+ m = @objects.find("Foo::Bar#method_with_wrong_doc")
347
+ assert m.has_doc?
348
+ assert m.has_parameters?
349
+ assert m.return_mentioned?
350
+
351
+ assert_equal 4, m.parameters.size
352
+ p = m.parameter(:param1)
353
+ assert p.mentioned? # mentioned in docs, correctly
354
+ refute p.wrongly_mentioned?
355
+ p = m.parameter(:param2)
356
+ refute p.mentioned?
357
+ refute p.wrongly_mentioned? # not mentioned in docs at all
358
+ p = m.parameter(:param3)
359
+ refute p.mentioned?
360
+ refute p.wrongly_mentioned? # not mentioned in docs at all
361
+
362
+ p = m.parameter(:param4)
363
+ assert p.mentioned?
364
+ assert p.wrongly_mentioned? # mentioned in docs, but not present
365
+
366
+ assert m.score
324
367
  end
325
- end
326
368
 
327
- def test_overloading_with_bad_doc
328
- m = @objects.find("Overloading#missing_param_names")
329
- refute m.has_doc? # it may be mentioned in the docs, but it's malformed.
330
- end
369
+ it "should recognize fully-documented methods with parameters" do
370
+ m = @objects.find("Foo::Bar#method_with_full_doc")
371
+ assert m.has_doc?
372
+ assert m.has_parameters?
373
+ assert m.return_mentioned?
374
+
375
+ assert_equal 2, m.parameters.size
376
+ m.parameters.each do |param|
377
+ assert param.mentioned?
378
+ assert param.typed?
379
+ assert param.described?
380
+ refute param.wrongly_mentioned?
381
+ end
382
+
383
+ assert_equal 100, m.score
384
+ end
331
385
 
332
- def test_attribute_directive_on_reader
333
- m = @objects.find("Attributes#email")
334
- refute_equal 0, m.score
335
- refute m.undocumented?
336
- end
386
+ it "should recognize question mark methods" do
387
+ m = @objects.find("InchTest#question_mark_method?")
388
+ refute m.has_doc?
389
+ refute m.has_parameters?
337
390
 
338
- def test_attribute_directive_on_writer
339
- m = @objects.find("Attributes#email=")
340
- refute_equal 0, m.score
341
- refute m.undocumented?
342
- end
391
+ # assert it is zero, because YARD auto-assigns tags to these
392
+ assert_equal 0, m.score
393
+ end
343
394
 
344
- def test_attr_accessor_on_reader
345
- m = @objects.find("Attributes#username")
346
- refute_equal 0, m.score
347
- refute m.undocumented?
348
- end
395
+ it "should recognize question mark methods with description" do
396
+ m = @objects.find("InchTest#question_mark_method_with_description?")
397
+ refute m.has_doc?
398
+ refute m.has_parameters?
349
399
 
350
- def test_attr_accessor_on_writer
351
- m = @objects.find("Attributes#username=")
352
- refute_equal 0, m.score
353
- refute m.undocumented?
354
- end
400
+ assert m.score > 0
401
+ assert m.score >= 50 # TODO: don't use magic numbers
402
+ end
355
403
 
356
- def test_overloading_with_many_overloads
357
- m = @objects.find("Overloading#many_overloads")
358
- assert_equal 1, count_roles(m, Inch::Evaluation::Role::Method::WithoutReturnDescription)
359
- assert_equal 1, count_roles(m, Inch::Evaluation::Role::Method::WithoutReturnType)
360
- assert_equal 1, count_roles(m, Inch::Evaluation::Role::MethodParameter::WithoutMention, 'block')
361
- end
404
+ it "should recognize question mark methods with description and parameters" do
405
+ m = @objects.find("InchTest#method_with_description_and_parameters?")
406
+ refute m.has_doc?
407
+ assert m.has_parameters?
362
408
 
363
- def test_overloading_with_bad_doc
364
- m = @objects.find("Overloading#params_only_in_overloads")
365
- unexpected_roles = [
366
- Inch::Evaluation::Role::Object::WithoutCodeExample,
367
- Inch::Evaluation::Role::MethodParameter::WithoutMention,
368
- Inch::Evaluation::Role::MethodParameter::WithoutType,
369
- ]
370
- assert_roles m, [], unexpected_roles
371
- end
409
+ assert m.score > 0
410
+ end
372
411
 
373
- def test_overloading_with_half_bad_doc
374
- m = @objects.find("Overloading#one_param_missing_in_overload")
375
- unexpected_roles = [
376
- Inch::Evaluation::Role::Object::WithoutCodeExample,
377
- ]
378
- expected_roles = [
379
- Inch::Evaluation::Role::MethodParameter::WithoutMention,
380
- Inch::Evaluation::Role::MethodParameter::WithoutType,
381
- ]
382
- assert_roles m, expected_roles, unexpected_roles
383
- end
412
+ it "should recognize the depth of methods" do
413
+ m = @objects.find("#root_method")
414
+ assert_equal 1, m.depth
415
+ m = @objects.find("InchTest#getter")
416
+ assert_equal 2, m.depth
417
+ m = @objects.find("Foo::Bar#method_without_doc")
418
+ assert_equal 3, m.depth
419
+ end
384
420
 
385
- def test_documenting_named_parameters
386
- m = @objects.find("Foo#method_with_named_parameter")
387
- unexpected_roles = [
388
- Inch::Evaluation::Role::MethodParameter::WithoutMention,
389
- Inch::Evaluation::Role::MethodParameter::WithoutType,
390
- ]
391
- assert_roles m, [], unexpected_roles
421
+ it "should recognize docs on class variables" do
422
+ m = @objects.find("Foo::@@class_variable")
423
+ assert m.has_doc?
424
+ refute m.undocumented?
425
+ assert_equal 100, m.score
426
+ end
392
427
  end
393
428
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.rc2
4
+ version: 0.5.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Föhring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -189,6 +189,7 @@ files:
189
189
  - lib/inch/code_object/provider/yard/object.rb
190
190
  - lib/inch/code_object/provider/yard/object/base.rb
191
191
  - lib/inch/code_object/provider/yard/object/class_object.rb
192
+ - lib/inch/code_object/provider/yard/object/class_variable_object.rb
192
193
  - lib/inch/code_object/provider/yard/object/constant_object.rb
193
194
  - lib/inch/code_object/provider/yard/object/method_object.rb
194
195
  - lib/inch/code_object/provider/yard/object/method_parameter_object.rb
@@ -200,6 +201,7 @@ files:
200
201
  - lib/inch/code_object/proxy.rb
201
202
  - lib/inch/code_object/proxy/base.rb
202
203
  - lib/inch/code_object/proxy/class_object.rb
204
+ - lib/inch/code_object/proxy/class_variable_object.rb
203
205
  - lib/inch/code_object/proxy/constant_object.rb
204
206
  - lib/inch/code_object/proxy/method_object.rb
205
207
  - lib/inch/code_object/proxy/method_parameter_object.rb
@@ -224,11 +226,13 @@ files:
224
226
  - lib/inch/evaluation/proxy.rb
225
227
  - lib/inch/evaluation/proxy/base.rb
226
228
  - lib/inch/evaluation/proxy/class_object.rb
229
+ - lib/inch/evaluation/proxy/class_variable_object.rb
227
230
  - lib/inch/evaluation/proxy/constant_object.rb
228
231
  - lib/inch/evaluation/proxy/method_object.rb
229
232
  - lib/inch/evaluation/proxy/module_object.rb
230
233
  - lib/inch/evaluation/proxy/namespace_object.rb
231
234
  - lib/inch/evaluation/role/base.rb
235
+ - lib/inch/evaluation/role/class_variable.rb
232
236
  - lib/inch/evaluation/role/constant.rb
233
237
  - lib/inch/evaluation/role/method.rb
234
238
  - lib/inch/evaluation/role/method_parameter.rb