From 7b6af21145d4c11491a73dfda2ecb09b1b36c0d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 25 Apr 2023 13:12:58 -1000 Subject: [PATCH] Remove deprecated upcase function From Puppet 6.0.0, the compatible function with the same name in Puppet core will be used instead of this function. --- lib/puppet/parser/functions/upcase.rb | 48 --------------------------- spec/functions/upcase_spec.rb | 28 ---------------- 2 files changed, 76 deletions(-) delete mode 100644 lib/puppet/parser/functions/upcase.rb delete mode 100644 spec/functions/upcase_spec.rb diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb deleted file mode 100644 index a7685d1e0..000000000 --- a/lib/puppet/parser/functions/upcase.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -# -# upcase.rb -# Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. -# -module Puppet::Parser::Functions - newfunction(:upcase, type: :rvalue, doc: <<-DOC - @summary - Converts a string or an array of strings to uppercase. - - @return - converted string ot array of strings to uppercase - - @example **Usage** - - upcase("abcd") - Will return ABCD - - > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core - will be used instead of this function. - DOC - ) do |arguments| - raise(Puppet::ParseError, "upcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 - - value = arguments[0] - - unless value.is_a?(Array) || value.is_a?(Hash) || value.respond_to?(:upcase) - raise(Puppet::ParseError, 'upcase(): Requires an array, hash or object that responds to upcase in order to work') - end - - if value.is_a?(Array) - # Numbers in Puppet are often string-encoded which is troublesome ... - result = value.map { |i| function_upcase([i]) } - elsif value.is_a?(Hash) - result = {} - value.each_pair do |k, v| - result[function_upcase([k])] = function_upcase([v]) - end - else - result = value.upcase - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb deleted file mode 100644 index d110ee108..000000000 --- a/spec/functions/upcase_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'upcase', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires an array, hash or object that responds to upcase}) } - it { is_expected.to run.with_params([1]).and_raise_error(Puppet::ParseError, %r{Requires an array, hash or object that responds to upcase}) } - end - - describe 'normal string handling' do - it { is_expected.to run.with_params('abc').and_return('ABC') } - it { is_expected.to run.with_params('Abc').and_return('ABC') } - it { is_expected.to run.with_params('ABC').and_return('ABC') } - end - - describe 'handling classes derived from String' do - it { is_expected.to run.with_params(AlsoString.new('ABC')).and_return('ABC') } - end - - describe 'strings in arrays handling' do - it { is_expected.to run.with_params([]).and_return([]) } - it { is_expected.to run.with_params(['One', 'twO']).and_return(['ONE', 'TWO']) } - end -end