puppet-strings 0.4.0 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +122 -0
  3. data/COMMITTERS.md +185 -0
  4. data/CONTRIBUTING.md +89 -0
  5. data/Gemfile +38 -0
  6. data/JSON.md +511 -0
  7. data/LICENSE +13 -0
  8. data/README.md +416 -0
  9. data/Rakefile +49 -0
  10. data/lib/puppet-strings.rb +63 -0
  11. data/lib/puppet-strings/json.rb +49 -0
  12. data/lib/puppet-strings/tasks.rb +10 -0
  13. data/lib/puppet-strings/tasks/generate.rb +23 -0
  14. data/lib/puppet-strings/tasks/gh_pages.rb +43 -0
  15. data/lib/puppet-strings/yard.rb +96 -0
  16. data/lib/puppet-strings/yard/code_objects.rb +8 -0
  17. data/lib/puppet-strings/yard/code_objects/base.rb +14 -0
  18. data/lib/puppet-strings/yard/code_objects/class.rb +59 -0
  19. data/lib/puppet-strings/yard/code_objects/defined_type.rb +58 -0
  20. data/lib/puppet-strings/yard/code_objects/function.rb +93 -0
  21. data/lib/puppet-strings/yard/code_objects/group.rb +30 -0
  22. data/lib/puppet-strings/yard/code_objects/provider.rb +93 -0
  23. data/lib/puppet-strings/yard/code_objects/type.rb +146 -0
  24. data/lib/puppet-strings/yard/handlers.rb +16 -0
  25. data/lib/puppet-strings/yard/handlers/puppet/base.rb +44 -0
  26. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +23 -0
  27. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +23 -0
  28. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +42 -0
  29. data/lib/puppet-strings/yard/handlers/ruby/base.rb +38 -0
  30. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +357 -0
  31. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +113 -0
  32. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +194 -0
  33. data/lib/puppet-strings/yard/parsers.rb +7 -0
  34. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +70 -0
  35. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +146 -0
  36. data/lib/puppet-strings/yard/tags.rb +6 -0
  37. data/lib/puppet-strings/yard/tags/overload_tag.rb +109 -0
  38. data/lib/puppet-strings/yard/tags/parameter_directive.rb +24 -0
  39. data/lib/puppet-strings/yard/tags/property_directive.rb +24 -0
  40. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
  41. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
  42. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
  43. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
  44. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
  45. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +64 -0
  46. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +35 -0
  47. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +172 -0
  48. data/lib/puppet-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
  49. data/lib/puppet-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
  50. data/lib/puppet-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
  51. data/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb +14 -0
  52. data/lib/puppet-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
  53. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
  54. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
  55. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
  56. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb +5 -0
  57. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
  58. data/lib/puppet-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
  59. data/lib/puppet-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
  60. data/lib/puppet-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
  61. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +5 -0
  62. data/lib/puppet-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
  63. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
  64. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/collection.erb +10 -0
  65. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
  66. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
  67. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
  68. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb +29 -0
  69. data/lib/puppet-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
  70. data/lib/puppet-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
  71. data/lib/puppet-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
  72. data/lib/puppet-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
  73. data/lib/puppet-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
  74. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +32 -0
  75. data/lib/puppet-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
  76. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +15 -0
  77. data/lib/puppet/application/strings.rb +1 -0
  78. data/lib/puppet/face/strings.rb +80 -39
  79. data/spec/acceptance/emit_json_options.rb +41 -0
  80. data/spec/acceptance/lib/util.rb +15 -0
  81. data/spec/acceptance/running_strings_generate.rb +54 -0
  82. data/spec/fixtures/acceptance/modules/test/functions/add.pp +9 -0
  83. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +5 -0
  84. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +2 -0
  85. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +9 -0
  86. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +15 -0
  87. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +27 -0
  88. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +27 -0
  89. data/spec/fixtures/acceptance/modules/test/metadata.json +6 -0
  90. data/spec/fixtures/unit/json/output.json +348 -0
  91. data/spec/fixtures/unit/json/output_without_puppet_function.json +301 -0
  92. data/spec/spec_helper.rb +21 -0
  93. data/spec/spec_helper_acceptance.rb +27 -0
  94. data/spec/unit/puppet-strings/json_spec.rb +136 -0
  95. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +155 -0
  96. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +155 -0
  97. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +169 -0
  98. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +613 -0
  99. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +90 -0
  100. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +214 -0
  101. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +171 -0
  102. metadata +115 -92
  103. data/lib/puppet-strings/rake_tasks.rb +0 -18
  104. data/lib/puppet_x/puppetlabs/strings.rb +0 -64
  105. data/lib/puppet_x/puppetlabs/strings/actions.rb +0 -92
  106. data/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb +0 -79
  107. data/lib/puppet_x/puppetlabs/strings/pops/yard_transformer.rb +0 -47
  108. data/lib/puppet_x/puppetlabs/strings/util.rb +0 -65
  109. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object.rb +0 -33
  110. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/host_class_object.rb +0 -22
  111. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/method_object.rb +0 -62
  112. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/provider_object.rb +0 -24
  113. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object.rb +0 -48
  114. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/type_object.rb +0 -42
  115. data/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb +0 -40
  116. data/lib/puppet_x/puppetlabs/strings/yard/handlers/base.rb +0 -13
  117. data/lib/puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler.rb +0 -31
  118. data/lib/puppet_x/puppetlabs/strings/yard/handlers/heredoc_helper.rb +0 -80
  119. data/lib/puppet_x/puppetlabs/strings/yard/handlers/host_class_handler.rb +0 -42
  120. data/lib/puppet_x/puppetlabs/strings/yard/handlers/provider_handler.rb +0 -95
  121. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +0 -54
  122. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +0 -234
  123. data/lib/puppet_x/puppetlabs/strings/yard/handlers/type_handler.rb +0 -295
  124. data/lib/puppet_x/puppetlabs/strings/yard/json_registry_store.rb +0 -85
  125. data/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb +0 -68
  126. data/lib/puppet_x/puppetlabs/strings/yard/parser.rb +0 -30
  127. data/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb +0 -9
  128. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb +0 -34
  129. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/header.erb +0 -5
  130. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb +0 -6
  131. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/setup.rb +0 -1
  132. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/setup.rb +0 -49
  133. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_class.erb +0 -2
  134. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_manifest.erb +0 -1
  135. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb +0 -21
  136. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +0 -1
  137. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +0 -1
  138. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/setup.rb +0 -82
  139. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/box_info.erb +0 -22
  140. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/setup.rb +0 -1
  141. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/subclasses.erb +0 -4
  142. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb +0 -21
  143. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/html_helper.rb +0 -139
  144. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/layout/html/setup.rb +0 -18
  145. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/html/header.erb +0 -17
  146. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/setup.rb +0 -21
  147. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/text/header.erb +0 -2
  148. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/command_details.erb +0 -8
  149. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/confine_details.erb +0 -10
  150. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/default_details.erb +0 -10
  151. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/docstring.erb +0 -34
  152. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/feature_details.erb +0 -10
  153. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/header.erb +0 -5
  154. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/setup.rb +0 -1
  155. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb +0 -50
  156. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/box_info.erb +0 -11
  157. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/header.erb +0 -5
  158. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_details_list.erb +0 -53
  159. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb +0 -20
  160. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/setup.rb +0 -1
  161. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb +0 -91
  162. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb +0 -192
  163. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/docstring.erb +0 -34
  164. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/header.erb +0 -5
  165. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/parameter_details.erb +0 -12
  166. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/provider_details.erb +0 -10
  167. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/setup.rb +0 -1
  168. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/setup.rb +0 -55
