yard 0.9.24 → 0.9.25

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 (223) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +37 -24
  3. data/CHANGELOG.md +18 -3
  4. data/README.md +96 -101
  5. data/Rakefile +2 -0
  6. data/lib/yard/cli/diff.rb +4 -1
  7. data/lib/yard/cli/server.rb +22 -13
  8. data/lib/yard/code_objects/proxy.rb +2 -1
  9. data/lib/yard/globals.rb +1 -1
  10. data/lib/yard/handlers/c/base.rb +164 -129
  11. data/lib/yard/parser/ruby/ruby_parser.rb +6 -4
  12. data/lib/yard/registry_store.rb +1 -1
  13. data/lib/yard/templates/helpers/html_helper.rb +10 -3
  14. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +5 -4
  15. data/lib/yard/version.rb +1 -1
  16. data/tasks/update_error_map.rake +53 -0
  17. data/yard.gemspec +1 -1
  18. metadata +3 -207
  19. data/spec/cli/command_parser_spec.rb +0 -43
  20. data/spec/cli/command_spec.rb +0 -36
  21. data/spec/cli/config_spec.rb +0 -148
  22. data/spec/cli/diff_spec.rb +0 -254
  23. data/spec/cli/display_spec.rb +0 -30
  24. data/spec/cli/gems_spec.rb +0 -81
  25. data/spec/cli/graph_spec.rb +0 -18
  26. data/spec/cli/help_spec.rb +0 -22
  27. data/spec/cli/i18n_spec.rb +0 -107
  28. data/spec/cli/list_spec.rb +0 -8
  29. data/spec/cli/markup_types_spec.rb +0 -22
  30. data/spec/cli/server_spec.rb +0 -324
  31. data/spec/cli/stats_spec.rb +0 -96
  32. data/spec/cli/yard_on_yard_spec.rb +0 -38
  33. data/spec/cli/yardoc_spec.rb +0 -896
  34. data/spec/cli/yri_spec.rb +0 -101
  35. data/spec/code_objects/base_spec.rb +0 -485
  36. data/spec/code_objects/class_object_spec.rb +0 -226
  37. data/spec/code_objects/code_object_list_spec.rb +0 -36
  38. data/spec/code_objects/constants_spec.rb +0 -116
  39. data/spec/code_objects/extra_file_object_spec.rb +0 -161
  40. data/spec/code_objects/macro_object_spec.rb +0 -150
  41. data/spec/code_objects/method_object_spec.rb +0 -184
  42. data/spec/code_objects/module_object_spec.rb +0 -142
  43. data/spec/code_objects/namespace_mapper_spec.rb +0 -32
  44. data/spec/code_objects/namespace_object_spec.rb +0 -171
  45. data/spec/code_objects/proxy_spec.rb +0 -147
  46. data/spec/code_objects/spec_helper.rb +0 -3
  47. data/spec/config_spec.rb +0 -171
  48. data/spec/core_ext/array_spec.rb +0 -13
  49. data/spec/core_ext/file_spec.rb +0 -72
  50. data/spec/core_ext/hash_spec.rb +0 -14
  51. data/spec/core_ext/insertion_spec.rb +0 -37
  52. data/spec/core_ext/module_spec.rb +0 -9
  53. data/spec/core_ext/string_spec.rb +0 -42
  54. data/spec/core_ext/symbol_hash_spec.rb +0 -89
  55. data/spec/docstring_parser_spec.rb +0 -280
  56. data/spec/docstring_spec.rb +0 -373
  57. data/spec/handlers/alias_handler_spec.rb +0 -82
  58. data/spec/handlers/attribute_handler_spec.rb +0 -96
  59. data/spec/handlers/base_spec.rb +0 -216
  60. data/spec/handlers/c/alias_handler_spec.rb +0 -34
  61. data/spec/handlers/c/attribute_handler_spec.rb +0 -41
  62. data/spec/handlers/c/class_handler_spec.rb +0 -78
  63. data/spec/handlers/c/constant_handler_spec.rb +0 -71
  64. data/spec/handlers/c/init_handler_spec.rb +0 -48
  65. data/spec/handlers/c/method_handler_spec.rb +0 -327
  66. data/spec/handlers/c/mixin_handler_spec.rb +0 -44
  67. data/spec/handlers/c/module_handler_spec.rb +0 -71
  68. data/spec/handlers/c/override_comment_handler_spec.rb +0 -47
  69. data/spec/handlers/c/path_handler_spec.rb +0 -36
  70. data/spec/handlers/c/spec_helper.rb +0 -23
  71. data/spec/handlers/c/struct_handler_spec.rb +0 -16
  72. data/spec/handlers/class_condition_handler_spec.rb +0 -87
  73. data/spec/handlers/class_handler_spec.rb +0 -247
  74. data/spec/handlers/class_method_handler_shared_examples.rb +0 -133
  75. data/spec/handlers/class_variable_handler_spec.rb +0 -12
  76. data/spec/handlers/constant_handler_spec.rb +0 -112
  77. data/spec/handlers/decorator_handler_methods_spec.rb +0 -393
  78. data/spec/handlers/dsl_handler_spec.rb +0 -226
  79. data/spec/handlers/examples/alias_handler_001.rb.txt +0 -46
  80. data/spec/handlers/examples/attribute_handler_001.rb.txt +0 -32
  81. data/spec/handlers/examples/class_condition_handler_001.rb.txt +0 -69
  82. data/spec/handlers/examples/class_handler_001.rb.txt +0 -120
  83. data/spec/handlers/examples/class_variable_handler_001.rb.txt +0 -10
  84. data/spec/handlers/examples/constant_handler_001.rb.txt +0 -35
  85. data/spec/handlers/examples/dsl_handler_001.rb.txt +0 -156
  86. data/spec/handlers/examples/exception_handler_001.rb.txt +0 -59
  87. data/spec/handlers/examples/extend_handler_001.rb.txt +0 -19
  88. data/spec/handlers/examples/method_condition_handler_001.rb.txt +0 -10
  89. data/spec/handlers/examples/method_handler_001.rb.txt +0 -128
  90. data/spec/handlers/examples/mixin_handler_001.rb.txt +0 -40
  91. data/spec/handlers/examples/module_handler_001.rb.txt +0 -29
  92. data/spec/handlers/examples/private_constant_handler_001.rb.txt +0 -8
  93. data/spec/handlers/examples/process_handler_001.rb.txt +0 -11
  94. data/spec/handlers/examples/visibility_handler_001.rb.txt +0 -36
  95. data/spec/handlers/examples/yield_handler_001.rb.txt +0 -54
  96. data/spec/handlers/exception_handler_spec.rb +0 -49
  97. data/spec/handlers/extend_handler_spec.rb +0 -28
  98. data/spec/handlers/legacy_base_spec.rb +0 -128
  99. data/spec/handlers/method_condition_handler_spec.rb +0 -15
  100. data/spec/handlers/method_handler_spec.rb +0 -214
  101. data/spec/handlers/mixin_handler_spec.rb +0 -60
  102. data/spec/handlers/module_function_handler_spec.rb +0 -106
  103. data/spec/handlers/module_handler_spec.rb +0 -35
  104. data/spec/handlers/private_class_method_handler_spec.rb +0 -11
  105. data/spec/handlers/private_constant_handler_spec.rb +0 -25
  106. data/spec/handlers/processor_spec.rb +0 -35
  107. data/spec/handlers/public_class_method_handler_spec.rb +0 -11
  108. data/spec/handlers/ruby/base_spec.rb +0 -95
  109. data/spec/handlers/ruby/legacy/base_spec.rb +0 -84
  110. data/spec/handlers/spec_helper.rb +0 -33
  111. data/spec/handlers/visibility_handler_spec.rb +0 -44
  112. data/spec/handlers/yield_handler_spec.rb +0 -52
  113. data/spec/i18n/locale_spec.rb +0 -81
  114. data/spec/i18n/message_spec.rb +0 -52
  115. data/spec/i18n/messages_spec.rb +0 -67
  116. data/spec/i18n/pot_generator_spec.rb +0 -295
  117. data/spec/i18n/text_spec.rb +0 -184
  118. data/spec/logging_spec.rb +0 -44
  119. data/spec/options_spec.rb +0 -171
  120. data/spec/parser/base_spec.rb +0 -24
  121. data/spec/parser/c_parser_spec.rb +0 -236
  122. data/spec/parser/examples/array.c.txt +0 -6267
  123. data/spec/parser/examples/example1.rb.txt +0 -8
  124. data/spec/parser/examples/extrafile.c.txt +0 -8
  125. data/spec/parser/examples/file.c.txt +0 -28
  126. data/spec/parser/examples/multifile.c.txt +0 -22
  127. data/spec/parser/examples/namespace.cpp.txt +0 -68
  128. data/spec/parser/examples/override.c.txt +0 -424
  129. data/spec/parser/examples/parse_in_order_001.rb.txt +0 -2
  130. data/spec/parser/examples/parse_in_order_002.rb.txt +0 -2
  131. data/spec/parser/examples/tag_handler_001.rb.txt +0 -8
  132. data/spec/parser/ruby/ast_node_spec.rb +0 -33
  133. data/spec/parser/ruby/legacy/statement_list_spec.rb +0 -299
  134. data/spec/parser/ruby/legacy/token_list_spec.rb +0 -79
  135. data/spec/parser/ruby/ruby_parser_spec.rb +0 -520
  136. data/spec/parser/ruby/token_resolver_spec.rb +0 -165
  137. data/spec/parser/source_parser_spec.rb +0 -727
  138. data/spec/parser/tag_parsing_spec.rb +0 -17
  139. data/spec/rake/yardoc_task_spec.rb +0 -118
  140. data/spec/registry_resolver_spec.rb +0 -15
  141. data/spec/registry_spec.rb +0 -463
  142. data/spec/registry_store_spec.rb +0 -327
  143. data/spec/rubygems/doc_manager_spec.rb +0 -112
  144. data/spec/serializers/data/serialized_yardoc/checksums +0 -1
  145. data/spec/serializers/data/serialized_yardoc/objects/Foo.dat +0 -0
  146. data/spec/serializers/data/serialized_yardoc/objects/Foo/bar_i.dat +0 -0
  147. data/spec/serializers/data/serialized_yardoc/objects/Foo/baz_i.dat +0 -0
  148. data/spec/serializers/data/serialized_yardoc/objects/root.dat +0 -0
  149. data/spec/serializers/data/serialized_yardoc/proxy_types +0 -2
  150. data/spec/serializers/file_system_serializer_spec.rb +0 -145
  151. data/spec/serializers/spec_helper.rb +0 -2
  152. data/spec/serializers/yardoc_serializer_spec.rb +0 -90
  153. data/spec/server/adapter_spec.rb +0 -39
  154. data/spec/server/commands/base_spec.rb +0 -91
  155. data/spec/server/commands/library_command_spec.rb +0 -39
  156. data/spec/server/doc_server_helper_spec.rb +0 -72
  157. data/spec/server/doc_server_serializer_spec.rb +0 -60
  158. data/spec/server/rack_adapter_spec.rb +0 -21
  159. data/spec/server/router_spec.rb +0 -123
  160. data/spec/server/spec_helper.rb +0 -22
  161. data/spec/server/static_caching_spec.rb +0 -47
  162. data/spec/server/webrick_servlet_spec.rb +0 -20
  163. data/spec/server_spec.rb +0 -19
  164. data/spec/spec_helper.rb +0 -212
  165. data/spec/tags/default_factory_spec.rb +0 -168
  166. data/spec/tags/default_tag_spec.rb +0 -11
  167. data/spec/tags/directives_spec.rb +0 -463
  168. data/spec/tags/library_spec.rb +0 -48
  169. data/spec/tags/overload_tag_spec.rb +0 -53
  170. data/spec/tags/ref_tag_list_spec.rb +0 -53
  171. data/spec/tags/types_explainer_spec.rb +0 -203
  172. data/spec/templates/class_spec.rb +0 -45
  173. data/spec/templates/constant_spec.rb +0 -41
  174. data/spec/templates/engine_spec.rb +0 -131
  175. data/spec/templates/examples/class001.html +0 -308
  176. data/spec/templates/examples/class001.txt +0 -36
  177. data/spec/templates/examples/class002.html +0 -39
  178. data/spec/templates/examples/constant001.txt +0 -25
  179. data/spec/templates/examples/constant002.txt +0 -7
  180. data/spec/templates/examples/constant003.txt +0 -11
  181. data/spec/templates/examples/method001.html +0 -137
  182. data/spec/templates/examples/method001.txt +0 -35
  183. data/spec/templates/examples/method002.html +0 -91
  184. data/spec/templates/examples/method002.txt +0 -20
  185. data/spec/templates/examples/method003.html +0 -165
  186. data/spec/templates/examples/method003.txt +0 -45
  187. data/spec/templates/examples/method004.html +0 -48
  188. data/spec/templates/examples/method004.txt +0 -10
  189. data/spec/templates/examples/method005.html +0 -105
  190. data/spec/templates/examples/method005.txt +0 -33
  191. data/spec/templates/examples/method006.html +0 -108
  192. data/spec/templates/examples/method006.txt +0 -20
  193. data/spec/templates/examples/module001.dot +0 -33
  194. data/spec/templates/examples/module001.html +0 -833
  195. data/spec/templates/examples/module001.txt +0 -33
  196. data/spec/templates/examples/module002.html +0 -341
  197. data/spec/templates/examples/module003.html +0 -202
  198. data/spec/templates/examples/module004.html +0 -394
  199. data/spec/templates/examples/module005.html +0 -82
  200. data/spec/templates/examples/tag001.txt +0 -82
  201. data/spec/templates/helpers/base_helper_spec.rb +0 -171
  202. data/spec/templates/helpers/html_helper_spec.rb +0 -666
  203. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +0 -65
  204. data/spec/templates/helpers/markup/rdoc_markup_spec.rb +0 -84
  205. data/spec/templates/helpers/markup_helper_spec.rb +0 -136
  206. data/spec/templates/helpers/method_helper_spec.rb +0 -107
  207. data/spec/templates/helpers/module_helper_spec.rb +0 -35
  208. data/spec/templates/helpers/shared_signature_examples.rb +0 -126
  209. data/spec/templates/helpers/text_helper_spec.rb +0 -65
  210. data/spec/templates/markup_processor_integrations/asciidoctor_spec.rb +0 -60
  211. data/spec/templates/markup_processor_integrations/integration_spec_helper.rb +0 -50
  212. data/spec/templates/markup_processor_integrations/rdoc_markdown_spec.rb +0 -48
  213. data/spec/templates/markup_processor_integrations/rdoc_spec.rb +0 -39
  214. data/spec/templates/markup_processor_integrations/redcarpet_spec.rb +0 -64
  215. data/spec/templates/markup_processor_integrations/redcloth_spec.rb +0 -64
  216. data/spec/templates/method_spec.rb +0 -118
  217. data/spec/templates/module_spec.rb +0 -203
  218. data/spec/templates/onefile_spec.rb +0 -66
  219. data/spec/templates/section_spec.rb +0 -144
  220. data/spec/templates/spec_helper.rb +0 -76
  221. data/spec/templates/tag_spec.rb +0 -52
  222. data/spec/templates/template_spec.rb +0 -410
  223. data/spec/verifier_spec.rb +0 -106
