diff --git a/lib/puppet/parser/functions/type.rb b/lib/puppet/parser/functions/type.rb deleted file mode 100644 index 57dd3e133..000000000 --- a/lib/puppet/parser/functions/type.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# -# type.rb -# -module Puppet::Parser::Functions - newfunction(:type, type: :rvalue, doc: <<-DOC - @summary - **DEPRECATED:** This function will cease to function on Puppet 4; - please use type3x() before upgrading to Puppet 4 for backwards-compatibility, or migrate to the new parser's typing system. - - @return the type when passed a value. Type can be one of: - - * string - * array - * hash - * float - * integer - * boolean - DOC - ) do |args| - warning("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Layout/LineLength : Cannot reduce line length - unless Puppet::Parser::Functions.autoloader.loaded?(:type3x) - Puppet::Parser::Functions.autoloader.load(:type3x) - end - function_type3x(args) - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/type3x.rb b/lib/puppet/parser/functions/type3x.rb deleted file mode 100644 index 49903b905..000000000 --- a/lib/puppet/parser/functions/type3x.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -# -# type3x.rb -# -module Puppet::Parser::Functions - newfunction(:type3x, type: :rvalue, doc: <<-DOC - @summary - **DEPRECATED:** This function will be removed when Puppet 3 support is dropped; please migrate to the new parser's typing system. - - @return the type when passed a value. Type can be one of: - - * string - * array - * hash - * float - * integer - * boolean - DOC - ) do |args| - raise(Puppet::ParseError, "type3x(): Wrong number of arguments given (#{args.size} for 1)") unless args.size == 1 - - value = args[0] - - klass = value.class - - unless [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) # rubocop:disable Lint/UnifiedInteger - raise(Puppet::ParseError, 'type3x(): Unknown type') - end - - klass = klass.to_s # Ugly ... - - # We note that Integer is the parent to Bignum and Fixnum ... - result = case klass - when %r{^(?:Big|Fix)num$} then 'integer' - when %r{^(?:True|False)Class$} then 'boolean' - else klass - end - - if result == 'String' - if value == value.to_i.to_s - result = 'Integer' - elsif value == value.to_f.to_s - result = 'Float' - end - end - - return result.downcase - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/type3x_spec.rb b/spec/functions/type3x_spec.rb deleted file mode 100644 index 750752628..000000000 --- a/spec/functions/type3x_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'type3x' do - it 'exists' do - expect(Puppet::Parser::Functions.function('type3x')).to eq('function_type3x') - end - - it 'raises a ParseError if there is less than 1 arguments' do - expect { scope.function_type3x([]) }.to(raise_error(Puppet::ParseError)) - end - - it 'returns string when given a string' do - result = scope.function_type3x(['aaabbbbcccc']) - expect(result).to(eq('string')) - end - - it 'returns array when given an array' do - result = scope.function_type3x([['aaabbbbcccc', 'asdf']]) - expect(result).to(eq('array')) - end - - it 'returns hash when given a hash' do - result = scope.function_type3x([{ 'a' => 1, 'b' => 2 }]) - expect(result).to(eq('hash')) - end - - it 'returns integer when given an integer' do - result = scope.function_type3x(['1']) - expect(result).to(eq('integer')) - end - - it 'returns float when given a float' do - result = scope.function_type3x(['1.34']) - expect(result).to(eq('float')) - end - - it 'returns boolean when given a boolean' do - result = scope.function_type3x([true]) - expect(result).to(eq('boolean')) - end -end diff --git a/spec/functions/type_spec.rb b/spec/functions/type_spec.rb deleted file mode 100644 index 8a0f2a11e..000000000 --- a/spec/functions/type_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'type' do - it 'exists' do - expect(Puppet::Parser::Functions.function('type')).to eq('function_type') - end - - it 'gives a deprecation warning when called' do - expect(scope).to receive(:warning).with("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Layout/LineLength : Unable to reduce to required length - scope.function_type(['aoeu']) - end - - it 'returns string when given a string' do - result = scope.function_type(['aaabbbbcccc']) - expect(result).to(eq('string')) - end - - it 'returns array when given an array' do - result = scope.function_type([['aaabbbbcccc', 'asdf']]) - expect(result).to(eq('array')) - end - - it 'returns hash when given a hash' do - result = scope.function_type([{ 'a' => 1, 'b' => 2 }]) - expect(result).to(eq('hash')) - end - - it 'returns integer when given an integer' do - result = scope.function_type(['1']) - expect(result).to(eq('integer')) - end - - it 'returns float when given a float' do - result = scope.function_type(['1.34']) - expect(result).to(eq('float')) - end - - it 'returns boolean when given a boolean' do - result = scope.function_type([true]) - expect(result).to(eq('boolean')) - end -end