@@ -0,0 +1,613 @@
1
+ require 'spec_helper'
2
+ require 'puppet-strings/yard'
3
+
4
+ describe PuppetStrings::Yard::Handlers::Ruby::FunctionHandler do
5
+ subject {
6
+ YARD::Parser::SourceParser.parse_string(source, :ruby)
7
+ YARD::Registry.all(:puppet_function)
8
+ }
9
+
10
+ describe 'parsing source without a function definition' do
11
+ let(:source) { 'puts "hi"' }
12
+
13
+ it 'no functions should be in the registry' do
14
+ expect(subject.empty?).to eq(true)
15
+ end
16
+ end
17
+
18
+ describe 'parsing 3.x API functions' do
19
+ describe 'parsing a function with a missing docstring' do
20
+ let(:source) { <<-SOURCE
21
+ Puppet::Parser::Functions.newfunction(:foo) do |*args|
22
+ end
23
+ SOURCE
24
+ }
25
+
26
+ it 'should log a warning' do
27
+ expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\./).to_stdout_from_any_process
28
+ end
29
+ end
30
+
31
+ describe 'parsing a function with a doc parameter' do
32
+ let(:source) { <<-SOURCE
33
+ Puppet::Parser::Functions.newfunction(:foo, doc: <<-DOC
34
+ An example 3.x function.
35
+ @param [String] first The first parameter.
36
+ @param second The second parameter.
37
+ @return [Undef] Returns nothing.
38
+ DOC
39
+ ) do |*args|
40
+ end
41
+ SOURCE
42
+ }
43
+
44
+ it 'should register a function object' do
45
+ expect(subject.size).to eq(1)
46
+ object = subject.first
47
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
48
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_3X))
49
+ expect(object.name).to eq(:foo)
50
+ expect(object.signature).to eq('foo(String $first, Any $second)')
51
+ expect(object.parameters).to eq([['first', nil], ['second', nil]])
52
+ expect(object.docstring).to eq('An example 3.x function.')
53
+ expect(object.docstring.tags.size).to eq(4)
54
+ tags = object.docstring.tags(:param)
55
+ expect(tags.size).to eq(2)
56
+ expect(tags[0].name).to eq('first')
57
+ expect(tags[0].text).to eq('The first parameter.')
58
+ expect(tags[0].types).to eq(['String'])
59
+ expect(tags[1].name).to eq('second')
60
+ expect(tags[1].text).to eq('The second parameter.')
61
+ expect(tags[1].types).to eq(['Any'])
62
+ tags = object.docstring.tags(:return)
63
+ expect(tags.size).to eq(1)
64
+ expect(tags[0].name).to be_nil
65
+ expect(tags[0].text).to eq('Returns nothing.')
66
+ expect(tags[0].types).to eq(['Undef'])
67
+ tags = object.docstring.tags(:api)
68
+ expect(tags.size).to eq(1)
69
+ expect(tags[0].text).to eq('public')
70
+ end
71
+ end
72
+
73
+ describe 'parsing a function with a missing @return tag' do
74
+ let(:source) { <<-SOURCE
75
+ Puppet::Parser::Functions.newfunction(:foo, doc: <<-DOC) do |*args|
76
+ An example 3.x function.
77
+ @param [String] first The first parameter.
78
+ @param second The second parameter.
79
+ DOC
80
+ end
81
+ SOURCE
82
+ }
83
+
84
+ it 'should log a warning' do
85
+ expect{ subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):1/).to_stdout_from_any_process
86
+ end
87
+ end
88
+ end
89
+
90
+ describe 'parsing 4.x API functions' do
91
+ describe 'parsing a function with a missing docstring' do
92
+ let(:source) { <<-SOURCE
93
+ Puppet::Functions.create_function(:foo) do
94
+ end
95
+ SOURCE
96
+ }
97
+
98
+ it 'should log a warning' do
99
+ expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\./).to_stdout_from_any_process
100
+ end
101
+ end
102
+
103
+ describe 'parsing a function with a simple docstring' do
104
+ let(:source) { <<-SOURCE
105
+ # An example 4.x function.
106
+ Puppet::Functions.create_function(:foo) do
107
+ end
108
+ SOURCE
109
+ }
110
+
111
+ it 'should register a function object' do
112
+ expect(subject.size).to eq(1)
113
+ object = subject.first
114
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
115
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
116
+ expect(object.name).to eq(:foo)
117
+ expect(object.signature).to eq('foo()')
118
+ expect(object.parameters).to eq([])
119
+ expect(object.docstring).to eq('An example 4.x function.')
120
+ expect(object.docstring.tags.size).to eq(1)
121
+ tags = object.docstring.tags(:api)
122
+ expect(tags.size).to eq(1)
123
+ expect(tags[0].text).to eq('public')
124
+ end
125
+ end
126
+
127
+ describe 'parsing a function without any dispatches' do
128
+ let(:source) { <<-SOURCE
129
+ # An example 4.x function.
130
+ Puppet::Functions.create_function(:foo) do
131
+ # @param [Integer] param1 The first parameter.
132
+ # @param param2 The second parameter.
133
+ # @param [String] param3 The third parameter.
134
+ # @return [Undef] Returns nothing.
135
+ def foo(param1, param2, param3 = nil)
136
+ end
137
+ end
138
+ SOURCE
139
+ }
140
+
141
+ it 'should register a function object' do
142
+ expect(subject.size).to eq(1)
143
+ object = subject.first
144
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
145
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
146
+ expect(object.name).to eq(:foo)
147
+ expect(object.signature).to eq('foo(Integer $param1, Any $param2, Optional[String] $param3 = undef)')
148
+ expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'undef']])
149
+ expect(object.docstring).to eq('An example 4.x function.')
150
+ expect(object.docstring.tags.size).to eq(5)
151
+ tags = object.docstring.tags(:param)
152
+ expect(tags.size).to eq(3)
153
+ expect(tags[0].name).to eq('param1')
154
+ expect(tags[0].text).to eq('The first parameter.')
155
+ expect(tags[0].types).to eq(['Integer'])
156
+ expect(tags[1].name).to eq('param2')
157
+ expect(tags[1].text).to eq('The second parameter.')
158
+ expect(tags[1].types).to eq(['Any'])
159
+ expect(tags[2].name).to eq('param3')
160
+ expect(tags[2].text).to eq('The third parameter.')
161
+ expect(tags[2].types).to eq(['Optional[String]'])
162
+ tags = object.docstring.tags(:return)
163
+ expect(tags.size).to eq(1)
164
+ expect(tags[0].name).to be_nil
165
+ expect(tags[0].text).to eq('Returns nothing.')
166
+ expect(tags[0].types).to eq(['Undef'])
167
+ tags = object.docstring.tags(:api)
168
+ expect(tags.size).to eq(1)
169
+ expect(tags[0].text).to eq('public')
170
+ end
171
+ end
172
+
173
+ describe 'parsing a function with a single dispatch' do
174
+ let(:source) { <<-SOURCE
175
+ # An example 4.x function.
176
+ Puppet::Functions.create_function(:foo) do
177
+ # @param param1 The first parameter.
178
+ # @param param2 The second parameter.
179
+ # @param param3 The third parameter.
180
+ # @return [Undef] Returns nothing.
181
+ dispatch :foo do
182
+ param 'Integer', :param1
183
+ param 'Any', :param2
184
+ optional_param 'Array[String]', :param3
185
+ end
186
+
187
+ def foo(param1, param2, param3 = nil)
188
+ end
189
+ end
190
+ SOURCE
191
+ }
192
+
193
+ it 'should register a function object without any overload tags' do
194
+ expect(subject.size).to eq(1)
195
+ object = subject.first
196
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
197
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
198
+ expect(object.name).to eq(:foo)
199
+ expect(object.signature).to eq('foo(Integer $param1, Any $param2, Optional[Array[String]] $param3)')
200
+ expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', nil]])
201
+ expect(object.docstring).to eq('An example 4.x function.')
202
+ expect(object.docstring.tags(:overload).empty?).to be_truthy
203
+ expect(object.docstring.tags.size).to eq(5)
204
+ tags = object.docstring.tags(:param)
205
+ expect(tags.size).to eq(3)
206
+ expect(tags[0].name).to eq('param1')
207
+ expect(tags[0].text).to eq('The first parameter.')
208
+ expect(tags[0].types).to eq(['Integer'])
209
+ expect(tags[1].name).to eq('param2')
210
+ expect(tags[1].text).to eq('The second parameter.')
211
+ expect(tags[1].types).to eq(['Any'])
212
+ expect(tags[2].name).to eq('param3')
213
+ expect(tags[2].text).to eq('The third parameter.')
214
+ expect(tags[2].types).to eq(['Optional[Array[String]]'])
215
+ tags = object.docstring.tags(:return)
216
+ expect(tags.size).to eq(1)
217
+ expect(tags[0].name).to be_nil
218
+ expect(tags[0].text).to eq('Returns nothing.')
219
+ expect(tags[0].types).to eq(['Undef'])
220
+ tags = object.docstring.tags(:api)
221
+ expect(tags.size).to eq(1)
222
+ expect(tags[0].text).to eq('public')
223
+ end
224
+ end
225
+
226
+ describe 'parsing a function with various dispatch parameters.' do
227
+ let(:source) { <<-SOURCE
228
+ # An example 4.x function.
229
+ Puppet::Functions.create_function(:foo) do
230
+ # @param param1 The first parameter.
231
+ # @param param2 The second parameter.
232
+ # @param param3 The third parameter.
233
+ # @param param4 The fourth parameter.
234
+ # @return [Undef] Returns nothing.
235
+ dispatch :foo do
236
+ param 'String', :param1
237
+ required_param 'Integer', :param2
238
+ optional_param 'Array', :param3
239
+ repeated_param 'String', :param4
240
+ end
241
+ end
242
+ SOURCE
243
+ }
244
+
245
+ it 'should register a function object with the expected parameters' do
246
+ expect(subject.size).to eq(1)
247
+ object = subject.first
248
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
249
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
250
+ expect(object.name).to eq(:foo)
251
+ expect(object.signature).to eq('foo(String $param1, Integer $param2, Optional[Array] $param3, String *$param4)')
252
+ expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', nil], ['*param4', nil]])
253
+ expect(object.docstring).to eq('An example 4.x function.')
254
+ expect(object.docstring.tags(:overload).empty?).to be_truthy
255
+ expect(object.docstring.tags.size).to eq(6)
256
+ tags = object.docstring.tags(:param)
257
+ expect(tags.size).to eq(4)
258
+ expect(tags[0].name).to eq('param1')
259
+ expect(tags[0].text).to eq('The first parameter.')
260
+ expect(tags[0].types).to eq(['String'])
261
+ expect(tags[1].name).to eq('param2')
262
+ expect(tags[1].text).to eq('The second parameter.')
263
+ expect(tags[1].types).to eq(['Integer'])
264
+ expect(tags[2].name).to eq('param3')
265
+ expect(tags[2].text).to eq('The third parameter.')
266
+ expect(tags[2].types).to eq(['Optional[Array]'])
267
+ expect(tags[3].name).to eq('*param4')
268
+ expect(tags[3].text).to eq('The fourth parameter.')
269
+ expect(tags[3].types).to eq(['String'])
270
+ tags = object.docstring.tags(:return)
271
+ expect(tags.size).to eq(1)
272
+ expect(tags[0].name).to be_nil
273
+ expect(tags[0].text).to eq('Returns nothing.')
274
+ expect(tags[0].types).to eq(['Undef'])
275
+ tags = object.docstring.tags(:api)
276
+ expect(tags.size).to eq(1)
277
+ expect(tags[0].text).to eq('public')
278
+ end
279
+ end
280
+
281
+ describe 'parsing a function with an optional repeated param.' do
282
+ let(:source) { <<-SOURCE
283
+ # An example 4.x function.
284
+ Puppet::Functions.create_function(:foo) do
285
+ # @param param The first parameter.
286
+ # @return [Undef] Returns nothing.
287
+ dispatch :foo do
288
+ optional_repeated_param 'String', :param
289
+ end
290
+ end
291
+ SOURCE
292
+ }
293
+
294
+ it 'should register a function object with the expected parameters' do
295
+ expect(subject.size).to eq(1)
296
+ object = subject.first
297
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
298
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
299
+ expect(object.name).to eq(:foo)
300
+ expect(object.signature).to eq('foo(Optional[String] *$param)')
301
+ expect(object.parameters).to eq([['*param', nil]])
302
+ expect(object.docstring).to eq('An example 4.x function.')
303
+ expect(object.docstring.tags(:overload).empty?).to be_truthy
304
+ expect(object.docstring.tags.size).to eq(3)
305
+ tags = object.docstring.tags(:param)
306
+ expect(tags.size).to eq(1)
307
+ expect(tags[0].name).to eq('*param')
308
+ expect(tags[0].text).to eq('The first parameter.')
309
+ expect(tags[0].types).to eq(['Optional[String]'])
310
+ tags = object.docstring.tags(:return)
311
+ expect(tags.size).to eq(1)
312
+ expect(tags[0].name).to be_nil
313
+ expect(tags[0].text).to eq('Returns nothing.')
314
+ expect(tags[0].types).to eq(['Undef'])
315
+ tags = object.docstring.tags(:api)
316
+ expect(tags.size).to eq(1)
317
+ expect(tags[0].text).to eq('public')
318
+ end
319
+ end
320
+
321
+ describe 'parsing a function with a block param with one parameter' do
322
+ let(:source) { <<-SOURCE
323
+ # An example 4.x function.
324
+ Puppet::Functions.create_function(:foo) do
325
+ # @param a_block The block parameter.
326
+ # @return [Undef] Returns nothing.
327
+ dispatch :foo do
328
+ block_param :a_block
329
+ end
330
+ end
331
+ SOURCE
332
+ }
333
+
334
+ it 'should register a function object with the expected parameters' do
335
+ expect(subject.size).to eq(1)
336
+ object = subject.first
337
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
338
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
339
+ expect(object.name).to eq(:foo)
340
+ expect(object.signature).to eq('foo(Callable &$a_block)')
341
+ expect(object.parameters).to eq([['&a_block', nil]])
342
+ expect(object.docstring).to eq('An example 4.x function.')
343
+ expect(object.docstring.tags(:overload).empty?).to be_truthy
344
+ expect(object.docstring.tags.size).to eq(3)
345
+ tags = object.docstring.tags(:param)
346
+ expect(tags.size).to eq(1)
347
+ expect(tags[0].name).to eq('&a_block')
348
+ expect(tags[0].text).to eq('The block parameter.')
349
+ expect(tags[0].types).to eq(['Callable'])
350
+ tags = object.docstring.tags(:return)
351
+ expect(tags.size).to eq(1)
352
+ expect(tags[0].name).to be_nil
353
+ expect(tags[0].text).to eq('Returns nothing.')
354
+ expect(tags[0].types).to eq(['Undef'])
355
+ tags = object.docstring.tags(:api)
356
+ expect(tags.size).to eq(1)
357
+ expect(tags[0].text).to eq('public')
358
+ end
359
+ end
360
+
361
+ describe 'parsing a function with a block param with two parameter' do
362
+ let(:source) { <<-SOURCE
363
+ # An example 4.x function.
364
+ Puppet::Functions.create_function(:foo) do
365
+ # @param a_block The block parameter.
366
+ # @return [Undef] Returns nothing.
367
+ dispatch :foo do
368
+ optional_block_param 'Callable[String]', :a_block
369
+ end
370
+ end
371
+ SOURCE
372
+ }
373
+
374
+ it 'should register a function object with the expected parameters' do
375
+ expect(subject.size).to eq(1)
376
+ object = subject.first
377
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
378
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
379
+ expect(object.name).to eq(:foo)
380
+ expect(object.signature).to eq('foo(Optional[Callable[String]] &$a_block)')
381
+ expect(object.parameters).to eq([['&a_block', nil]])
382
+ expect(object.docstring).to eq('An example 4.x function.')
383
+ expect(object.docstring.tags(:overload).empty?).to be_truthy
384
+ expect(object.docstring.tags.size).to eq(3)
385
+ tags = object.docstring.tags(:param)
386
+ expect(tags.size).to eq(1)
387
+ expect(tags[0].name).to eq('&a_block')
388
+ expect(tags[0].text).to eq('The block parameter.')
389
+ expect(tags[0].types).to eq(['Optional[Callable[String]]'])
390
+ tags = object.docstring.tags(:return)
391
+ expect(tags.size).to eq(1)
392
+ expect(tags[0].name).to be_nil
393
+ expect(tags[0].text).to eq('Returns nothing.')
394
+ expect(tags[0].types).to eq(['Undef'])
395
+ tags = object.docstring.tags(:api)
396
+ expect(tags.size).to eq(1)
397
+ expect(tags[0].text).to eq('public')
398
+ end
399
+ end
400
+ end
401
+
402
+ describe 'parsing a function with a multiple dispatches' do
403
+ let(:source) { <<-SOURCE
404
+ # An example 4.x function.
405
+ Puppet::Functions.create_function(:foo) do
406
+ # The first overload.
407
+ # @param param1 The first parameter.
408
+ # @param param2 The second parameter.
409
+ # @param param3 The third parameter.
410
+ # @return [Undef] Returns nothing.
411
+ dispatch :foo do
412
+ param 'Integer', :param1
413
+ param 'Any', :param2
414
+ optional_param 'Array[String]', :param3
415
+ end
416
+
417
+ # The second overload.
418
+ # @param param The first parameter.
419
+ # @param block The block parameter.
420
+ # @return [String] Returns a string.
421
+ dispatch :other do
422
+ param 'Boolean', :param
423
+ block_param
424
+ end
425
+
426
+ def foo(param1, param2, param3 = nil)
427
+ end
428
+
429
+ def other(b)
430
+ 'lol'
431
+ end
432
+ end
433
+ SOURCE
434
+ }
435
+
436
+ it 'should register a function object with overload tags' do
437
+ expect(subject.size).to eq(1)
438
+ object = subject.first
439
+ expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
440
+ expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
441
+ expect(object.name).to eq(:foo)
442
+ expect(object.signature).to eq('')
443
+ expect(object.parameters).to eq([])
444
+ expect(object.docstring).to eq('An example 4.x function.')
445
+ expect(object.docstring.tags(:param).empty?).to be_truthy
446
+ expect(object.docstring.tags(:return).empty?).to be_truthy
447
+ expect(object.docstring.tags.size).to eq(3)
448
+ overloads = object.docstring.tags(:overload)
449
+ expect(overloads.size).to eq(2)
450
+ expect(overloads[0]).to be_a(PuppetStrings::Yard::Tags::OverloadTag)
451
+ expect(overloads[0].docstring).to eq('The first overload.')
452
+ expect(overloads[0].signature).to eq('foo(Integer $param1, Any $param2, Optional[Array[String]] $param3)')
453
+ expect(overloads[0].tags.size).to eq(4)
454
+ tags = overloads[0].tags(:param)
455
+ expect(tags.size).to eq(3)
456
+ expect(tags[0].name).to eq('param1')
457
+ expect(tags[0].text).to eq('The first parameter.')
458
+ expect(tags[0].types).to eq(['Integer'])
459
+ expect(tags[1].name).to eq('param2')
460
+ expect(tags[1].text).to eq('The second parameter.')
461
+ expect(tags[1].types).to eq(['Any'])
462
+ expect(tags[2].name).to eq('param3')
463
+ expect(tags[2].text).to eq('The third parameter.')
464
+ expect(tags[2].types).to eq(['Optional[Array[String]]'])
465
+ tags = overloads[0].tags(:return)
466
+ expect(tags.size).to eq(1)
467
+ expect(tags[0].name).to be_nil
468
+ expect(tags[0].text).to eq('Returns nothing.')
469
+ expect(tags[0].types).to eq(['Undef'])
470
+ expect(overloads[1]).to be_a(PuppetStrings::Yard::Tags::OverloadTag)
471
+ expect(overloads[1].docstring).to eq('The second overload.')
472
+ expect(overloads[1].signature).to eq('foo(Boolean $param, Callable &$block)')
473
+ expect(overloads[1].tags.size).to eq(3)
474
+ tags = overloads[1].tags(:param)
475
+ expect(tags.size).to eq(2)
476
+ expect(tags[0].name).to eq('param')
477
+ expect(tags[0].text).to eq('The first parameter.')
478
+ expect(tags[0].types).to eq(['Boolean'])
479
+ expect(tags[1].name).to eq('&block')
480
+ expect(tags[1].text).to eq('The block parameter.')
481
+ expect(tags[1].types).to eq(['Callable'])
482
+ tags = overloads[1].tags(:return)
483
+ expect(tags.size).to eq(1)
484
+ expect(tags[0].name).to be_nil
485
+ expect(tags[0].text).to eq('Returns a string.')
486
+ expect(tags[0].types).to eq(['String'])
487
+ tags = object.docstring.tags(:api)
488
+ expect(tags.size).to eq(1)
489
+ expect(tags[0].text).to eq('public')
490
+ end
491
+ end
492
+
493
+ describe 'parsing a function with a missing parameter' do
494
+ let(:source) { <<-SOURCE
495
+ # An example 4.x function.
496
+ Puppet::Functions.create_function(:foo) do
497
+ # @param missing A missing parameter.
498
+ # @return [Undef] Returns nothing.
499
+ dispatch :foo do
500
+ end
501
+ end
502
+ SOURCE
503
+ }
504
+
505
+ it 'should output a warning' do
506
+ expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'missing' has no matching parameter at \(stdin\):5/).to_stdout_from_any_process
507
+ end
508
+ end
509
+
510
+ describe 'parsing a function with a missing @param tag' do
511
+ let(:source) { <<-SOURCE
512
+ # An example 4.x function.
513
+ Puppet::Functions.create_function(:foo) do
514
+ # @return [Undef] Returns nothing.
515
+ dispatch :foo do
516
+ param 'String', :param1
517
+ end
518
+ end
519
+ SOURCE
520
+ }
521
+
522
+ it 'should output a warning' do
523
+ expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param1' near \(stdin\):5/).to_stdout_from_any_process
524
+ end
525
+ end
526
+
527
+ describe 'parsing a function with a typed @param tag' do
528
+ let(:source) { <<-SOURCE
529
+ # An example 4.x function.
530
+ Puppet::Functions.create_function(:foo) do
531
+ # @param [Integer] param1 The first parameter.
532
+ # @return [Undef] Returns nothing.
533
+ dispatch :foo do
534
+ param 'String', :param1
535
+ end
536
+ end
537
+ SOURCE
538
+ }
539
+
540
+ it 'should output a warning' do
541
+ expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param1' should not contain a type specification near \(stdin\):6: ignoring in favor of dispatch type information\./).to_stdout_from_any_process
542
+ end
543
+ end
544
+
545
+ describe 'parsing a function with a typed @param tag' do
546
+ let(:source) { <<-SOURCE
547
+ # An example 4.x function.
548
+ Puppet::Functions.create_function(:foo) do
549
+ # @param param1 The first parameter.
550
+ dispatch :foo do
551
+ param 'String', :param1
552
+ end
553
+ end
554
+ SOURCE
555
+ }
556
+
557
+ it 'should output a warning' do
558
+ expect{ subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):4/).to_stdout_from_any_process
559
+ end
560
+ end
561
+
562
+ describe 'parsing a function with a root @param tag' do
563
+ let(:source) { <<-SOURCE
564
+ # An example 4.x function.
565
+ # @param param Nope.
566
+ Puppet::Functions.create_function(:foo) do
567
+ # @return [Undef]
568
+ dispatch :foo do
569
+ end
570
+ end
571
+ SOURCE
572
+ }
573
+
574
+ it 'should output a warning' do
575
+ expect{ subject }.to output(/\[warn\]: The docstring for Puppet 4.x function 'foo' contains @param tags near \(stdin\):3: parameter documentation should be made on the dispatch call\./).to_stdout_from_any_process
576
+ end
577
+ end
578
+
579
+
580
+ describe 'parsing a function with a root @overload tag' do
581
+ let(:source) { <<-SOURCE
582
+ # An example 4.x function.
583
+ # @overload foo
584
+ Puppet::Functions.create_function(:foo) do
585
+ # @return [Undef]
586
+ dispatch :foo do
587
+ end
588
+ end
589
+ SOURCE
590
+ }
591
+
592
+ it 'should output a warning' do
593
+ expect{ subject }.to output(/\[warn\]: The docstring for Puppet 4.x function 'foo' contains @overload tags near \(stdin\):3: overload tags are automatically generated from the dispatch calls\./).to_stdout_from_any_process
594
+ end
595
+ end
596
+
597
+ describe 'parsing a function with a root @return tag' do
598
+ let(:source) { <<-SOURCE
599
+ # An example 4.x function.
600
+ # @return [Undef] foo
601
+ Puppet::Functions.create_function(:foo) do
602
+ # @return [Undef]
603
+ dispatch :foo do
604
+ end
605
+ end
606
+ SOURCE
607
+ }
608
+
609
+ it 'should output a warning' do
610
+ expect{ subject }.to output(/\[warn\]: The docstring for Puppet 4.x function 'foo' contains @return tags near \(stdin\):3: return value documentation should be made on the dispatch call\./).to_stdout_from_any_process
611
+ end
612
+ end
613
+ end