diff options
author | Martin Hellmich <mhellmic@gmail.com> | 2013-04-22 23:24:38 +0200 |
---|---|---|
committer | Martin Hellmich <mhellmic@gmail.com> | 2013-04-22 23:24:38 +0200 |
commit | 89bceb2821d82c64434e6529de48ec7d7389a13e (patch) | |
tree | 28378bbd407cae78abbff2a1fc86349db9d58c0b /spec/unit/puppet/parser/functions/count_spec.rb | |
parent | 0c622b2e30333f26103a4440a888d440cf455c9c (diff) | |
parent | bebecd33783b483f6af059e311b9631d3a3336cc (diff) | |
download | puppet-stdlib-89bceb2821d82c64434e6529de48ec7d7389a13e.tar.gz puppet-stdlib-89bceb2821d82c64434e6529de48ec7d7389a13e.tar.bz2 |
Merge branch 'master' of git://github.com/puppetlabs/puppetlabs-stdlib
Diffstat (limited to 'spec/unit/puppet/parser/functions/count_spec.rb')
-rw-r--r-- | spec/unit/puppet/parser/functions/count_spec.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/unit/puppet/parser/functions/count_spec.rb b/spec/unit/puppet/parser/functions/count_spec.rb new file mode 100644 index 0000000..2453815 --- /dev/null +++ b/spec/unit/puppet/parser/functions/count_spec.rb @@ -0,0 +1,31 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the count function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("count").should == "function_count" + end + + it "should raise a ArgumentError if there is more than 2 arguments" do + lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError)) + end + + it "should be able to count arrays" do + scope.function_count([["1","2","3"]]).should(eq(3)) + end + + it "should be able to count matching elements in arrays" do + scope.function_count([["1", "2", "2"], "2"]).should(eq(2)) + end + + it "should not count nil or empty strings" do + scope.function_count([["foo","bar",nil,""]]).should(eq(2)) + end + + it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do + expect(scope.function_count([["foo",:undef,:undef]])).to eq(1) + end +end |