diff options
-rw-r--r-- | lib/puppet/parser/functions/count.rb | 36 | ||||
-rwxr-xr-x | spec/unit/parser/functions/count_spec.rb | 26 |
2 files changed, 0 insertions, 62 deletions
diff --git a/lib/puppet/parser/functions/count.rb b/lib/puppet/parser/functions/count.rb deleted file mode 100644 index c4e2283..0000000 --- a/lib/puppet/parser/functions/count.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -# count.rb -# - -# TODO(Krzysztof Wilczynski): We need to add support for regular expression ... -# TODO(Krzysztof Wilczynski): Support for hash values would be nice too ... - -module Puppet::Parser::Functions - newfunction(:count, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - # Technically we support two arguments but only first is mandatory ... - raise(Puppet::ParseError, "count(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - value = arguments[0] - klass = value.class - - unless [Array, Hash, String].include?(klass) - raise(Puppet::ParseError, 'count(): Requires either ' + - 'array, hash or string to work with') - end - - item = arguments[1] if arguments[1] - - value = value.is_a?(Hash) ? value.keys : value - - # No item to look for and count? Then just return current size ... - result = item ? value.count(item) : value.size - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/unit/parser/functions/count_spec.rb b/spec/unit/parser/functions/count_spec.rb deleted file mode 100755 index 62d005a..0000000 --- a/spec/unit/parser/functions/count_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the count function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("count").should == "function_count" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_count([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return the size of an array" do - result = @scope.function_count([['a','c','b']]) - result.should(eq(3)) - end - -end |