From cfdb53e04801e2105f920a4ba70898a6edf77d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Tue, 25 Apr 2023 13:13:23 -1000 Subject: [PATCH] Remove deprecated sort function From Puppet 6.0.0 the same function in Puppet will be used instead of this. --- lib/puppet/parser/functions/sort.rb | 32 ----------------------- spec/functions/sort_spec.rb | 39 ----------------------------- 2 files changed, 71 deletions(-) delete mode 100644 lib/puppet/parser/functions/sort.rb delete mode 100644 spec/functions/sort_spec.rb diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb deleted file mode 100644 index 29c9f6098..000000000 --- a/lib/puppet/parser/functions/sort.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -# -# sort.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(:sort, type: :rvalue, doc: <<-DOC - @summary - Sorts strings and arrays lexically. - - @return - sorted string or array - - Note that from Puppet 6.0.0 the same function in Puppet will be used instead of this. - DOC - ) do |arguments| - if arguments.size != 1 - raise(Puppet::ParseError, "sort(): Wrong number of arguments given #{arguments.size} for 1") - end - - value = arguments[0] - - if value.is_a?(Array) - value.sort - elsif value.is_a?(String) - value.split('').sort.join('') - end - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/sort_spec.rb b/spec/functions/sort_spec.rb deleted file mode 100644 index 3387e7503..000000000 --- a/spec/functions/sort_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'sort', 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([], 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { - pending('stricter input checking') - is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{requires string or array}) - } - it { - pending('stricter input checking') - is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{requires string or array}) - } - it { - pending('stricter input checking') - is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{requires string or array}) - } - end - - context 'when called with an array' do - it { is_expected.to run.with_params([]).and_return([]) } - it { is_expected.to run.with_params(['a']).and_return(['a']) } - it { is_expected.to run.with_params(['c', 'b', 'a']).and_return(['a', 'b', 'c']) } - end - - context 'when called with a string' do - it { is_expected.to run.with_params('').and_return('') } - it { is_expected.to run.with_params('a').and_return('a') } - it { is_expected.to run.with_params('cbda').and_return('abcd') } - end - - context 'when called with a number' do - it { is_expected.to run.with_params('9478').and_return('4789') } - end -end