yard 0.9.21 → 0.9.26

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (250) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +0 -0
  3. data/.gitattributes +4 -0
  4. data/.github/FUNDING.yml +3 -0
  5. data/.github/ISSUE_TEMPLATE.md +6 -6
  6. data/.github/PULL_REQUEST_TEMPLATE.md +5 -5
  7. data/.github/workflows/ci.yml +42 -0
  8. data/.github/workflows/gem.yml +27 -0
  9. data/.gitignore +0 -0
  10. data/.rspec +0 -0
  11. data/.rubocop.yml +37 -24
  12. data/.travis.yml +0 -3
  13. data/.yardopts +0 -0
  14. data/.yardopts_guide +0 -0
  15. data/.yardopts_i18n +0 -0
  16. data/CHANGELOG.md +47 -4
  17. data/CONTRIBUTING.md +2 -2
  18. data/Gemfile +4 -3
  19. data/README.md +97 -102
  20. data/Rakefile +2 -0
  21. data/lib/yard/cli/diff.rb +4 -1
  22. data/lib/yard/cli/server.rb +22 -13
  23. data/lib/yard/code_objects/method_object.rb +1 -1
  24. data/lib/yard/code_objects/namespace_mapper.rb +30 -3
  25. data/lib/yard/code_objects/proxy.rb +2 -1
  26. data/lib/yard/globals.rb +1 -1
  27. data/lib/yard/handlers/c/base.rb +35 -0
  28. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -1
  29. data/lib/yard/parser/ruby/legacy/irb/slex.rb +1 -1
  30. data/lib/yard/parser/ruby/ruby_parser.rb +6 -4
  31. data/lib/yard/parser/ruby/token_resolver.rb +3 -1
  32. data/lib/yard/parser/source_parser.rb +1 -1
  33. data/lib/yard/registry_resolver.rb +10 -24
  34. data/lib/yard/registry_store.rb +1 -1
  35. data/lib/yard/serializers/yardoc_serializer.rb +1 -1
  36. data/lib/yard/server/commands/base.rb +2 -2
  37. data/lib/yard/templates/helpers/html_helper.rb +10 -3
  38. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +1 -1
  39. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
  40. data/lib/yard/templates/section.rb +1 -3
  41. data/lib/yard/version.rb +1 -1
  42. data/samus.json +15 -46
  43. data/tasks/update_error_map.rake +53 -0
  44. data/templates/default/fulldoc/html/css/style.css +1 -0
  45. data/templates/default/fulldoc/html/js/jquery.js +4 -2
  46. data/yard.gemspec +1 -2
  47. metadata +9 -206
  48. data/spec/cli/command_parser_spec.rb +0 -43
  49. data/spec/cli/command_spec.rb +0 -36
  50. data/spec/cli/config_spec.rb +0 -148
  51. data/spec/cli/diff_spec.rb +0 -254
  52. data/spec/cli/display_spec.rb +0 -30
  53. data/spec/cli/gems_spec.rb +0 -81
  54. data/spec/cli/graph_spec.rb +0 -18
  55. data/spec/cli/help_spec.rb +0 -22
  56. data/spec/cli/i18n_spec.rb +0 -107
  57. data/spec/cli/list_spec.rb +0 -8
  58. data/spec/cli/markup_types_spec.rb +0 -22
  59. data/spec/cli/server_spec.rb +0 -324
  60. data/spec/cli/stats_spec.rb +0 -96
  61. data/spec/cli/yard_on_yard_spec.rb +0 -38
  62. data/spec/cli/yardoc_spec.rb +0 -896
  63. data/spec/cli/yri_spec.rb +0 -101
  64. data/spec/code_objects/base_spec.rb +0 -485
  65. data/spec/code_objects/class_object_spec.rb +0 -226
  66. data/spec/code_objects/code_object_list_spec.rb +0 -36
  67. data/spec/code_objects/constants_spec.rb +0 -116
  68. data/spec/code_objects/extra_file_object_spec.rb +0 -161
  69. data/spec/code_objects/macro_object_spec.rb +0 -150
  70. data/spec/code_objects/method_object_spec.rb +0 -184
  71. data/spec/code_objects/module_object_spec.rb +0 -142
  72. data/spec/code_objects/namespace_object_spec.rb +0 -171
  73. data/spec/code_objects/proxy_spec.rb +0 -147
  74. data/spec/code_objects/spec_helper.rb +0 -3
  75. data/spec/config_spec.rb +0 -171
  76. data/spec/core_ext/array_spec.rb +0 -13
  77. data/spec/core_ext/file_spec.rb +0 -72
  78. data/spec/core_ext/hash_spec.rb +0 -14
  79. data/spec/core_ext/insertion_spec.rb +0 -37
  80. data/spec/core_ext/module_spec.rb +0 -9
  81. data/spec/core_ext/string_spec.rb +0 -42
  82. data/spec/core_ext/symbol_hash_spec.rb +0 -89
  83. data/spec/docstring_parser_spec.rb +0 -280
  84. data/spec/docstring_spec.rb +0 -373
  85. data/spec/handlers/alias_handler_spec.rb +0 -82
  86. data/spec/handlers/attribute_handler_spec.rb +0 -96
  87. data/spec/handlers/base_spec.rb +0 -216
  88. data/spec/handlers/c/alias_handler_spec.rb +0 -34
  89. data/spec/handlers/c/attribute_handler_spec.rb +0 -41
  90. data/spec/handlers/c/class_handler_spec.rb +0 -78
  91. data/spec/handlers/c/constant_handler_spec.rb +0 -71
  92. data/spec/handlers/c/init_handler_spec.rb +0 -48
  93. data/spec/handlers/c/method_handler_spec.rb +0 -327
  94. data/spec/handlers/c/mixin_handler_spec.rb +0 -44
  95. data/spec/handlers/c/module_handler_spec.rb +0 -71
  96. data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
  97. data/spec/handlers/c/path_handler_spec.rb +0 -36
  98. data/spec/handlers/c/spec_helper.rb +0 -23
  99. data/spec/handlers/c/struct_handler_spec.rb +0 -16
  100. data/spec/handlers/class_condition_handler_spec.rb +0 -87
  101. data/spec/handlers/class_handler_spec.rb +0 -247
  102. data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
  103. data/spec/handlers/class_variable_handler_spec.rb +0 -12
  104. data/spec/handlers/constant_handler_spec.rb +0 -112
  105. data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
  106. data/spec/handlers/dsl_handler_spec.rb +0 -226
  107. data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
  108. data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
  109. data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
  110. data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
  111. data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
  112. data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
  113. data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
  114. data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
  115. data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
  116. data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
  117. data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
  118. data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
  119. data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
  120. data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
  121. data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
  122. data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
  123. data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
  124. data/spec/handlers/exception_handler_spec.rb +0 -49
  125. data/spec/handlers/extend_handler_spec.rb +0 -28
  126. data/spec/handlers/legacy_base_spec.rb +0 -128
  127. data/spec/handlers/method_condition_handler_spec.rb +0 -15
  128. data/spec/handlers/method_handler_spec.rb +0 -214
  129. data/spec/handlers/mixin_handler_spec.rb +0 -60
  130. data/spec/handlers/module_function_handler_spec.rb +0 -106
  131. data/spec/handlers/module_handler_spec.rb +0 -35
  132. data/spec/handlers/private_class_method_handler_spec.rb +0 -11
  133. data/spec/handlers/private_constant_handler_spec.rb +0 -25
  134. data/spec/handlers/processor_spec.rb +0 -35
  135. data/spec/handlers/public_class_method_handler_spec.rb +0 -11
  136. data/spec/handlers/ruby/base_spec.rb +0 -95
  137. data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
  138. data/spec/handlers/spec_helper.rb +0 -33
  139. data/spec/handlers/visibility_handler_spec.rb +0 -44
  140. data/spec/handlers/yield_handler_spec.rb +0 -52
  141. data/spec/i18n/locale_spec.rb +0 -81
  142. data/spec/i18n/message_spec.rb +0 -52
  143. data/spec/i18n/messages_spec.rb +0 -67
  144. data/spec/i18n/pot_generator_spec.rb +0 -295
  145. data/spec/i18n/text_spec.rb +0 -184
  146. data/spec/logging_spec.rb +0 -44
  147. data/spec/options_spec.rb +0 -171
  148. data/spec/parser/base_spec.rb +0 -24
  149. data/spec/parser/c_parser_spec.rb +0 -236
  150. data/spec/parser/examples/array.c.txt +0 -6267
  151. data/spec/parser/examples/example1.rb.txt +0 -8
  152. data/spec/parser/examples/extrafile.c.txt +0 -8
  153. data/spec/parser/examples/file.c.txt +0 -28
  154. data/spec/parser/examples/multifile.c.txt +0 -22
  155. data/spec/parser/examples/namespace.cpp.txt +0 -68
  156. data/spec/parser/examples/override.c.txt +0 -424
  157. data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
  158. data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
  159. data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
  160. data/spec/parser/ruby/ast_node_spec.rb +0 -33
  161. data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
  162. data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
  163. data/spec/parser/ruby/ruby_parser_spec.rb +0 -508
  164. data/spec/parser/ruby/token_resolver_spec.rb +0 -165
  165. data/spec/parser/source_parser_spec.rb +0 -727
  166. data/spec/parser/tag_parsing_spec.rb +0 -17
  167. data/spec/rake/yardoc_task_spec.rb +0 -118
  168. data/spec/registry_spec.rb +0 -463
  169. data/spec/registry_store_spec.rb +0 -327
  170. data/spec/rubygems/doc_manager_spec.rb +0 -112
  171. data/spec/serializers/data/serialized_yardoc/checksums +0 -1
  172. data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
  173. data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
  174. data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
  175. data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
  176. data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
  177. data/spec/serializers/file_system_serializer_spec.rb +0 -145
  178. data/spec/serializers/spec_helper.rb +0 -2
  179. data/spec/serializers/yardoc_serializer_spec.rb +0 -78
  180. data/spec/server/adapter_spec.rb +0 -39
  181. data/spec/server/commands/base_spec.rb +0 -91
  182. data/spec/server/commands/library_command_spec.rb +0 -39
  183. data/spec/server/doc_server_helper_spec.rb +0 -72
  184. data/spec/server/doc_server_serializer_spec.rb +0 -60
  185. data/spec/server/rack_adapter_spec.rb +0 -21
  186. data/spec/server/router_spec.rb +0 -123
  187. data/spec/server/spec_helper.rb +0 -22
  188. data/spec/server/static_caching_spec.rb +0 -47
  189. data/spec/server/webrick_servlet_spec.rb +0 -20
  190. data/spec/server_spec.rb +0 -19
  191. data/spec/spec_helper.rb +0 -212
  192. data/spec/tags/default_factory_spec.rb +0 -168
  193. data/spec/tags/default_tag_spec.rb +0 -11
  194. data/spec/tags/directives_spec.rb +0 -463
  195. data/spec/tags/library_spec.rb +0 -48
  196. data/spec/tags/overload_tag_spec.rb +0 -53
  197. data/spec/tags/ref_tag_list_spec.rb +0 -53
  198. data/spec/tags/types_explainer_spec.rb +0 -203
  199. data/spec/templates/class_spec.rb +0 -45
  200. data/spec/templates/constant_spec.rb +0 -41
  201. data/spec/templates/engine_spec.rb +0 -131
  202. data/spec/templates/examples/class001.html +0 -308
  203. data/spec/templates/examples/class001.txt +0 -36
  204. data/spec/templates/examples/class002.html +0 -39
  205. data/spec/templates/examples/constant001.txt +0 -25
  206. data/spec/templates/examples/constant002.txt +0 -7
  207. data/spec/templates/examples/constant003.txt +0 -11
  208. data/spec/templates/examples/method001.html +0 -137
  209. data/spec/templates/examples/method001.txt +0 -35
  210. data/spec/templates/examples/method002.html +0 -91
  211. data/spec/templates/examples/method002.txt +0 -20
  212. data/spec/templates/examples/method003.html +0 -165
  213. data/spec/templates/examples/method003.txt +0 -45
  214. data/spec/templates/examples/method004.html +0 -48
  215. data/spec/templates/examples/method004.txt +0 -10
  216. data/spec/templates/examples/method005.html +0 -105
  217. data/spec/templates/examples/method005.txt +0 -33
  218. data/spec/templates/examples/method006.html +0 -108
  219. data/spec/templates/examples/method006.txt +0 -20
  220. data/spec/templates/examples/module001.dot +0 -33
  221. data/spec/templates/examples/module001.html +0 -833
  222. data/spec/templates/examples/module001.txt +0 -33
  223. data/spec/templates/examples/module002.html +0 -341
  224. data/spec/templates/examples/module003.html +0 -202
  225. data/spec/templates/examples/module004.html +0 -394
  226. data/spec/templates/examples/module005.html +0 -82
  227. data/spec/templates/examples/tag001.txt +0 -82
  228. data/spec/templates/helpers/base_helper_spec.rb +0 -171
  229. data/spec/templates/helpers/html_helper_spec.rb +0 -687
  230. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
  231. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
  232. data/spec/templates/helpers/markup_helper_spec.rb +0 -136
  233. data/spec/templates/helpers/method_helper_spec.rb +0 -107
  234. data/spec/templates/helpers/module_helper_spec.rb +0 -35
  235. data/spec/templates/helpers/shared_signature_examples.rb +0 -126
  236. data/spec/templates/helpers/text_helper_spec.rb +0 -65
  237. data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
  238. data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -46
  239. data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -59
  240. data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
  241. data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -59
  242. data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -48
  243. data/spec/templates/method_spec.rb +0 -118
  244. data/spec/templates/module_spec.rb +0 -203
  245. data/spec/templates/onefile_spec.rb +0 -66
  246. data/spec/templates/section_spec.rb +0 -144
  247. data/spec/templates/spec_helper.rb +0 -76
  248. data/spec/templates/tag_spec.rb +0 -52
  249. data/spec/templates/template_spec.rb +0 -410
  250. data/spec/verifier_spec.rb +0 -106
