File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
lib/puppet-strings/yard/handlers/puppet
spec/unit/puppet-strings/yard/handlers/puppet Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya
3939 def add_return_tag ( object , type = nil )
4040 tag = object . tag ( :return )
4141 if tag
42- if ( type && tag . types . first ) && ( type != tag . types . first )
42+ if ( type && tag . types && tag . types . first ) && ( type != tag . types . first )
4343 log . warn "Documented return type does not match return type in function definition near #{ statement . file } :#{ statement . line } ."
4444 end
4545
Original file line number Diff line number Diff line change 256256 end
257257 end
258258
259+ describe 'parsing a function with return tag without type' , if : TEST_FUNCTION_RETURN_TYPE do
260+ let ( :source ) { <<-SOURCE
261+ # A simple foo function.
262+ # @return This is something.
263+ function foo() >> Struct[{'a' => Integer[1, 10]}] {
264+ notice 'hello world'
265+ }
266+ SOURCE
267+ }
268+
269+ it 'should get the return type from the function definition' do
270+ expect { subject } . to output ( '' ) . to_stdout_from_any_process
271+ expect ( subject . size ) . to eq ( 1 )
272+ object = subject . first
273+ expect ( object ) . to be_a ( PuppetStrings ::Yard ::CodeObjects ::Function )
274+ tags = object . docstring . tags ( :return )
275+ expect ( tags . size ) . to eq ( 1 )
276+ expect ( tags [ 0 ] . tag_name ) . to eq ( 'return' )
277+ expect ( tags [ 0 ] . text ) . to eq ( 'This is something.' )
278+ expect ( tags [ 0 ] . types ) . to eq ( [ "Struct[{'a' => Integer[1, 10]}]" ] )
279+ end
280+ end
281+
259282 describe 'parsing a function without a return tag or return type in the function definition' do
260283 let ( :source ) { <<-SOURCE
261284# A simple foo function.
You can’t perform that action at this time.
0 commit comments