Skip to content

Commit

Permalink
Merge pull request #205 from glennsarti/pdoc-283-fix-symbols
Browse files Browse the repository at this point in the history
(PDOC-283) Fix namespaced symbols
  • Loading branch information
binford2k authored Jul 1, 2019
2 parents 8b9e267 + 42a643e commit b3b24fe
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/puppet-strings/yard/handlers/ruby/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ def node_as_string(node)
when :label
node.source[0..-2]
when :dyna_symbol
node.source
# YARD 0.9.20 changed how dyna_symbols are represented
# https://github.com/lsegal/yard/commit/225ded9ef38c6d2be5a3b0fc7effbc7d6644768d
if yard_version >= Gem::Version.new('0.9.20')
node.source[2..-2]
else
node.source
end
when :string_literal
content = node.jump(:tstring_content)
return content.source if content != node
Expand Down Expand Up @@ -46,4 +52,9 @@ def get_name(statementobject, statementtype)
name
end

private

def yard_version
@yard_version ||= Gem::Version.new(YARD::VERSION)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,23 @@ def other(b)
end
end

describe 'parsing a function with a namespaced name' do
let(:source) { <<-SOURCE
# An example 4.x function.
Puppet::Functions.create_function(:'foo::bar::baz') do
# @return [Undef]
dispatch :foo do
end
end
SOURCE
}

it 'should output the name correctly as a symbol' do
expect(subject.size).to eq(1)
expect(subject.first.name).to eq(:'foo::bar::baz')
end
end

describe 'parsing a function with a missing parameter' do
let(:source) { <<-SOURCE
# An example 4.x function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@
end
end

describe 'parsing a provider definition with a string based name' do
let(:source) { <<-SOURCE
Puppet::Type.type(:'custom').provide :'linux' do
desc 'An example provider on Linux.'
end
SOURCE
}

it 'should register a provider object' do
expect(subject.size).to eq(1)
object = subject.first
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Provider)
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Providers.instance('custom'))
expect(object.name).to eq(:linux)
expect(object.type_name).to eq('custom')
expect(object.docstring).to eq('An example provider on Linux.')
end
end

describe 'parsing a provider with a summary' do
context 'when the summary has fewer than 140 characters' do
let(:source) { <<-SOURCE
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@
end
end

describe 'parsing a valid type with string based name' do
let(:source) { <<-SOURCE
Puppet::Type.newtype(:'database') do
desc 'An example database server resource type.'
ensurable
end
SOURCE
}

it 'should register a type object with default ensure values' do
expect(subject.size).to eq(1)
object = subject.first
expect(object.name).to eq(:database)
end
end

describe 'parsing an ensurable type with default ensure values' do
let(:source) { <<-SOURCE
Puppet::Type.newtype(:database) do
Expand Down

0 comments on commit b3b24fe

Please # to comment.