@@ -1,29 +0,0 @@
1
- module ModName
2
- private
3
-
4
- # Docstring
5
- module OtherModName
6
- end
7
- end
8
-
9
- module StressTest; end
10
-
11
- module A; end
12
-
13
- module Q
14
- module A::B
15
- end
16
- module FOO; end
17
- end
18
-
19
- module ::Kernel
20
- def x; end
21
- end
22
-
23
- module A; end
24
- module B; end
25
- module C; end
26
- class D; include A; include B; include C; end
27
-
28
- Z = Q
29
- module Z::FOO::A; end
@@ -1,8 +0,0 @@
1
- module A
2
- Foo = 1
3
- class B; end
4
- module C; end
5
- module D; end
6
-
7
- private_constant :Foo, 'B', C
8
- end
@@ -1,11 +0,0 @@
1
- class A < NotHandler
2
- process { hello }
3
- end
4
-
5
- class B < YARD::Handlers::Ruby::Base
6
- process { test }
7
- end
8
-
9
- class C < YARD::Handlers::Ruby::Legacy::Base
10
- process do test end
11
- end
@@ -1,36 +0,0 @@
1
- class Testing
2
- def pub; end
3
-
4
- private
5
-
6
- def priv; end
7
- def notpriv; end
8
- def notpriv2; end
9
- def notpriv?; end
10
-
11
- protected
12
-
13
- def prot; end
14
-
15
- public
16
-
17
- def pub2; end
18
-
19
- protected :notpriv, 'notpriv2', :notpriv?
20
-
21
- private name
22
- private *argument
23
- private *(method_call)
24
-
25
- def Foo; end
26
- private :Foo
27
-
28
- private def decpriv; end
29
-
30
- private
31
-
32
- class Bar; end
33
- module Baz; end
34
-
35
- private :not_exist!
36
- end
@@ -1,54 +0,0 @@
1
- class Testing
2
- # Ignore yields outside methods
3
- yield x, y, z
4
-
5
- # Should document this
6
- def mymethod
7
- yield
8
- end
9
-
10
- # Has yield and yieldparam documentation
11
- # @yield [a, b] Blah
12
- # @yieldparam a Blah
13
- # @yieldparam b Blah
14
- def mymethod2
15
- yield(b, a) # Yield something else
16
- end
17
-
18
- # Has yield documentation only
19
- # @yield [a, b]
20
- def mymethod3
21
- yield self # Should not be changed
22
- end
23
-
24
- # Has yieldparam documentation only
25
- # @yieldparam _self BLAH
26
- def mymethod4
27
- yield self
28
- end
29
-
30
- # Some weird possibilities..
31
- # Document it all.
32
-
33
-
34
- def mymethod5
35
- yield :a, b, self, File.read('file', 'w'), CONSTANT if x == 2
36
- end
37
-
38
- def mymethod6
39
- yield(b, a)
40
- end
41
-
42
- def mymethod7
43
- yield a
44
- yield b
45
- end
46
-
47
- def mymethod8
48
- yield self
49
- end
50
-
51
- def mymethod9
52
- yield super
53
- end
54
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ExceptionHandler" do
5
- before(:all) { parse_file :exception_handler_001, __FILE__ }
6
-
7
- it "does not document an exception outside of a method" do
8
- expect(P('Testing').has_tag?(:raise)).to be false
9
- end
10
-
11
- it "documents a valid raise" do
12
- expect(P('Testing#mymethod').tag(:raise).types).to eq ['ArgumentError']
13
- end
14
-
15
- it "only documents non-dynamic raises" do
16
- expect(P('Testing#mymethod2').tag(:raise)).to be nil
17
- expect(P('Testing#mymethod6').tag(:raise)).to be nil
18
- expect(P('Testing#mymethod7').tag(:raise)).to be nil
19
- end
20
-
21
- it "treats ConstantName.new as a valid exception class" do
22
- expect(P('Testing#mymethod8').tag(:raise).types).to eq ['ExceptionClass']
23
- end
24
-
25
- it "does not document a method with an existing @raise tag" do
26
- expect(P('Testing#mymethod3').tag(:raise).types).to eq ['A']
27
- end
28
-
29
- it "only documents the first raise message of a method (limitation of exception handler)" do
30
- expect(P('Testing#mymethod4').tag(:raise).types).to eq ['A']
31
- end
32
-
33
- it "handles complex class names" do
34
- expect(P('Testing#mymethod5').tag(:raise).types).to eq ['YARD::Parser::UndocumentableError']
35
- end
36
-
37
- it "ignores any raise calls on a receiver" do
38
- expect(P('Testing#mymethod9').tag(:raise)).to be nil
39
- end
40
-
41
- it "handles raise expressions that are method calls" do
42
- expect(P('Testing#mymethod10').tag(:raise)).to be nil
43
- expect(P('Testing#mymethod11').tag(:raise)).to be nil
44
- end
45
-
46
- it "ignores empty raise call" do
47
- expect(P('Testing#mymethod12').tag(:raise)).to be nil
48
- end
49
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ExtendHandler" do
5
- before(:all) { parse_file :extend_handler_001, __FILE__ }
6
-
7
- it "includes modules at class scope" do
8
- expect(Registry.at(:B).class_mixins).to eq [P(:A)]
9
- expect(Registry.at(:B).instance_mixins).to be_empty
10
- end
11
-
12
- it "handles a module extending itself" do
13
- expect(Registry.at(:C).class_mixins).to eq [P(:C)]
14
- expect(Registry.at(:C).instance_mixins).to be_empty
15
- end
16
-
17
- it "extends module with correct namespace" do
18
- expect(Registry.at('Q::R::S').class_mixins.first.path).to eq 'A'
19
- end
20
-
21
- it "does not allow extending self if object is a class" do
22
- undoc_error "class Foo; extend self; end"
23
- end
24
-
25
- it "adds mixins from extend calls to constants" do
26
- expect(P('FromConstant').class_mixins).to eq [P('A')]
27
- end
28
- end
@@ -1,128 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- include Parser::Ruby::Legacy
5
-
6
- RSpec.describe YARD::Handlers::Ruby::Legacy::Base, "#tokval" do
7
- before { @handler = Handlers::Ruby::Legacy::Base.new(nil, nil) }
8
-
9
- def tokval(code, *types)
10
- @handler.send(:tokval, TokenList.new(code).first, *types)
11
- end
12
-
13
- it "returns the String's value without quotes" do
14
- expect(tokval('"hello"')).to eq "hello"
15
- end
16
-
17
- it "does not allow interpolated strings with TkSTRING" do
18
- expect(tokval('"#{c}"', RubyToken::TkSTRING)).to be nil
19
- end
20
-
21
- it "returns a Symbol's value as a String (as if it was done via :name.to_sym)" do
22
- expect(tokval(':sym')).to eq :sym
23
- end
24
-
25
- it "returns nil for any non accepted type" do
26
- expect(tokval('identifier')).to be nil
27
- expect(tokval(':sym', RubyToken::TkId)).to be nil
28
- end
29
-
30
- it "accepts TkVal tokens by default" do
31
- expect(tokval('2.5')).to eq 2.5
32
- expect(tokval(':sym')).to eq :sym
33
- end
34
-
35
- it "accepts any ID type if TkId is set" do
36
- expect(tokval('variable', RubyToken::TkId)).to eq "variable"
37
- expect(tokval('CONSTANT', RubyToken::TkId)).to eq "CONSTANT"
38
- end
39
-
40
- it "allows extra token types to be accepted" do
41
- expect(tokval('2.5', RubyToken::TkFLOAT)).to eq 2.5
42
- expect(tokval('2', RubyToken::TkFLOAT)).to be nil
43
- expect(tokval(':symbol', RubyToken::TkFLOAT)).to be nil
44
- end
45
-
46
- it "allows :string for any string type" do
47
- expect(tokval('"hello"', :string)).to eq "hello"
48
- expect(tokval('"#{c}"', :string)).to eq '#{c}'
49
- end
50
-
51
- it "does not include interpolated strings when using :attr" do
52
- expect(tokval('"#{c}"', :attr)).to be nil
53
- end
54
-
55
- it "allows any number type with :number" do
56
- expect(tokval('2.5', :number)).to eq 2.5
57
- expect(tokval('2', :number)).to eq 2
58
- end
59
-
60
- it "allows method names with :identifier" do
61
- expect(tokval('methodname?', :identifier)).to eq "methodname?"
62
- end
63
-
64
- # it "obeys documentation expectations" do docspec end
65
- end
66
-
67
- RSpec.describe YARD::Handlers::Base, "#tokval_list" do
68
- before { @handler = Handlers::Ruby::Legacy::Base.new(nil, nil) }
69
-
70
- def tokval_list(code, *types)
71
- @handler.send(:tokval_list, TokenList.new(code), *types)
72
- end
73
-
74
- it "returns the list of tokvalues" do
75
- expect(tokval_list(":a, :b, \"\#{c}\", 'd'", :attr)).to eq [:a, :b, 'd']
76
- expect(tokval_list(":a, :b, File.read(\"\#{c}\", ['w']), :d",
77
- RubyToken::Token)).to eq [:a, :b, 'File.read("#{c}", [\'w\'])', :d]
78
- end
79
-
80
- it "tries to skip any invalid tokens" do
81
- expect(tokval_list(":a, :b, \"\#{c}\", :d", :attr)).to eq [:a, :b, :d]
82
- expect(tokval_list(":a, :b, File.read(\"\#{c}\", 'w', File.open { }), :d", :attr)).to eq [:a, :b, :d]
83
- expect(tokval_list("CONST1, identifier, File.read(\"\#{c}\", 'w', File.open { }), CONST2",
84
- RubyToken::TkId)).to eq ['CONST1', 'identifier', 'CONST2']
85
- end
86
-
87
- it "ignores a token if another invalid token is read before a comma" do
88
- expect(tokval_list(":a, :b XYZ, :c", RubyToken::TkSYMBOL)).to eq [:a, :c]
89
- end
90
-
91
- it "stops on most keywords" do
92
- expect(tokval_list(':a rescue :x == 5', RubyToken::Token)).to eq [:a]
93
- end
94
-
95
- it "handles ignore parentheses that begin the token list" do
96
- expect(tokval_list('(:a, :b, :c)', :attr)).to eq [:a, :b, :c]
97
- end
98
-
99
- it "ends when a closing parenthesis was found" do
100
- expect(tokval_list(':a, :b, :c), :d', :attr)).to eq [:a, :b, :c]
101
- end
102
-
103
- it "ignores parentheses around items in a list" do
104
- expect(tokval_list(':a, (:b), :c, (:d TEST), :e, [:f], :g', :attr)).to eq [:a, :b, :c, :e, :g]
105
- expect(tokval_list(':a, (((:f)))', :attr)).to eq [:a, :f]
106
- expect(tokval_list(':a, ([:f]), :c)', RubyToken::Token)).to eq [:a, '[:f]', :c]
107
- end
108
-
109
- it "does not stop on a true/false/self keyword (cannot handle nil)" do
110
- expect(tokval_list(':a, true, :b, self, false, :c, nil, File, super, if, XYZ',
111
- RubyToken::Token)).to eq [:a, true, :b, 'self', false, :c, 'File', 'super']
112
- end
113
-
114
- it "ignores invalid commas" do
115
- expect(tokval_list(":a, :b, , :d")).to eq [:a, :b, :d]
116
- end
117
-
118
- it "returns an empty list if no matches were found" do
119
- expect(tokval_list('attr_accessor :x')).to eq []
120
- end
121
-
122
- it "treats {} as a valid value" do
123
- # FIXME: tokval_list destroys extra spaces surrounding the '=' in
124
- # this situation. This is technically a design flaw of the
125
- # tokval parser, but this is now the expected behaviour.
126
- expect(tokval_list("opts = {}", :all)).to eq ["opts={}"]
127
- end
128
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MethodConditionHandler" do
5
- before(:all) { parse_file :method_condition_handler_001, __FILE__ }
6
-
7
- it "does not parse regular if blocks in methods" do
8
- expect(Registry.at('#b')).to be nil
9
- end
10
-
11
- it "parses if/unless blocks in the form X if COND" do
12
- expect(Registry.at('#c')).not_to be nil
13
- expect(Registry.at('#d')).not_to be nil
14
- end
15
- end
@@ -1,214 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}MethodHandler" do
5
- before(:all) do
6
- log.enter_level(Logger::ERROR) do
7
- parse_file :method_handler_001, __FILE__
8
- end
9
- end
10
-
11
- it "adds methods to parent's #meths list" do
12
- expect(P(:Foo).meths).to include(P("Foo#method1"))
13
- end
14
-
15
- it "parses and adds class methods (self.method2)" do
16
- expect(P(:Foo).meths).to include(P("Foo.method2"))
17
- end
18
-
19
- it "parses and adds class methods from other namespaces (String.hello)" do
20
- expect(P("String.hello")).to be_instance_of(CodeObjects::MethodObject)
21
- end
22
-
23
- [:[], :[]=, :allowed?, :/, :=~, :==, :`, :|, :*, :&, :%, :'^', :-@, :+@, :'~@'].each do |name|
24
- it "allows valid method #{name}" do
25
- expect(Registry.at("Foo##{name}")).not_to be nil
26
- end
27
- end
28
-
29
- it "allows self.methname" do
30
- expect(Registry.at("Foo.new")).not_to be nil
31
- end
32
-
33
- it "marks dynamic methods as such" do
34
- expect(P('Foo#dynamic').dynamic?).to be true
35
- end
36
-
37
- it "shows that a method is explicitly defined (if it was originally defined implicitly by attribute)" do
38
- expect(P('Foo#method1').is_explicit?).to be true
39
- end
40
-
41
- it "handles parameters" do
42
- expect(P('Foo#[]').parameters).to eq [['key', "'default'"]]
43
- expect(P('Foo#/').parameters).to eq [['x', "File.new('x', 'w')"], ['y', '2']]
44
- end
45
-
46
- it "handles multiline parameters" do
47
- YARD.parse_string <<-EOF
48
- class Bar
49
- def multiline_params(x,
50
- y, z, zz = 'zz',
51
- *foo,
52
- a: 'a', b: 'b',
53
- c: 'c',
54
- **bar,
55
- &blk
56
- )
57
- end
58
- end
59
- EOF
60
-
61
- sig = "def multiline_params(x, y, z, zz = 'zz', *foo, a: 'a', b: 'b', c: 'c', **bar, &blk)"
62
- expect(P('Bar#multiline_params').signature).to eq sig
63
- end if YARD.ruby2?
64
-
65
- it "handles method signature with no parameters" do
66
- YARD.parse_string "class Bar; def foo; end end"
67
- expect(P('Bar#foo').signature).to eq 'def foo'
68
- end
69
-
70
- it "handles opts = {} as parameter" do
71
- expect(P('Foo#optsmeth').parameters).to eq [['x', nil], ['opts', '{}']]
72
- end
73
-
74
- it "handles &block as parameter" do
75
- expect(P('Foo#blockmeth').parameters).to eq [['x', nil], ['&block', nil]]
76
- end
77
-
78
- it "handles double splats" do
79
- expect(P('Foo#d_splat').parameters).to eq [["reg", nil], ["**opts", nil]]
80
- expect(P('Foo#d_unnamed_splat').parameters).to eq []
81
- end
82
-
83
- it "handles overloads" do
84
- meth = P('Foo#foo')
85
-
86
- o1 = meth.tags(:overload).first
87
- expect(o1.name).to eq :bar
88
- expect(o1.parameters).to eq [['a', nil], ['b', "1"]]
89
- expect(o1.tag(:return).type).to eq "String"
90
-
91
- o2 = meth.tags(:overload)[1]
92
- expect(o2.name).to eq :baz
93
- expect(o2.parameters).to eq [['b', nil], ['c', nil]]
94
- expect(o2.tag(:return).type).to eq "Fixnum"
95
-
96
- o3 = meth.tags(:overload)[2]
97
- expect(o3.name).to eq :bang
98
- expect(o3.parameters).to eq [['d', nil], ['e', nil]]
99
- expect(o3.docstring).to be_empty
100
- expect(o3.docstring).to be_blank
101
- end
102
-
103
- it "sets a return tag if not set on #initialize" do
104
- meth = P('Foo#initialize')
105
-
106
- expect(meth).to have_tag(:return)
107
- expect(meth.tag(:return).types).to eq ["Foo"]
108
- expect(meth.tag(:return).text).to eq "a new instance of Foo"
109
- end
110
-
111
- %w(inherited included method_added method_removed method_undefined).each do |meth|
112
- it "sets @private tag on #{meth} callback method if no docstring is set" do
113
- expect(P('Foo.' + meth)).to have_tag(:private)
114
- end
115
- end
116
-
117
- it "does not set @private tag on extended callback method since docstring is set" do
118
- expect(P('Foo.extended')).not_to have_tag(:private)
119
- end
120
-
121
- it "adds @return [Boolean] tag to methods ending in ? without return types" do
122
- meth = P('Foo#boolean?')
123
- expect(meth).to have_tag(:return)
124
- expect(meth.tag(:return).types).to eq ['Boolean']
125
- end
126
-
127
- it "adds Boolean type to return tag without types" do
128
- meth = P('Foo#boolean2?')
129
- expect(meth).to have_tag(:return)
130
- expect(meth.tag(:return).types).to eq ['Boolean']
131
- end
132
-
133
- it "does not change return type for method ending in ? with return types set" do
134
- meth = P('Foo#boolean3?')
135
- expect(meth).to have_tag(:return)
136
- expect(meth.tag(:return).types).to eq ['NotBoolean', 'nil']
137
- end
138
-
139
- it "does not change return type for method ending in ? with return types set by @overload" do
140
- meth = P('Foo#rainy?')
141
- expect(meth).to have_tag(:overload)
142
- expect(meth.tag(:overload)).to have_tag(:return)
143
- expect(meth).not_to have_tag(:return)
144
- end
145
-
146
- it "adds method writer to existing attribute" do
147
- expect(Registry.at('Foo#attr_name')).to be_reader
148
- expect(Registry.at('Foo#attr_name=')).to be_writer
149
- end
150
-
151
- it "adds method reader to existing attribute" do
152
- expect(Registry.at('Foo#attr_name2')).to be_reader
153
- expect(Registry.at('Foo#attr_name2=')).to be_writer
154
- end
155
-
156
- it "generates an options parameter if @option refers to an undocumented parameter" do
157
- meth = P('Foo#auto_opts')
158
- expect(meth).to have_tag(:param)
159
- expect(meth.tag(:param).name).to eq "opts"
160
- expect(meth.tag(:param).types).to eq ["Hash"]
161
- end
162
-
163
- it "raises an undocumentable error when a method is defined on an object instance" do
164
- undoc_error "error = Foo; def error.at(foo) end"
165
- expect(Registry.at('error')).to be nil
166
- end
167
-
168
- it "allows class method to be defined on constant reference object" do
169
- expect(Registry.at('Foo.meth_on_const')).not_to be nil
170
- expect(Registry.at('Foo.meth2_on_const')).not_to be nil
171
- end
172
-
173
- it "copies alias information on method (re-)definition to new method" do
174
- expect(Registry.at('D').aliases).to be_empty
175
- expect(Registry.at('D#b').is_alias?).to be false
176
- expect(Registry.at('D#a').is_alias?).to be false
177
- end
178
-
179
- it "adds macros for class methods" do
180
- macro = CodeObjects::MacroObject.find('prop')
181
- expect(macro).not_to be nil
182
- expect(macro.macro_data).to eq "@!method $1(value)\n$3\n@return [$2]"
183
- expect(macro.method_object).to eq Registry.at('E.property')
184
- expect(macro).to be_attached
185
- obj = Registry.at('E#foo')
186
- expect(obj).not_to be nil
187
- expect(obj.docstring).to eq 'create a foo'
188
- expect(obj.signature).to eq 'def foo(value)'
189
- expect(obj.tag(:return).types).to eq ['String']
190
- end
191
-
192
- it "handles macros on any object" do
193
- macro = CodeObjects::MacroObject.find('xyz')
194
- expect(macro).not_to be nil
195
- expect(macro.macro_data).to eq '@!method $1'
196
- end
197
-
198
- it "skips macros on instance methods" do
199
- expect(Registry.at('E#a')).to be nil
200
- end
201
-
202
- it "warns if the macro name is invalid" do
203
- expect(log).to receive(:warn).with(/Invalid directive.*@!macro/)
204
- YARD.parse_string "class Foo\n# @!macro\ndef self.foo; end\nend"
205
- end
206
-
207
- it "handles 'def end' methods" do
208
- obj = Registry.at('F::A#foo')
209
- expect(obj).not_to be nil
210
- obj = Registry.at('F::A#bar')
211
- expect(obj).not_to be nil
212
- expect(obj.docstring).to eq 'PASS'
213
- end
214
- end