yard 0.9.23 → 0.9.27

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 (257) 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 +30 -0
  8. data/.github/workflows/gem.yml +19 -0
  9. data/.gitignore +0 -0
  10. data/.rspec +0 -0
  11. data/.rubocop.yml +37 -24
  12. data/.yardopts +0 -0
  13. data/.yardopts_guide +0 -0
  14. data/.yardopts_i18n +0 -0
  15. data/CHANGELOG.md +50 -4
  16. data/CONTRIBUTING.md +2 -2
  17. data/Gemfile +5 -3
  18. data/README.md +97 -102
  19. data/Rakefile +2 -3
  20. data/lib/yard/cli/diff.rb +4 -1
  21. data/lib/yard/cli/server.rb +22 -13
  22. data/lib/yard/cli/stats.rb +2 -0
  23. data/lib/yard/cli/yardoc.rb +2 -1
  24. data/lib/yard/code_objects/method_object.rb +1 -1
  25. data/lib/yard/code_objects/namespace_mapper.rb +30 -3
  26. data/lib/yard/code_objects/proxy.rb +2 -1
  27. data/lib/yard/globals.rb +1 -1
  28. data/lib/yard/handlers/c/base.rb +35 -0
  29. data/lib/yard/handlers/ruby/method_handler.rb +1 -1
  30. data/lib/yard/handlers/ruby/mixin_handler.rb +7 -2
  31. data/lib/yard/handlers/ruby/module_function_handler.rb +15 -3
  32. data/lib/yard/parser/ruby/ast_node.rb +2 -2
  33. data/lib/yard/parser/ruby/ruby_parser.rb +7 -5
  34. data/lib/yard/parser/ruby/token_resolver.rb +3 -1
  35. data/lib/yard/parser/source_parser.rb +1 -1
  36. data/lib/yard/registry_resolver.rb +10 -24
  37. data/lib/yard/registry_store.rb +1 -1
  38. data/lib/yard/serializers/yardoc_serializer.rb +1 -1
  39. data/lib/yard/server/commands/base.rb +2 -2
  40. data/lib/yard/server/commands/library_command.rb +1 -1
  41. data/lib/yard/tags/directives.rb +10 -1
  42. data/lib/yard/templates/helpers/html_helper.rb +15 -5
  43. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
  44. data/lib/yard/templates/helpers/markup_helper.rb +2 -1
  45. data/lib/yard/templates/section.rb +1 -3
  46. data/lib/yard/version.rb +1 -1
  47. data/lib/yard.rb +3 -0
  48. data/samus.json +15 -46
  49. data/tasks/prepare_tag.rake +45 -0
  50. data/tasks/update_error_map.rake +53 -0
  51. data/templates/default/fulldoc/html/css/style.css +1 -0
  52. data/yard.gemspec +3 -2
  53. metadata +23 -207
  54. data/.travis.yml +0 -52
  55. data/spec/cli/command_parser_spec.rb +0 -43
  56. data/spec/cli/command_spec.rb +0 -36
  57. data/spec/cli/config_spec.rb +0 -148
  58. data/spec/cli/diff_spec.rb +0 -254
  59. data/spec/cli/display_spec.rb +0 -30
  60. data/spec/cli/gems_spec.rb +0 -81
  61. data/spec/cli/graph_spec.rb +0 -18
  62. data/spec/cli/help_spec.rb +0 -22
  63. data/spec/cli/i18n_spec.rb +0 -107
  64. data/spec/cli/list_spec.rb +0 -8
  65. data/spec/cli/markup_types_spec.rb +0 -22
  66. data/spec/cli/server_spec.rb +0 -324
  67. data/spec/cli/stats_spec.rb +0 -96
  68. data/spec/cli/yard_on_yard_spec.rb +0 -38
  69. data/spec/cli/yardoc_spec.rb +0 -896
  70. data/spec/cli/yri_spec.rb +0 -101
  71. data/spec/code_objects/base_spec.rb +0 -485
  72. data/spec/code_objects/class_object_spec.rb +0 -226
  73. data/spec/code_objects/code_object_list_spec.rb +0 -36
  74. data/spec/code_objects/constants_spec.rb +0 -116
  75. data/spec/code_objects/extra_file_object_spec.rb +0 -161
  76. data/spec/code_objects/macro_object_spec.rb +0 -150
  77. data/spec/code_objects/method_object_spec.rb +0 -184
  78. data/spec/code_objects/module_object_spec.rb +0 -142
  79. data/spec/code_objects/namespace_object_spec.rb +0 -171
  80. data/spec/code_objects/proxy_spec.rb +0 -147
  81. data/spec/code_objects/spec_helper.rb +0 -3
  82. data/spec/config_spec.rb +0 -171
  83. data/spec/core_ext/array_spec.rb +0 -13
  84. data/spec/core_ext/file_spec.rb +0 -72
  85. data/spec/core_ext/hash_spec.rb +0 -14
  86. data/spec/core_ext/insertion_spec.rb +0 -37
  87. data/spec/core_ext/module_spec.rb +0 -9
  88. data/spec/core_ext/string_spec.rb +0 -42
  89. data/spec/core_ext/symbol_hash_spec.rb +0 -89
  90. data/spec/docstring_parser_spec.rb +0 -280
  91. data/spec/docstring_spec.rb +0 -373
  92. data/spec/handlers/alias_handler_spec.rb +0 -82
  93. data/spec/handlers/attribute_handler_spec.rb +0 -96
  94. data/spec/handlers/base_spec.rb +0 -216
  95. data/spec/handlers/c/alias_handler_spec.rb +0 -34
  96. data/spec/handlers/c/attribute_handler_spec.rb +0 -41
  97. data/spec/handlers/c/class_handler_spec.rb +0 -78
  98. data/spec/handlers/c/constant_handler_spec.rb +0 -71
  99. data/spec/handlers/c/init_handler_spec.rb +0 -48
  100. data/spec/handlers/c/method_handler_spec.rb +0 -327
  101. data/spec/handlers/c/mixin_handler_spec.rb +0 -44
  102. data/spec/handlers/c/module_handler_spec.rb +0 -71
  103. data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
  104. data/spec/handlers/c/path_handler_spec.rb +0 -36
  105. data/spec/handlers/c/spec_helper.rb +0 -23
  106. data/spec/handlers/c/struct_handler_spec.rb +0 -16
  107. data/spec/handlers/class_condition_handler_spec.rb +0 -87
  108. data/spec/handlers/class_handler_spec.rb +0 -247
  109. data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
  110. data/spec/handlers/class_variable_handler_spec.rb +0 -12
  111. data/spec/handlers/constant_handler_spec.rb +0 -112
  112. data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
  113. data/spec/handlers/dsl_handler_spec.rb +0 -226
  114. data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
  115. data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
  116. data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
  117. data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
  118. data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
  119. data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
  120. data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
  121. data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
  122. data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
  123. data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
  124. data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
  125. data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
  126. data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
  127. data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
  128. data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
  129. data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
  130. data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
  131. data/spec/handlers/exception_handler_spec.rb +0 -49
  132. data/spec/handlers/extend_handler_spec.rb +0 -28
  133. data/spec/handlers/legacy_base_spec.rb +0 -128
  134. data/spec/handlers/method_condition_handler_spec.rb +0 -15
  135. data/spec/handlers/method_handler_spec.rb +0 -214
  136. data/spec/handlers/mixin_handler_spec.rb +0 -60
  137. data/spec/handlers/module_function_handler_spec.rb +0 -106
  138. data/spec/handlers/module_handler_spec.rb +0 -35
  139. data/spec/handlers/private_class_method_handler_spec.rb +0 -11
  140. data/spec/handlers/private_constant_handler_spec.rb +0 -25
  141. data/spec/handlers/processor_spec.rb +0 -35
  142. data/spec/handlers/public_class_method_handler_spec.rb +0 -11
  143. data/spec/handlers/ruby/base_spec.rb +0 -95
  144. data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
  145. data/spec/handlers/spec_helper.rb +0 -33
  146. data/spec/handlers/visibility_handler_spec.rb +0 -44
  147. data/spec/handlers/yield_handler_spec.rb +0 -52
  148. data/spec/i18n/locale_spec.rb +0 -81
  149. data/spec/i18n/message_spec.rb +0 -52
  150. data/spec/i18n/messages_spec.rb +0 -67
  151. data/spec/i18n/pot_generator_spec.rb +0 -295
  152. data/spec/i18n/text_spec.rb +0 -184
  153. data/spec/logging_spec.rb +0 -44
  154. data/spec/options_spec.rb +0 -171
  155. data/spec/parser/base_spec.rb +0 -24
  156. data/spec/parser/c_parser_spec.rb +0 -236
  157. data/spec/parser/examples/array.c.txt +0 -6267
  158. data/spec/parser/examples/example1.rb.txt +0 -8
  159. data/spec/parser/examples/extrafile.c.txt +0 -8
  160. data/spec/parser/examples/file.c.txt +0 -28
  161. data/spec/parser/examples/multifile.c.txt +0 -22
  162. data/spec/parser/examples/namespace.cpp.txt +0 -68
  163. data/spec/parser/examples/override.c.txt +0 -424
  164. data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
  165. data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
  166. data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
  167. data/spec/parser/ruby/ast_node_spec.rb +0 -33
  168. data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
  169. data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
  170. data/spec/parser/ruby/ruby_parser_spec.rb +0 -508
  171. data/spec/parser/ruby/token_resolver_spec.rb +0 -165
  172. data/spec/parser/source_parser_spec.rb +0 -727
  173. data/spec/parser/tag_parsing_spec.rb +0 -17
  174. data/spec/rake/yardoc_task_spec.rb +0 -118
  175. data/spec/registry_spec.rb +0 -463
  176. data/spec/registry_store_spec.rb +0 -327
  177. data/spec/rubygems/doc_manager_spec.rb +0 -112
  178. data/spec/serializers/data/serialized_yardoc/checksums +0 -1
  179. data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
  180. data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
  181. data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
  182. data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
  183. data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
  184. data/spec/serializers/file_system_serializer_spec.rb +0 -145
  185. data/spec/serializers/spec_helper.rb +0 -2
  186. data/spec/serializers/yardoc_serializer_spec.rb +0 -78
  187. data/spec/server/adapter_spec.rb +0 -39
  188. data/spec/server/commands/base_spec.rb +0 -91
  189. data/spec/server/commands/library_command_spec.rb +0 -39
  190. data/spec/server/doc_server_helper_spec.rb +0 -72
  191. data/spec/server/doc_server_serializer_spec.rb +0 -60
  192. data/spec/server/rack_adapter_spec.rb +0 -21
  193. data/spec/server/router_spec.rb +0 -123
  194. data/spec/server/spec_helper.rb +0 -22
  195. data/spec/server/static_caching_spec.rb +0 -47
  196. data/spec/server/webrick_servlet_spec.rb +0 -20
  197. data/spec/server_spec.rb +0 -19
  198. data/spec/spec_helper.rb +0 -212
  199. data/spec/tags/default_factory_spec.rb +0 -168
  200. data/spec/tags/default_tag_spec.rb +0 -11
  201. data/spec/tags/directives_spec.rb +0 -463
  202. data/spec/tags/library_spec.rb +0 -48
  203. data/spec/tags/overload_tag_spec.rb +0 -53
  204. data/spec/tags/ref_tag_list_spec.rb +0 -53
  205. data/spec/tags/types_explainer_spec.rb +0 -203
  206. data/spec/templates/class_spec.rb +0 -45
  207. data/spec/templates/constant_spec.rb +0 -41
  208. data/spec/templates/engine_spec.rb +0 -131
  209. data/spec/templates/examples/class001.html +0 -308
  210. data/spec/templates/examples/class001.txt +0 -36
  211. data/spec/templates/examples/class002.html +0 -39
  212. data/spec/templates/examples/constant001.txt +0 -25
  213. data/spec/templates/examples/constant002.txt +0 -7
  214. data/spec/templates/examples/constant003.txt +0 -11
  215. data/spec/templates/examples/method001.html +0 -137
  216. data/spec/templates/examples/method001.txt +0 -35
  217. data/spec/templates/examples/method002.html +0 -91
  218. data/spec/templates/examples/method002.txt +0 -20
  219. data/spec/templates/examples/method003.html +0 -165
  220. data/spec/templates/examples/method003.txt +0 -45
  221. data/spec/templates/examples/method004.html +0 -48
  222. data/spec/templates/examples/method004.txt +0 -10
  223. data/spec/templates/examples/method005.html +0 -105
  224. data/spec/templates/examples/method005.txt +0 -33
  225. data/spec/templates/examples/method006.html +0 -108
  226. data/spec/templates/examples/method006.txt +0 -20
  227. data/spec/templates/examples/module001.dot +0 -33
  228. data/spec/templates/examples/module001.html +0 -833
  229. data/spec/templates/examples/module001.txt +0 -33
  230. data/spec/templates/examples/module002.html +0 -341
  231. data/spec/templates/examples/module003.html +0 -202
  232. data/spec/templates/examples/module004.html +0 -394
  233. data/spec/templates/examples/module005.html +0 -82
  234. data/spec/templates/examples/tag001.txt +0 -82
  235. data/spec/templates/helpers/base_helper_spec.rb +0 -171
  236. data/spec/templates/helpers/html_helper_spec.rb +0 -687
  237. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
  238. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
  239. data/spec/templates/helpers/markup_helper_spec.rb +0 -136
  240. data/spec/templates/helpers/method_helper_spec.rb +0 -107
  241. data/spec/templates/helpers/module_helper_spec.rb +0 -35
  242. data/spec/templates/helpers/shared_signature_examples.rb +0 -126
  243. data/spec/templates/helpers/text_helper_spec.rb +0 -65
  244. data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
  245. data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -46
  246. data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -59
  247. data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
  248. data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -59
  249. data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -48
  250. data/spec/templates/method_spec.rb +0 -118
  251. data/spec/templates/module_spec.rb +0 -203
  252. data/spec/templates/onefile_spec.rb +0 -66
  253. data/spec/templates/section_spec.rb +0 -144
  254. data/spec/templates/spec_helper.rb +0 -76
  255. data/spec/templates/tag_spec.rb +0 -52
  256. data/spec/templates/template_spec.rb +0 -410
  257. data/spec/verifier_spec.rb +0 -106
