From e31a77f554abd21203708af524e9821b1b7a7c03 Mon Sep 17 00:00:00 2001 From: martyewings Date: Tue, 25 Apr 2023 11:42:56 +0100 Subject: [PATCH] Remove deprecated hash function --- lib/puppet/parser/functions/hash.rb | 48 ----------------------------- spec/functions/hash_spec.rb | 17 ---------- 2 files changed, 65 deletions(-) delete mode 100644 lib/puppet/parser/functions/hash.rb delete mode 100644 spec/functions/hash_spec.rb diff --git a/lib/puppet/parser/functions/hash.rb b/lib/puppet/parser/functions/hash.rb deleted file mode 100644 index 029089ec4..000000000 --- a/lib/puppet/parser/functions/hash.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -# -# hash.rb -# -module Puppet::Parser::Functions - newfunction(:hash, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** This function converts an array into a hash. - - @return - the converted array as a hash - @example Example Usage: - hash(['a',1,'b',2,'c',3]) # Returns: {'a'=>1,'b'=>2,'c'=>3} - - > **Note:** This function has been replaced with the built-in ability to create a new value of almost any - data type - see the built-in [`Hash.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-hash-and-struct) function - in Puppet. - This example shows the equivalent expression in the Puppet language: - ``` - Hash(['a',1,'b',2,'c',3]) - Hash([['a',1],['b',2],['c',3]]) - ``` - DOC - ) do |arguments| - raise(Puppet::ParseError, "hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? - - array = arguments[0] - - unless array.is_a?(Array) - raise(Puppet::ParseError, 'hash(): Requires array to work with') - end - - result = {} - - begin - # This is to make it compatible with older version of Ruby ... - array = array.flatten - result = Hash[*array] - rescue StandardError - raise(Puppet::ParseError, 'hash(): Unable to compute hash from array given') - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/hash_spec.rb b/spec/functions/hash_spec.rb deleted file mode 100644 index 1d678f9aa..000000000 --- a/spec/functions/hash_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'hash' 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 { - pending('Current implementation ignores parameters after the first.') - is_expected.to run.with_params([], 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) - } - it { is_expected.to run.with_params(['one']).and_raise_error(Puppet::ParseError, %r{Unable to compute}) } - it { is_expected.to run.with_params([]).and_return({}) } - it { is_expected.to run.with_params(['key1', 'value1']).and_return('key1' => 'value1') } - it { is_expected.to run.with_params(['κ℮ұ1', '√āĺűẻ1']).and_return('κ℮ұ1' => '√āĺűẻ1') } - it { is_expected.to run.with_params(['key1', 'value1', 'key2', 'value2']).and_return('key1' => 'value1', 'key2' => 'value2') } -end