From 84a215d5999cd82bd847f57bc57637bedcb9fc45 Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Tue, 1 Sep 2015 15:31:13 -0700 Subject: [PATCH 1/2] (PDOC-45) Puppet 4x functions handle unusual names `lib/puppet/functions/defined.rb` has some unusual syntax: Puppet::Functions.create_function(:'defined', .... It runs, so apparently this is legal. --- .../strings/yard/handlers/puppet_4x_function_handler.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb index 14fd54c..46967fc 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb @@ -187,6 +187,7 @@ class Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base name = process_element(name) + name end @@ -199,12 +200,12 @@ class Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base # @param ele [YARD::Parser::Ruby::AstNode] # @return [String] def process_element(ele) - ele = ele.jump(:ident, :string_content) + ele = ele.jump(:ident, :string_content, :tstring_content) case ele.type when :ident ele.source - when :string_content + when :string_content, :tstring_content source = ele.source if HEREDOC_START.match(source) process_heredoc(source) From c4a1a10c67e581a2f409992e437936e034384b0b Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Tue, 1 Sep 2015 15:42:37 -0700 Subject: [PATCH 2/2] (PDOC-45) Test Puppet 4x functions don't throw Parsing puppet 4x functions with symbols for their names like :'defined' should not raise ParseErrorWithIssue, or anything for that matter. --- .../strings/yard/puppet_4x_function_handler_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_4x_function_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_4x_function_handler_spec.rb index 51f5f5f..7430471 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_4x_function_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_4x_function_handler_spec.rb @@ -173,4 +173,17 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet4xFunctionHandler d RUBY }.to output("").to_stdout_from_any_process end + + it "should parse unusually named functions" do + # This should not raise a ParseErrorWithIssue exceptoin + parse <<-RUBY + Puppet::Functions.create_function :'max' do + def max(num_a, num_b) + num_a >= num_b ? num_a : num_b + end + end + RUBY + end + + end