@@ -1,463 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- def tag_parse(content, object = nil, handler = nil)
4
- @parser = DocstringParser.new
5
- @parser.parse(content, object, handler)
6
- @parser
7
- end
8
-
9
- RSpec.describe YARD::Tags::ParseDirective do
10
- describe "#call" do
11
- after { Registry.clear }
12
-
13
- it "parses if handler=nil but use file=(stdin)" do
14
- tag_parse %(@!parse
15
- # Docstring here
16
- def foo; end
17
- )
18
- expect(Registry.at('#foo').docstring).to eq "Docstring here"
19
- expect(Registry.at('#foo').file).to eq '(stdin)'
20
- end
21
-
22
- it "allows parser type to be specified in type" do
23
- tag_parse %{@!parse [c]
24
- void Init_Foo() {
25
- rb_define_method(rb_cMyClass, "foo", foo, 1);
26
- }
27
- }
28
- expect(Registry.at('MyClass#foo')).not_to be nil
29
- end
30
-
31
- it "parses code in context of current handler" do
32
- src = <<-eof
33
- class A
34
- # @!parse
35
- # def foo; end
36
- eval "def foo; end"
37
- end
38
- eof
39
- parser = YARD::Parser::SourceParser.new
40
- parser.file = "myfile.rb"
41
- parser.parse(StringIO.new(src))
42
- expect(Registry.at('A#foo').file).to eq 'myfile.rb'
43
- end
44
- end
45
- end
46
-
47
- RSpec.describe YARD::Tags::GroupDirective do
48
- describe "#call" do
49
- it "does nothing if handler=nil" do
50
- tag_parse("@!group foo")
51
- end
52
-
53
- it "sets group value in parser state (with handler)" do
54
- handler = OpenStruct.new(:extra_state => OpenStruct.new)
55
- tag_parse("@!group foo", nil, handler)
56
- expect(handler.extra_state.group).to eq 'foo'
57
- end
58
- end
59
- end
60
-
61
- RSpec.describe YARD::Tags::EndGroupDirective do
62
- describe "#call" do
63
- it "does nothing if handler=nil" do
64
- tag_parse("@!endgroup foo")
65
- end
66
-
67
- it "sets group value in parser state (with handler)" do
68
- handler = OpenStruct.new(:extra_state => OpenStruct.new(:group => "foo"))
69
- tag_parse("@!endgroup", nil, handler)
70
- expect(handler.extra_state.group).to be nil
71
- end
72
- end
73
- end
74
-
75
- RSpec.describe YARD::Tags::MacroDirective do
76
- def handler
77
- OpenStruct.new(:call_params => %w(a b c),
78
- :caller_method => 'foo',
79
- :scope => :instance, :visibility => :public,
80
- :namespace => P('Foo::Bar'),
81
- :parser => OpenStruct.new(:file => "(stdin)", :line => 1),
82
- :statement => OpenStruct.new(:source => 'foo :a, :b, :c'))
83
- end
84
-
85
- after(:all) { Registry.clear }
86
-
87
- describe "#call" do
88
- it "defines new macro when [new] is provided" do
89
- tag_parse("@!macro [new] foo\n foo")
90
- expect(CodeObjects::MacroObject.find('foo').macro_data).to eq 'foo'
91
- end
92
-
93
- it "defines new macro if text block is provided" do
94
- tag_parse("@!macro bar\n bar")
95
- expect(CodeObjects::MacroObject.find('bar').macro_data).to eq 'bar'
96
- end
97
-
98
- it "expands macros and return #expanded_text to tag parser" do
99
- tag_parse("@!macro [new] foo\n foo")
100
- expect(tag_parse("@!macro foo").text).to eq 'foo'
101
- end
102
-
103
- it "does not expand new macro if docstring is unattached" do
104
- expect(tag_parse("@!macro [new] foo\n foo").text).not_to eq 'foo'
105
- end
106
-
107
- it "expands new anonymous macro even if docstring is unattached" do
108
- expect(tag_parse("@!macro\n foo").text).to eq 'foo'
109
- end
110
-
111
- it "allows multiple macros to be expanded" do
112
- tag_parse("@!macro [new] foo\n foo")
113
- tag_parse("@!macro bar\n bar")
114
- expect(tag_parse("@!macro foo\n@!macro bar").text).to eq "foo\nbar"
115
- end
116
-
117
- it "allows anonymous macros" do
118
- tag_parse("@!macro\n a b c", nil, handler)
119
- expect(@parser.text).to eq 'a b c'
120
- end
121
-
122
- it "expands call_params and caller_method using $N when handler is provided" do
123
- tag_parse("@!macro\n $1 $2 $3", nil, handler)
124
- expect(@parser.text).to eq 'a b c'
125
- end
126
-
127
- it "attaches macro to method if one exists" do
128
- tag_parse("@!macro [attach] attached\n $1 $2 $3", nil, handler)
129
- macro = CodeObjects::MacroObject.find('attached')
130
- expect(macro.method_object).to eq P('Foo::Bar.foo')
131
- end
132
-
133
- it "does not expand new attached macro if defined on class method" do
134
- baz = CodeObjects::MethodObject.new(P('Foo::Bar'), :baz, :class)
135
- expect(baz.visibility).to eq :public
136
- tag_parse("@!macro [attach] attached2\n @!visibility private", baz, handler)
137
- macro = CodeObjects::MacroObject.find('attached2')
138
- expect(macro.method_object).to eq P('Foo::Bar.baz')
139
- expect(baz.visibility).to eq :public
140
- end
141
-
142
- it "expands macro if defined on class method and there is no data block" do
143
- tag_parse("@!macro [new] attached3\n expanded_data")
144
- baz = CodeObjects::MethodObject.new(P('Foo::Bar'), :baz, :class)
145
- doc = DocstringParser.new.parse('@!macro attached3', baz, handler).to_docstring
146
- expect(doc).to eq 'expanded_data'
147
- end
148
-
149
- it "does not attach macros to class/modules but creates macro" do
150
- YARD::Registry.clear
151
- YARD.parse_string "module Foo; end"
152
- tag_parse("@!macro [attach] attached4\n $1 $2 $3", YARD::Registry.at('Foo'), handler)
153
- macro = CodeObjects::MacroObject.find('attached4')
154
- expect(macro.method_object).to eq nil
155
- expect(log.io.string).to match(/Attaching macros to non-methods is unsupported/)
156
- end
157
-
158
- it "does not attempt to expand macro values if handler = nil" do
159
- tag_parse("@!macro [attach] xyz\n $1 $2 $3")
160
- end
161
- end
162
- end
163
-
164
- RSpec.describe YARD::Tags::MethodDirective do
165
- describe "#call" do
166
- after { Registry.clear }
167
-
168
- it "uses entire docstring if no indented data is found" do
169
- YARD.parse_string <<-eof
170
- class Foo
171
- # @!method foo
172
- # @!method bar
173
- # @!scope class
174
- end
175
- eof
176
- expect(Registry.at('Foo.foo')).to be_a(CodeObjects::MethodObject)
177
- expect(Registry.at('Foo.bar')).to be_a(CodeObjects::MethodObject)
178
- end
179
-
180
- it "handles indented block text in @!method" do
181
- YARD.parse_string <<-eof
182
- # @!method foo(a)
183
- # Docstring here
184
- # @return [String] the foo
185
- # Ignore this
186
- # @param [String] a
187
- eof
188
- foo = Registry.at('#foo')
189
- expect(foo.docstring).to eq "Docstring here"
190
- expect(foo.docstring.tag(:return)).not_to be nil
191
- expect(foo.tag(:param)).to be nil
192
- end
193
-
194
- it "executes directives on object in indented block" do
195
- YARD.parse_string <<-eof
196
- class Foo
197
- # @!method foo(a)
198
- # @!scope class
199
- # @!visibility private
200
- # @!method bar
201
- # Hello
202
- # Ignore this
203
- end
204
- eof
205
- foo = Registry.at('Foo.foo')
206
- expect(foo.visibility).to eq :private
207
- bar = Registry.at('Foo#bar')
208
- expect(bar.visibility).to eq :public
209
- end
210
-
211
- it "is able to define multiple @methods in docstring" do
212
- YARD.parse_string <<-eof
213
- class Foo
214
- # @!method foo1
215
- # Docstring1
216
- # @!method foo2
217
- # Docstring2
218
- # @!method foo3
219
- # @!scope class
220
- # Docstring3
221
- end
222
- eof
223
- foo1 = Registry.at('Foo#foo1')
224
- foo2 = Registry.at('Foo#foo2')
225
- foo3 = Registry.at('Foo.foo3')
226
- expect(foo1.docstring).to eq 'Docstring1'
227
- expect(foo2.docstring).to eq 'Docstring2'
228
- expect(foo3.docstring).to eq 'Docstring3'
229
- end
230
-
231
- it "defines the method inside namespace if attached to namespace object" do
232
- YARD.parse_string <<-eof
233
- module Foo
234
- # @!method foo
235
- # Docstring1
236
- # @!method bar
237
- # Docstring2
238
- class Bar
239
- end
240
- end
241
- eof
242
- expect(Registry.at('Foo::Bar#foo').docstring).to eq 'Docstring1'
243
- expect(Registry.at('Foo::Bar#bar').docstring).to eq 'Docstring2'
244
- end
245
-
246
- it "sets scope to class if signature has 'self.' prefix" do
247
- YARD.parse_string <<-eof
248
- # @!method self.foo
249
- # @!method self. bar
250
- # @!method self.baz()
251
- class Foo
252
- end
253
- eof
254
- %w(foo bar baz).each do |name|
255
- expect(Registry.at("Foo.#{name}")).to be_a(CodeObjects::MethodObject)
256
- end
257
- end
258
-
259
- it "defines parameters from signature" do
260
- YARD.parse_string <<-eof
261
- # @!method foo(a, b, c = nil)
262
- eof
263
- expect(Registry.at('#foo').parameters).to eq [['a', nil], ['b', nil], ['c', 'nil']]
264
- end
265
-
266
- it "is able to define method with module scope (module function)" do
267
- YARD.parse_string <<-eof
268
- # @!method foo
269
- # @!scope module
270
- # This is a docstring
271
- # @return [Boolean] whether this is true
272
- class Foo
273
- end
274
- eof
275
- foo_c = Registry.at('Foo.foo')
276
- foo_i = Registry.at('Foo#foo')
277
- expect(foo_c).not_to be nil
278
- expect(foo_i).not_to be nil
279
- expect(foo_c).to be_module_function
280
- expect(foo_c.docstring).to eq foo_i.docstring
281
- expect(foo_c.tag(:return).text).to eq foo_i.tag(:return).text
282
- end
283
- end
284
- end
285
-
286
- RSpec.describe YARD::Tags::AttributeDirective do
287
- describe "#call" do
288
- after { Registry.clear }
289
-
290
- it "uses entire docstring if no indented data is found" do
291
- YARD.parse_string <<-eof
292
- class Foo
293
- # @!attribute foo
294
- # @!attribute bar
295
- # @!scope class
296
- end
297
- eof
298
- expect(Registry.at('Foo.foo')).to be_reader
299
- expect(Registry.at('Foo.bar')).to be_reader
300
- end
301
-
302
- it "handles indented block in @!attribute" do
303
- YARD.parse_string <<-eof
304
- # @!attribute foo
305
- # Docstring here
306
- # @return [String] the foo
307
- # Ignore this
308
- # @param [String] a
309
- eof
310
- foo = Registry.at('#foo')
311
- expect(foo.is_attribute?).to be true
312
- expect(foo.docstring).to eq "Docstring here"
313
- expect(foo.docstring.tag(:return)).not_to be nil
314
- expect(foo.tag(:param)).to be nil
315
- end
316
-
317
- it "is able to define multiple @attributes in docstring" do
318
- YARD.parse_string <<-eof
319
- class Foo
320
- # @!attribute [r] foo1
321
- # Docstring1
322
- # @!attribute [w] foo2
323
- # Docstring2
324
- # @!attribute foo3
325
- # @!scope class
326
- # Docstring3
327
- end
328
- eof
329
- foo1 = Registry.at('Foo#foo1')
330
- foo2 = Registry.at('Foo#foo2=')
331
- foo3 = Registry.at('Foo.foo3')
332
- foo4 = Registry.at('Foo.foo3=')
333
- expect(foo1).to be_reader
334
- expect(foo2).to be_writer
335
- expect(foo3).to be_reader
336
- expect(foo1.docstring).to eq 'Docstring1'
337
- expect(foo2.docstring).to eq 'Docstring2'
338
- expect(foo3.docstring).to eq 'Docstring3'
339
- expect(foo4).to be_writer
340
- expect(foo1.attr_info[:write]).to be nil
341
- expect(foo2.attr_info[:read]).to be nil
342
- end
343
-
344
- it "defines the attr inside namespace if attached to namespace object" do
345
- YARD.parse_string <<-eof
346
- module Foo
347
- # @!attribute [r] foo
348
- # @!attribute [r] bar
349
- class Bar
350
- end
351
- end
352
- eof
353
- expect(Registry.at('Foo::Bar#foo')).to be_reader
354
- expect(Registry.at('Foo::Bar#bar')).to be_reader
355
- end
356
- end
357
-
358
- it "sets scope to class if signature has 'self.' prefix" do
359
- YARD.parse_string <<-eof
360
- # @!attribute self.foo
361
- # @!attribute self. bar
362
- # @!attribute self.baz
363
- class Foo
364
- end
365
- eof
366
- %w(foo bar baz).each do |name|
367
- expect(Registry.at("Foo.#{name}")).to be_reader
368
- end
369
- end
370
- end
371
-
372
- RSpec.describe YARD::Tags::ScopeDirective do
373
- describe "#call" do
374
- after { Registry.clear }
375
-
376
- it "sets state on tag parser if object = nil" do
377
- tag_parse("@!scope class")
378
- expect(@parser.state.scope).to eq :class
379
- end
380
-
381
- it "sets state on tag parser if object is namespace" do
382
- object = CodeObjects::ClassObject.new(:root, 'Foo')
383
- tag_parse("@!scope class", object)
384
- expect(object[:scope]).to be nil
385
- expect(@parser.state.scope).to eq :class
386
- end
387
-
388
- it "sets scope on object if object is a method object" do
389
- object = CodeObjects::MethodObject.new(:root, 'foo')
390
- tag_parse("@!scope class", object)
391
- expect(object.scope).to eq :class
392
- end
393
-
394
- %w(class instance module).each do |type|
395
- it "allows #{type} as value" do
396
- tag_parse("@!scope #{type}")
397
- expect(@parser.state.scope).to eq type.to_sym
398
- end
399
- end
400
-
401
- %w(invalid foo FOO CLASS INSTANCE).each do |type|
402
- it "does not allow #{type} as value" do
403
- tag_parse("@!scope #{type}")
404
- expect(@parser.state.scope).to be nil
405
- end
406
- end
407
- end
408
- end
409
-
410
- RSpec.describe YARD::Tags::VisibilityDirective do
411
- describe "#call" do
412
- after { Registry.clear }
413
-
414
- it "sets visibility on tag parser if object = nil" do
415
- tag_parse("@!visibility private")
416
- expect(@parser.state.visibility).to eq :private
417
- end
418
-
419
- it "sets state on tag parser if object is namespace" do
420
- object = CodeObjects::ClassObject.new(:root, 'Foo')
421
- tag_parse("@!visibility protected", object)
422
- expect(object.visibility).to eq :protected
423
- expect(@parser.state.visibility).to be nil
424
- end
425
-
426
- it "sets visibility on object if object is a method object" do
427
- object = CodeObjects::MethodObject.new(:root, 'foo')
428
- tag_parse("@!visibility private", object)
429
- expect(object.visibility).to eq :private
430
- end
431
-
432
- %w(public private protected).each do |type|
433
- it "allows #{type} as value" do
434
- tag_parse("@!visibility #{type}")
435
- expect(@parser.state.visibility).to eq type.to_sym
436
- end
437
- end
438
-
439
- %w(invalid foo FOO PRIVATE INSTANCE).each do |type|
440
- it "does not allow #{type} as value" do
441
- tag_parse("@!visibility #{type}")
442
- expect(@parser.state.visibility).to be nil
443
- end
444
- end
445
-
446
- it "updates visibility on future methods" do
447
- Registry.clear
448
- YARD.parse_string <<-eof
449
- class Foo
450
- # @!visibility private
451
-
452
-
453
- def foo; end
454
- def bar; end
455
- def baz; end
456
- end
457
- eof
458
- %w(foo bar baz).each do |name|
459
- expect(Registry.at("Foo##{name}").visibility).to eq :private
460
- end
461
- end if YARD::Parser::SourceParser.parser_type == :ruby
462
- end
463
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::Tags::Library do
4
- def tag(docstring)
5
- Docstring.new(docstring).tags.first
6
- end
7
-
8
- describe "#see_tag" do
9
- it "takes a URL" do
10
- expect(tag("@see http://example.com").name).to eq "http://example.com"
11
- end
12
-
13
- it "takes an object path" do
14
- expect(tag("@see String#reverse").name).to eq "String#reverse"
15
- end
16
-
17
- it "takes a description after the url/object" do
18
- tag = tag("@see http://example.com An Example Site")
19
- expect(tag.name).to eq "http://example.com"
20
- expect(tag.text).to eq "An Example Site"
21
- end
22
- end
23
-
24
- describe ".define_tag" do
25
- it "allows defining tags with '.' in the name (x.y.z defines method x_y_z)" do
26
- Tags::Library.define_tag("foo", 'x.y.z')
27
- Tags::Library.define_tag("foo2", 'x.y.zz', Tags::OverloadTag)
28
- expect(Tags::Library.instance.method(:x_y_z_tag)).not_to be nil
29
- expect(Tags::Library.instance.method(:x_y_zz_tag)).not_to be nil
30
- expect(tag('@x.y.z foo bar').text).to eq 'foo bar'
31
- expect(tag('@x.y.zz foo(bar)').signature).to eq 'foo(bar)'
32
- end
33
- end
34
-
35
- describe "#tag.explain_types" do
36
- it "can explain tag types" do
37
- expect(tag("@return [A, B<String>]").explain_types).to eq "an A; a B of (Strings)"
38
- end
39
-
40
- it "returns nil if no types present" do
41
- expect(tag("@return").explain_types).to eq nil
42
- end
43
-
44
- it "returns nil if types are not parseable" do
45
- expect(tag("@return [$]").explain_types).to eq nil
46
- end
47
- end
48
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::Tags::OverloadTag do
4
- before do
5
- @tag = Tags::OverloadTag.new(:overload, <<-'eof')
6
- def bar(a, b = 1, &block)
7
- Hello world
8
- @param a [String]
9
- @return [String]
10
- eof
11
- end
12
-
13
- it "parses the first line as a method signature" do
14
- expect(@tag.signature).to eq "def bar(a, b = 1, &block)"
15
- expect(@tag.parameters).to eq [['a', nil], ['b', "1"], ['&block', nil]]
16
- end
17
-
18
- it "parses the rest of the text as a new Docstring" do
19
- expect(@tag.docstring).to be_instance_of(Docstring)
20
- expect(@tag.docstring).to eq "Hello world"
21
- end
22
-
23
- it "sets Docstring's object after #object= is called" do
24
- m = double(:object)
25
- @tag.object = m
26
- expect(@tag.docstring.object).to eq m
27
- end
28
-
29
- it "responds to #tag, #tags and #has_tag?" do
30
- @tag.object = double(:object)
31
- expect(@tag.tags.size).to eq 2
32
- expect(@tag.tag(:param).name).to eq "a"
33
- expect(@tag.has_tag?(:return)).to be true
34
- end
35
-
36
- it "is not a CodeObjects::Base when not hooked up to an object" do
37
- @tag.object = nil
38
- expect(@tag.is_a?(CodeObjects::Base)).to be false
39
- end
40
-
41
- it "is a CodeObjects::Base when hooked up to an object" do
42
- @tag.object = double(:object)
43
- expect(@tag.object).to receive(:is_a?).at_least(3).times.with(CodeObjects::Base).and_return(true)
44
- expect(@tag.is_a?(CodeObjects::Base)).to be true
45
- expect(@tag.is_a?(CodeObjects::Base)).to be true
46
- expect(CodeObjects::Base === @tag).to be true
47
- end
48
-
49
- it "does not parse 'def' out of method name" do
50
- tag = Tags::OverloadTag.new(:overload, "default")
51
- expect(tag.signature).to eq "default"
52
- end
53
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::Tags::RefTagList do
4
- before { YARD::Registry.clear }
5
-
6
- it "accepts symbol or string as owner's path and convert it into a proxy" do
7
- t = Tags::RefTagList.new('author', :String)
8
- expect(t.owner).to eq P(:String)
9
- end
10
-
11
- it "accepts proxy object as owner" do
12
- t = Tags::RefTagList.new('author', P(:String))
13
- expect(t.owner).to eq P(:String)
14
- end
15
-
16
- it "returns tags from a proxy object" do
17
- o = CodeObjects::ClassObject.new(:root, :String)
18
- t = Tags::Tag.new(:author, 'foo')
19
- o.docstring.add_tag(t)
20
-
21
- ref = Tags::RefTagList.new('author', :String)
22
- expect(ref.tags).to eq [t]
23
- expect(ref.tags.first.text).to eq 'foo'
24
- end
25
-
26
- it "returns named tags from a proxy object" do
27
- o = CodeObjects::ClassObject.new(:root, :String)
28
- p1 = Tags::Tag.new(:param, 'bar1', nil, 'foo')
29
- p2 = Tags::Tag.new(:param, 'bar2', nil, 'foo')
30
- p3 = Tags::Tag.new(:param, 'bar3', nil, 'bar')
31
- t1 = Tags::Tag.new(:return, 'blah')
32
- o.docstring.add_tag(p1, t1, p2, p3)
33
-
34
- ref = Tags::RefTagList.new('param', :String, 'foo')
35
- expect(ref.tags).to eq [p1, p2]
36
- expect(ref.tags.first.text).to eq 'bar1'
37
- end
38
-
39
- it "all tags should respond to #owner and be a RefTag" do
40
- o = CodeObjects::ClassObject.new(:root, :String)
41
- p1 = Tags::Tag.new(:param, 'bar1', nil, 'foo')
42
- p2 = Tags::Tag.new(:param, 'bar2', nil, 'foo')
43
- p3 = Tags::Tag.new(:param, 'bar3', nil, 'bar')
44
- t1 = Tags::Tag.new(:return, 'blah')
45
- o.docstring.add_tag(p1, t1, p2, p3)
46
-
47
- ref = Tags::RefTagList.new('param', :String)
48
- ref.tags.each do |t|
49
- expect(t).to be_kind_of(Tags::RefTag)
50
- expect(t.owner).to eq o
51
- end
52
- end
53
- end