@@ -1,168 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::Tags::DefaultFactory do
4
- before { @f = YARD::Tags::DefaultFactory.new }
5
-
6
- describe "#parse_tag" do
7
- it "does not have trailing whitespace on a regular freeform tag" do
8
- expect(@f.parse_tag('api', 'private ').text).to eq "private"
9
- end
10
- end
11
-
12
- describe "#extract_types_and_name_from_text" do
13
- def parse_types(types)
14
- @f.send(:extract_types_and_name_from_text, types)
15
- end
16
-
17
- it "handles one type" do
18
- expect(parse_types('[A]')).to eq [nil, ['A'], ""]
19
- end
20
-
21
- it "handles a list of types" do
22
- expect(parse_types('[A, B, C]')).to eq [nil, ['A', 'B', 'C'], ""]
23
- end
24
-
25
- it "handles ducktypes" do
26
- expect(parse_types('[#foo]')).to eq [nil, ['#foo'], '']
27
- end
28
-
29
- %w(#foo= #<< #<=> #>> #== #=== Array<#<=>> Array<#==>).each do |meth|
30
- it "handles ducktypes with special method name #{meth}" do
31
- expect(parse_types("[#{meth}]")).to eq [nil, [meth], '']
32
- end
33
- end
34
-
35
- it "only parses #ducktypes inside brackets" do
36
- expect(parse_types("#ducktype")).to eq [nil, nil, '#ducktype']
37
- end
38
-
39
- it "returns the text before and after the type list" do
40
- expect(parse_types(' b <String> description')).to eq ['b', ['String'], 'description']
41
- expect(parse_types('b c <String> description (test)')).to eq [nil, nil, 'b c <String> description (test)']
42
- end
43
-
44
- it "does not allow types to start after a newline" do
45
- v = parse_types(" \n [X]")
46
- expect(v).to eq [nil, nil, "[X]"]
47
- end
48
-
49
- it "handles a complex list of types" do
50
- v = parse_types(' [Test, Array<String, Hash, C>, String]')
51
- expect(v).to include(["Test", "Array<String, Hash, C>", "String"])
52
- end
53
-
54
- it "handles any of the following start/end delimiting chars: (), <>, {}, []" do
55
- a = parse_types('[a,b,c]')
56
- b = parse_types('<a,b,c>')
57
- c = parse_types('(a,b,c)')
58
- d = parse_types('{a,b,c}')
59
- expect(a).to eq b
60
- expect(b).to eq c
61
- expect(c).to eq d
62
- expect(a).to include(['a', 'b', 'c'])
63
- end
64
-
65
- it "returns the text before the type list as the last element" do
66
- expect(parse_types('b[x, y, z]')).to eq ['b', ['x', 'y', 'z'], '']
67
- expect(parse_types(' ! <x>')).to eq ["!", ['x'], '']
68
- end
69
-
70
- it "returns text unparsed if there is no type list" do
71
- expect(parse_types('')).to eq [nil, nil, '']
72
- expect(parse_types('[]')).to eq [nil, nil, '[]']
73
- end
74
-
75
- it "allows A => B syntax" do
76
- v = parse_types(' [Test, Array<String, Hash{A => {B => C}}, C>, String]')
77
- expect(v).to include(["Test", "Array<String, Hash{A => {B => C}}, C>", "String"])
78
- end
79
-
80
- it "handles quoted values" do
81
- v = parse_types(' ["foo, bar", \'baz, qux\', in"them,iddle"]')
82
- expect(v).to include(["\"foo, bar\"", "'baz, qux'", 'in"them,iddle"'])
83
- end
84
- end
85
-
86
- describe "#parse_tag_with_types" do
87
- def parse_types(text)
88
- @f.send(:parse_tag_with_types, 'test', text)
89
- end
90
-
91
- it "parses given types and description" do
92
- expect(YARD::Tags::Tag).to receive(:new).with("test", "description", ["x", "y", "z"])
93
- parse_types(' [x, y, z] description')
94
- end
95
-
96
- it "parses given types only" do
97
- expect(YARD::Tags::Tag).to receive(:new).with("test", "", ["x", "y", "z"])
98
- parse_types(' [x, y, z] ')
99
- end
100
-
101
- it "allows type list to be omitted" do
102
- expect(YARD::Tags::Tag).to receive(:new).with('test', 'description', nil)
103
- parse_types(' description ')
104
- end
105
-
106
- it "raises an error if a name is specified before type list" do
107
- expect { parse_types('b<String> desc') }.to raise_error(YARD::Tags::TagFormatError, 'cannot specify a name before type list for \'@test\'')
108
- end
109
- end
110
-
111
- describe "#parse_tag_with_types_name_and_default" do
112
- def parse_types(text)
113
- @f.send(:parse_tag_with_types_name_and_default, 'test', text)
114
- end
115
-
116
- it "parses a standard type list with name before types (no default)" do
117
- expect(YARD::Tags::DefaultTag).to receive(:new).with("test", "description", ["x", "y", "z"], 'NAME', nil)
118
- parse_types('NAME [x, y, z] description')
119
- end
120
-
121
- it "parses a standard type list with name after types (no default)" do
122
- expect(YARD::Tags::DefaultTag).to receive(:new).with("test", "description", ["x", "y", "z"], 'NAME', nil)
123
- parse_types(' [x, y, z] NAME description')
124
- end
125
-
126
- it "parses a tag definition with name, typelist and default" do
127
- expect(YARD::Tags::DefaultTag).to receive(:new).with("test", "description", ["x", "y", "z"], 'NAME', ['default', 'values'])
128
- parse_types(' [x, y, z] NAME (default, values) description')
129
- end
130
-
131
- it "parses a tag definition with name, typelist and default when name is before type list" do
132
- expect(YARD::Tags::DefaultTag).to receive(:new).with("test", "description", ["x", "y", "z"], 'NAME', ['default', 'values'])
133
- parse_types(' NAME [x, y, z] (default, values) description')
134
- end
135
-
136
- it "allows typelist to be omitted" do
137
- expect(YARD::Tags::DefaultTag).to receive(:new).with("test", "description", nil, 'NAME', ['default', 'values'])
138
- parse_types(' NAME (default, values) description')
139
- end
140
- end
141
-
142
- describe "#parse_tag_with_options" do
143
- def parse_options(text)
144
- @f.parse_tag_with_options('option', text)
145
- end
146
-
147
- it "has a name before tag info" do
148
- t = parse_options("xyz key [Types] (default) description")
149
- expect(t.tag_name).to eq 'option'
150
- expect(t.name).to eq 'xyz'
151
- end
152
-
153
- it "parses the rest of the tag like DefaultTag" do
154
- t = parse_options("xyz key [Types] (default) description")
155
- expect(t.pair).to be_instance_of(Tags::DefaultTag)
156
- expect(t.pair.types).to eq ["Types"]
157
- expect(t.pair.name).to eq "key"
158
- expect(t.pair.defaults).to eq ["default"]
159
- expect(t.pair.text).to eq "description"
160
- end
161
-
162
- it "allows omitting default" do
163
- t = parse_options("xyz [Types] key")
164
- expect(t.pair).to be_instance_of(Tags::DefaultTag)
165
- expect(t.pair.name).to eq "key"
166
- end
167
- end
168
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe YARD::Tags::DefaultTag do
4
- it "creates a tag with defaults" do
5
- o = YARD::Tags::DefaultTag.new('tagname', 'desc', ['types'], 'name', ['defaults'])
6
- expect(o.defaults).to eq ['defaults']
7
- expect(o.tag_name).to eq 'tagname'
8
- expect(o.name).to eq 'name'
9
- expect(o.types).to eq ['types']
10
- end
11
- end
@@ -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