Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PDOC-283) Fix namespaced symbols #205

Merged
merged 1 commit into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a really fragile way to do this, but I trust your judgement that there's not a better way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wasn't super happy with it. But it's no worse than the examples above or below 🤷‍♂️ The fragility is also why I add tests so at least we should be able to detect when it goes bad.

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