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,327 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + "/spec_helper"
3
-
4
- RSpec.describe YARD::Handlers::C::MethodHandler do
5
- it "registers methods" do
6
- parse_init <<-eof
7
- mFoo = rb_define_module("Foo");
8
- rb_define_method(mFoo, "bar", bar, 0);
9
- eof
10
- expect(Registry.at('Foo#bar')).not_to be nil
11
- expect(Registry.at('Foo#bar').visibility).to eq :public
12
- end
13
-
14
- it "registers private methods" do
15
- parse_init <<-eof
16
- mFoo = rb_define_module("Foo");
17
- rb_define_private_method(mFoo, "bar", bar, 0);
18
- eof
19
- expect(Registry.at('Foo#bar')).not_to be nil
20
- expect(Registry.at('Foo#bar').visibility).to eq :private
21
- end
22
-
23
- it "registers singleton methods" do
24
- parse_init <<-eof
25
- mFoo = rb_define_module("Foo");
26
- rb_define_singleton_method(mFoo, "bar", bar, 0);
27
- eof
28
- expect(Registry.at('Foo.bar')).not_to be nil
29
- expect(Registry.at('Foo.bar').visibility).to eq :public
30
- end
31
-
32
- it "registers module functions" do
33
- parse <<-eof
34
- /* DOCSTRING
35
- * @return [String] foo!
36
- */
37
- static VALUE bar(VALUE self) { x(); y(); z(); }
38
-
39
- void Init_Foo() {
40
- mFoo = rb_define_module("Foo");
41
- rb_define_module_function(mFoo, "bar", bar, 0);
42
- }
43
- eof
44
- bar_c = Registry.at('Foo.bar')
45
- bar_i = Registry.at('Foo#bar')
46
- expect(bar_c).to be_module_function
47
- expect(bar_c.visibility).to eq :public
48
- expect(bar_c.docstring).to eq "DOCSTRING"
49
- expect(bar_c.tag(:return).object).to eq bar_c
50
- expect(bar_c.source).to eq "static VALUE bar(VALUE self) { x(); y(); z(); }"
51
- expect(bar_i).not_to be_module_function
52
- expect(bar_i.visibility).to eq :private
53
- expect(bar_i.docstring).to eq "DOCSTRING"
54
- expect(bar_i.tag(:return).object).to eq bar_i
55
- expect(bar_i.source).to eq bar_c.source
56
- end
57
-
58
- it "registers global functions into Kernel" do
59
- parse_init 'rb_define_global_function("bar", bar, 0);'
60
- expect(Registry.at('Kernel#bar')).not_to be nil
61
- end
62
-
63
- it "looks for symbol containing method source" do
64
- parse <<-eof
65
- static VALUE foo(VALUE self) { x(); y(); z(); }
66
- VALUE bar() { a(); b(); c(); }
67
- void Init_Foo() {
68
- mFoo = rb_define_module("Foo");
69
- rb_define_method(mFoo, "foo", foo, 0);
70
- rb_define_method(mFoo, "bar", bar, 0);
71
- }
72
- eof
73
- foo = Registry.at('Foo#foo')
74
- bar = Registry.at('Foo#bar')
75
- expect(foo.source).to eq "static VALUE foo(VALUE self) { x(); y(); z(); }"
76
- expect(foo.file).to eq '(stdin)'
77
- expect(foo.line).to eq 1
78
- expect(bar.source).to eq "VALUE bar() { a(); b(); c(); }"
79
- expect(bar.file).to eq '(stdin)'
80
- expect(bar.line).to eq 2
81
- end
82
-
83
- it "finds docstrings attached to method symbols" do
84
- parse <<-eof
85
- /* DOCSTRING */
86
- static VALUE foo(VALUE self) { x(); y(); z(); }
87
- void Init_Foo() {
88
- mFoo = rb_define_module("Foo");
89
- rb_define_method(mFoo, "foo", foo, 0);
90
- }
91
- eof
92
- foo = Registry.at('Foo#foo')
93
- expect(foo.docstring).to eq 'DOCSTRING'
94
- end
95
-
96
- it "uses declaration comments as docstring if there are no others" do
97
- parse <<-eof
98
- static VALUE foo(VALUE self) { x(); y(); z(); }
99
- void Init_Foo() {
100
- mFoo = rb_define_module("Foo");
101
- /* DOCSTRING */
102
- rb_define_method(mFoo, "foo", foo, 0);
103
- // DOCSTRING!
104
- rb_define_method(mFoo, "bar", bar, 0);
105
- }
106
- eof
107
- foo = Registry.at('Foo#foo')
108
- expect(foo.docstring).to eq 'DOCSTRING'
109
- bar = Registry.at('Foo#bar')
110
- expect(bar.docstring).to eq 'DOCSTRING!'
111
- end
112
-
113
- it "looks for symbols in other file" do
114
- other = <<-eof
115
- /* DOCSTRING! */
116
- static VALUE foo() { x(); }
117
- eof
118
- expect(File).to receive(:read).with('other.c').and_return(other)
119
- parse <<-eof
120
- void Init_Foo() {
121
- mFoo = rb_define_module("Foo");
122
- rb_define_method(mFoo, "foo", foo, 0); // in other.c
123
- }
124
- eof
125
- foo = Registry.at('Foo#foo')
126
- expect(foo.docstring).to eq 'DOCSTRING!'
127
- expect(foo.file).to eq 'other.c'
128
- expect(foo.line).to eq 2
129
- expect(foo.source).to eq 'static VALUE foo() { x(); }'
130
- end
131
-
132
- it "allows extra file to include /'s and other filename characters" do
133
- expect(File).to receive(:read).at_least(1).times.with('ext/a-file.c').and_return(<<-eof)
134
- /* FOO */
135
- VALUE foo(VALUE x) { int value = x; }
136
-
137
- /* BAR */
138
- VALUE bar(VALUE x) { int value = x; }
139
- eof
140
- parse_init <<-eof
141
- rb_define_method(rb_cFoo, "foo", foo, 1); /* in ext/a-file.c */
142
- rb_define_global_function("bar", bar, 1); /* in ext/a-file.c */
143
- eof
144
- expect(Registry.at('Foo#foo').docstring).to eq 'FOO'
145
- expect(Registry.at('Kernel#bar').docstring).to eq 'BAR'
146
- end
147
-
148
- it "warns if other file can't be found" do
149
- expect(log).to receive(:warn).with(/Missing source file `other.c' when parsing Foo#foo/)
150
- parse <<-eof
151
- void Init_Foo() {
152
- mFoo = rb_define_module("Foo");
153
- rb_define_method(mFoo, "foo", foo, 0); // in other.c
154
- }
155
- eof
156
- end
157
-
158
- it "looks at override comments for docstring" do
159
- parse <<-eof
160
- /* Document-method: Foo::foo
161
- * Document-method: new
162
- * Document-method: Foo::Bar#baz
163
- * Foo bar!
164
- */
165
-
166
- // init comments
167
- void Init_Foo() {
168
- mFoo = rb_define_module("Foo");
169
- rb_define_method(mFoo, "foo", foo, 0);
170
- rb_define_method(mFoo, "initialize", foo, 0);
171
- mBar = rb_define_module_under(mFoo, "Bar");
172
- rb_define_method(mBar, "baz", foo, 0);
173
- }
174
- eof
175
- expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
176
- expect(Registry.at('Foo#initialize').docstring).to eq 'Foo bar!'
177
- expect(Registry.at('Foo::Bar#baz').docstring).to eq 'Foo bar!'
178
- end
179
-
180
- it "looks at overrides in other files" do
181
- other = <<-eof
182
- /* Document-method: Foo::foo
183
- * Document-method: new
184
- * Document-method: Foo::Bar#baz
185
- * Foo bar!
186
- */
187
- eof
188
- expect(File).to receive(:read).with('foo/bar/other.c').and_return(other)
189
- src = <<-eof
190
- void Init_Foo() {
191
- mFoo = rb_define_module("Foo");
192
- rb_define_method(mFoo, "foo", foo, 0); // in foo/bar/other.c
193
- rb_define_method(mFoo, "initialize", foo, 0); // in foo/bar/other.c
194
- mBar = rb_define_module_under(mFoo, "Bar"); // in foo/bar/other.c
195
- rb_define_method(mBar, "baz", foo, 0); // in foo/bar/other.c
196
- }
197
- eof
198
- parse(src, 'foo/bar/baz/init.c')
199
- expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
200
- expect(Registry.at('Foo#initialize').docstring).to eq 'Foo bar!'
201
- expect(Registry.at('Foo::Bar#baz').docstring).to eq 'Foo bar!'
202
- end
203
-
204
- it "adds return tag on methods ending in '?'" do
205
- parse <<-eof
206
- /* DOCSTRING */
207
- static VALUE foo(VALUE self) { x(); y(); z(); }
208
- void Init_Foo() {
209
- mFoo = rb_define_module("Foo");
210
- rb_define_method(mFoo, "foo?", foo, 0);
211
- }
212
- eof
213
- foo = Registry.at('Foo#foo?')
214
- expect(foo.docstring).to eq 'DOCSTRING'
215
- expect(foo.tag(:return).types).to eq ['Boolean']
216
- expect(foo.tags(:return).size).to eq 1
217
- end
218
-
219
- it "does not add return tag if return tags exist" do
220
- parse <<-eof
221
- // @return [String] foo
222
- static VALUE foo(VALUE self) { x(); y(); z(); }
223
- void Init_Foo() {
224
- mFoo = rb_define_module("Foo");
225
- rb_define_method(mFoo, "foo?", foo, 0);
226
- }
227
- eof
228
- foo = Registry.at('Foo#foo?')
229
- expect(foo.tag(:return).types).to eq ['String']
230
- expect(foo.tags(:return).size).to eq 1
231
- end
232
-
233
- it "handles casted method names" do
234
- parse_init <<-eof
235
- mFoo = rb_define_module("Foo");
236
- rb_define_method(mFoo, "bar", (METHOD)bar, 0);
237
- rb_define_global_function("baz", (METHOD)baz, 0);
238
- eof
239
- expect(Registry.at('Foo#bar')).not_to be nil
240
- expect(Registry.at('Kernel#baz')).not_to be nil
241
- end
242
-
243
- it "extracts at regular method parameters from C function signatures" do
244
- parse <<-eof
245
- static VALUE noargs_func(VALUE self) { return Qnil; }
246
- static VALUE twoargs_func(VALUE self, VALUE a, VALUE b) { return a; }
247
- void Init_Foo() {
248
- mFoo = rb_define_module("Foo");
249
- rb_define_method(mFoo, "noargs", noargs_func, 0);
250
- rb_define_method(mFoo, "twoargs", twoargs_func, 2);
251
- }
252
- eof
253
- expect(Registry.at('Foo#noargs').parameters).to be_empty
254
- expect(Registry.at('Foo#twoargs').parameters).to eq [['a', nil], ['b', nil]]
255
- end
256
-
257
- it "extracts at varargs method parameters from C function signatures" do
258
- parse <<-eof
259
- static VALUE varargs_func(int argc, VALUE *argv, VALUE self) { return self; }
260
- /* let's see if parser is robust in the face of strange spacing */
261
- static VALUE varargs_func2( int argc , VALUE
262
- * argv ,VALUE self )
263
-
264
- {return self;}
265
- void Init_Foo() {
266
- mFoo = rb_define_module("Foo");
267
- rb_define_method(mFoo, "varargs", varargs_func, -1);
268
- rb_define_method( mFoo ,"varargs2",varargs_func2 ,-1);
269
- }
270
- eof
271
- expect(Registry.at('Foo#varargs').parameters).to eq [['*args', nil]]
272
- expect(Registry.at('Foo#varargs2').parameters).to eq [['*args', nil]]
273
- end
274
-
275
- it "is not too strict or too loose about matching override comments to methods" do
276
- parse <<-eof
277
- /* Document-method: Foo::foo
278
- * Document-method: new
279
- * Document-method: Foo::Bar#baz
280
- * Foo bar!
281
- */
282
-
283
- void Init_Foo() {
284
- mFoo = rb_define_module("Foo");
285
- mBar = rb_define_module_under(mFoo, "Bar");
286
-
287
- rb_define_method(mFoo, "foo", foo, 0);
288
- rb_define_singleton_method(mFoo, "foo", foo, 0);
289
- rb_define_method(mBar, "foo", foo, 0);
290
- rb_define_singleton_method(mBar, "foo", foo, 0);
291
-
292
- rb_define_method(mFoo, "initialize", foo, 0);
293
- rb_define_method(mBar, "initialize", foo, 0);
294
-
295
- rb_define_method(mFoo, "baz", foo, 0);
296
- rb_define_singleton_method(mFoo, "baz", foo, 0);
297
- rb_define_method(mBar, "baz", foo, 0);
298
- rb_define_singleton_method(mBar, "baz", foo, 0);
299
- }
300
- eof
301
- expect(Registry.at('Foo#foo').docstring).to eq 'Foo bar!'
302
- expect(Registry.at('Foo.foo').docstring).to eq 'Foo bar!'
303
- expect(Registry.at('Foo::Bar#foo').docstring).to be_empty
304
- expect(Registry.at('Foo::Bar.foo').docstring).to be_empty
305
- expect(Registry.at('Foo#initialize').docstring).to eq 'Foo bar!'
306
- expect(Registry.at('Foo::Bar#initialize').docstring).to eq 'Foo bar!'
307
- expect(Registry.at('Foo#baz').docstring).to be_empty
308
- expect(Registry.at('Foo.baz').docstring).to be_empty
309
- expect(Registry.at('Foo::Bar#baz').docstring).to eq 'Foo bar!'
310
- expect(Registry.at('Foo::Bar.baz').docstring).to be_empty
311
- end
312
-
313
- it "recognizes core Ruby classes and modules provided by ruby.h" do
314
- parse_init <<-eof
315
- rb_define_method(rb_cFixnum, "popcount", fix_popcount, 0);
316
- rb_define_private_method(rb_mKernel, "pp", obj_pp, 0);
317
- rb_define_method(rb_mEnumerable, "to_hash", enum_to_hash, 0);
318
- eof
319
- expect(Registry.at('Fixnum').type).to eq :class
320
- expect(Registry.at('Fixnum#popcount').type).to eq :method
321
- expect(Registry.at('Object').type).to eq :class
322
- # Methods defined on Kernel are treated as if they were defined on Object
323
- expect(Registry.at('Object#pp').type).to eq :method
324
- expect(Registry.at('Enumerable').type).to eq :module
325
- expect(Registry.at('Enumerable#to_hash').type).to eq :method
326
- end
327
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + "/spec_helper"
3
-
4
- RSpec.describe YARD::Handlers::C::MixinHandler do
5
- it "adds includes to modules or classes" do
6
- parse_init <<-eof
7
- mFoo = rb_define_module("Foo");
8
- cBar = rb_define_class("Bar", rb_cObject);
9
- mBaz = rb_define_module("Baz");
10
- rb_include_module(cBar, mFoo);
11
- rb_include_module(mBaz, mFoo);
12
- eof
13
- foo = Registry.at('Foo')
14
- bar = Registry.at('Bar')
15
- baz = Registry.at('Baz')
16
- expect(bar.mixins(:instance)).to eq [foo]
17
- expect(baz.mixins(:instance)).to eq [foo]
18
- end
19
-
20
- it "adds include as proxy if symbol lookup fails" do
21
- parse_init <<-eof
22
- mFoo = rb_define_module("Foo");
23
- rb_include_module(mFoo, mXYZ);
24
- eof
25
- foo = Registry.at('Foo')
26
- expect(foo.mixins(:instance)).to eq [P('XYZ')]
27
- end
28
-
29
- it "fails if mixin variable cannot be detected" do
30
- with_parser(:c) do
31
- undoc_error <<-eof
32
- void Init_Foo() {
33
- VALUE noprefix;
34
-
35
- mFoo = rb_define_module("Foo");
36
- // YARD doesn't understand this
37
- noprefix = rb_const_get(rb_cObject, rb_intern("Observable"));
38
-
39
- rb_include_module(mFoo, noprefix);
40
- }
41
- eof
42
- end
43
- end
44
- end
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + "/spec_helper"
3
-
4
- RSpec.describe YARD::Handlers::C::ClassHandler do
5
- it "registers modules" do
6
- parse_init 'mFoo = rb_define_module("Foo");'
7
- expect(Registry.at('Foo').type).to eq :module
8
- end
9
-
10
- it "registers classes under namespaces" do
11
- parse_init <<-EOF
12
- mBar = rb_define_module("Bar");
13
- mFoo = rb_define_module_under(mBar, "Foo");
14
- EOF
15
- expect(Registry.at('Bar::Foo').type).to eq :module
16
- end
17
-
18
- it "remembers symbol defined with class" do
19
- parse_init(<<-eof)
20
- cXYZ = rb_define_module("Foo");
21
- rb_define_method(cXYZ, "bar", bar, 0);
22
- eof
23
- expect(Registry.at('Foo').type).to eq :module
24
- expect(Registry.at('Foo#bar')).not_to be nil
25
- end
26
-
27
- it "does not associate declaration comments as module docstring" do
28
- parse_init(<<-eof)
29
- /* Docstring! */
30
- mFoo = rb_define_module("Foo");
31
- eof
32
- expect(Registry.at('Foo').docstring).to be_blank
33
- end
34
-
35
- it "associates a file with the declaration" do
36
- parse_init(<<-eof)
37
- mFoo = rb_define_module("Foo");
38
- eof
39
- expect(Registry.at('Foo').file).to eq '(stdin)'
40
- expect(Registry.at('Foo').line).to eq 2
41
- end
42
-
43
- it "resolves namespace variable names across multiple files" do
44
- parse_multi_file_init(
45
- 'mBar = rb_define_module_under(mFoo, "Bar");',
46
- 'mFoo = rb_define_module("Foo");'
47
- )
48
-
49
- expect(Registry.at('Foo::Bar').type).to eq :module
50
- end
51
-
52
- it "raises undoc error if a class is defined under a namespace that cannot be resolved" do
53
- with_parser(:c) do
54
- undoc_error <<-eof
55
- void Init_Foo() {
56
- mFoo = rb_define_class_under(invalid, "Foo", rb_cObject);
57
- }
58
- eof
59
- end
60
- end unless ENV['LEGACY']
61
-
62
- it "raises undoc error if a module is defined under a namespace that cannot be resolved" do
63
- with_parser(:c) do
64
- undoc_error <<-eof
65
- void Init_Foo() {
66
- mFoo = rb_define_module_under(invalid, "Foo");
67
- }
68
- eof
69
- end
70
- end unless ENV['LEGACY']
71
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + "/spec_helper"
3
-
4
- RSpec.describe YARD::Handlers::C::OverrideCommentHandler do
5
- [:class, :module].each do |type|
6
- it "handles Document-#{type}" do
7
- parse(<<-eof)
8
- void something;
9
- /* Document-#{type}: A
10
- * Foo bar baz
11
- */
12
- void
13
- eof
14
- expect(Registry.at('A').type).to eq type
15
- expect(Registry.at('A').docstring).to eq 'Foo bar baz'
16
- expect(Registry.at('A').file).to eq '(stdin)'
17
- expect(Registry.at('A').line).to eq 2
18
- end
19
- end
20
-
21
- it "handles multiple class/module combinations" do
22
- parse(<<-eof)
23
- /* Document-class: A
24
- * Document-class: B
25
- * Document-module: C
26
- * Foo bar baz
27
- */
28
- eof
29
- expect(Registry.at('A').docstring).to eq 'Foo bar baz'
30
- expect(Registry.at('B').docstring).to eq 'Foo bar baz'
31
- expect(Registry.at('C').docstring).to eq 'Foo bar baz'
32
- expect(Registry.at('C').type).to eq :module
33
- end
34
-
35
- it "handles Document-class with inheritance" do
36
- parse(<<-eof)
37
- /* Document-class: A < B
38
- * Foo bar baz
39
- */
40
- void
41
- eof
42
- obj = Registry.at('A')
43
- expect(obj.type).to eq :class
44
- expect(obj.docstring).to eq 'Foo bar baz'
45
- expect(obj.superclass).to eq P('B')
46
- end
47
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + "/spec_helper"
3
-
4
- RSpec.describe YARD::Handlers::C::PathHandler do
5
- it "tracks variable names defined under namespaces" do
6
- parse_init <<-eof
7
- mFoo = rb_define_module("Foo");
8
- cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
9
- rb_define_method(cBar, "foo", foo, 1);
10
- eof
11
- expect(Registry.at('Foo::Bar')).not_to be nil
12
- expect(Registry.at('Foo::Bar#foo')).not_to be nil
13
- end
14
-
15
- it "tracks variable names defined under namespaces" do
16
- parse_init <<-eof
17
- mFoo = rb_define_module("Foo");
18
- cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
19
- mBaz = rb_define_module_under(cBar, "Baz");
20
- rb_define_method(mBaz, "foo", foo, 1);
21
- eof
22
- expect(Registry.at('Foo::Bar::Baz')).not_to be nil
23
- expect(Registry.at('Foo::Bar::Baz#foo')).not_to be nil
24
- end
25
-
26
- it "handles rb_path2class() calls" do
27
- parse_init <<-eof
28
- somePath = rb_path2class("Foo::Bar::Baz")
29
- mFoo = rb_define_module("Foo");
30
- cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);
31
- mBaz = rb_define_module_under(cBar, "Baz");
32
- rb_define_method(somePath, "foo", foo, 1);
33
- eof
34
- expect(Registry.at('Foo::Bar::Baz#foo')).not_to be nil
35
- end
36
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- def parse(src, file = '(stdin)')
4
- YARD::Registry.clear
5
- parser = YARD::Parser::SourceParser.new(:c)
6
- parser.file = file
7
- parser.parse(StringIO.new(src))
8
- end
9
-
10
- def parse_init(src)
11
- YARD::Registry.clear
12
- YARD.parse_string("void Init_Foo() {\n#{src}\n}", :c)
13
- end
14
-
15
- def parse_multi_file_init(*srcs)
16
- YARD::Registry.clear
17
- srcs = srcs.map {|src| StringIO.new("void Init_Foo() {\n#{src}\n}") }
18
- orig_type = YARD::Parser::SourceParser.parser_type
19
- YARD::Parser::SourceParser.parser_type = :c
20
- YARD::Parser::OrderedParser.new(OpenStruct.new, srcs).parse
21
- ensure
22
- YARD::Parser::SourceParser.parser_type = orig_type
23
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe YARD::Handlers::C::StructHandler do
5
- after { Registry.clear }
6
-
7
- it "handles Struct class definitions" do
8
- parse_init <<-eof
9
- rb_cRange = rb_struct_define_without_accessor(
10
- "Range", rb_cFoo, range_alloc,
11
- "begin", "end", "excl", NULL);
12
- eof
13
- expect(Registry.at('Range').type).to eq :class
14
- expect(Registry.at('Range').superclass).to eq P(:Foo)
15
- end
16
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- RSpec.describe "YARD::Handlers::Ruby::#{LEGACY_PARSER ? "Legacy::" : ""}ClassConditionHandler" do
5
- before(:all) { parse_file :class_condition_handler_001, __FILE__ }
6
-
7
- def verify_method(*names)
8
- names.each {|name| expect(Registry.at("A##{name}")).not_to be nil }
9
- names.each {|name| expect(Registry.at("A##{name}not")).to be nil }
10
- end
11
-
12
- def no_undoc_error(code)
13
- expect { StubbedSourceParser.parse_string(code) }.not_to raise_error
14
- end
15
-
16
- it "parses all unless blocks for complex conditions" do
17
- verify_method :g
18
- end
19
-
20
- it "does not parse conditionals inside methods" do
21
- verify_method :h
22
- end
23
-
24
- it "only parses then block if condition is literal value `true`" do
25
- verify_method :p
26
- end
27
-
28
- it "only parses then block if condition is literal integer != 0" do
29
- verify_method :o
30
- end
31
-
32
- it "inverts block to parse for literal condition if it's an unless block" do
33
- verify_method :e
34
- end
35
-
36
- it "handles conditions such as 'defined? VALUE'" do
37
- verify_method :j, :k
38
- end
39
-
40
- it "parses all if/elsif blocks for complex conditions" do
41
- verify_method :a, :b, :c, :d
42
- end
43
-
44
- it "parses else block if condition is literal value `false`" do
45
- verify_method :q
46
- end
47
-
48
- it "only parses else block if condition is literal integer == 0" do
49
- verify_method :n
50
- end
51
-
52
- it "maintains visibility and scope state inside condition" do
53
- expect(Registry.at('A#m').visibility).to eq :private
54
- expect(Registry.at('A#mnot').visibility).to eq :private
55
- end
56
-
57
- it "does not fail on complex conditions" do
58
- expect(log).not_to receive(:warn)
59
- expect(log).not_to receive(:error)
60
- no_undoc_error "if defined?(A) && defined?(B); puts 'hi' end"
61
- no_undoc_error(<<-eof)
62
- (<<-TEST) unless defined?(ABCD_MODEL_TEST)
63
- 'String'
64
- TEST
65
- eof
66
- no_undoc_error "if caller.none? { |l| l =~ %r{lib/rails/generators\\.rb:(\\d+):in `lookup!'$} }; end"
67
- end
68
-
69
- it "only parses identifiers or namespaces from defined? expressions" do
70
- module A
71
- @@value = nil
72
- def self.b(value) @@value = value end
73
- def self.value; @@value end
74
- end
75
-
76
- YARD.parse_string <<-eof
77
- if defined? A.b(42).to_i
78
- class Foo; end
79
- else
80
- class Bar; end
81
- end
82
- eof
83
- expect(A.value).to be_nil
84
- expect(YARD::Registry.at('Foo')).not_to be_nil
85
- expect(YARD::Registry.at('Bar')).not_to be_nil
86
- end
87
- end