Count functionality overlaps with size - so removing it.

This commit is contained in:
Ken Barber 2011-07-28 21:30:02 +01:00
parent 4915eff575
commit 7d6ae5d57c
2 changed files with 0 additions and 62 deletions

View file

@ -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 :

View file

@ -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