"given #{arguments.size} for 1")
end
+ # TODO: stubbed
+
end
end
"given #{arguments.size} for 2")
end
+ a = arguments[0]
+ item = arguments[1]
+
+ a.delete(item)
+ a
+
end
end
+++ /dev/null
-#
-# fact.rb
-#
-
-module Puppet::Parser::Functions
- newfunction(:fact, :type => :rvalue, :doc => <<-EOS
- EOS
- ) do |arguments|
-
- raise(Puppet::ParseError, "fact(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
-
- fact = arguments[0]
-
- unless fact.is_a?(String)
- raise(Puppet::ParseError, 'fact(): Requires fact name to be a string')
- end
-
- raise(Puppet::ParseError, 'fact(): You must provide ' +
- 'fact name') if fact.empty?
-
- result = lookupvar(fact) # Get the value of interest from Facter ...
-
- #
- # Now this is a funny one ... Puppet does not have a concept of
- # returning neither undef nor nil back for use within the Puppet DSL
- # and empty string is as closest to actual undef as you we can get
- # at this point in time ...
- #
- result = result.empty? ? '' : result
-
- return result
- end
-end
-
-# vim: set ts=2 sw=2 et :
"given #{arguments.size} for 2")
end
+ a = arguments[0]
+ pattern = Regexp.new(arguments[1])
+
+ a.grep(pattern)
+
end
end
lambda { @scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should delete an item at specified location from an array" do
+ result = @scope.function_delete_at([['a','b','c'],1])
+ result.should(eq(['a','c']))
+ end
+
end
lambda { @scope.function_delete([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should delete an item from an array" do
+ result = @scope.function_delete([['a','b','c'],'b'])
+ result.should(eq(['a','c']))
+ end
+
end
lambda { @scope.function_downcase([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should downcase a string" do
+ result = @scope.function_downcase(["ASFD"])
+ result.should(eq("asfd"))
+ end
+
end
lambda { @scope.function_empty([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should return a true for an empty string" do
+ result = @scope.function_empty([''])
+ result.should(eq(true))
+ end
+
end
+++ /dev/null
-#!/usr/bin/env rspec
-require 'spec_helper'
-
-describe "the fact 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("fact").should == "function_fact"
- end
-
- it "should raise a ParseError if there is less than 1 arguments" do
- lambda { @scope.function_fact([]) }.should( raise_error(Puppet::ParseError))
- end
-
-end
lambda { @scope.function_flatten([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should flatten a complex data structure" do
+ result = @scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
+ result.should(eq(["a","b","c","d","e","f","g"]))
+ end
+
end
lambda { @scope.function_grep([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should grep contents from an array" do
+ result = @scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"])
+ result.should(eq(["aaabbb","bbbccc"]))
+ end
+
end
lambda { @scope.function_hash([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should convert an array to a hash" do
+ result = @scope.function_hash([['a',1,'b',2,'c',3]])
+ result.should(eq({'a'=>1,'b'=>2,'c'=>3}))
+ end
+
end
lambda { @scope.function_is_array([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should return true if passed an array" do
+ result = @scope.function_is_array([[1,2,3]])
+ result.should(eq(true))
+ end
+
+ it "should return false if passed a hash" do
+ result = @scope.function_is_array([{'a'=>1}])
+ result.should(eq(false))
+ end
+
end
lambda { @scope.function_is_float([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should return true if a float" do
+ result = @scope.function_is_float([0.12])
+ result.should(eq(true))
+ end
+
+ it "should return false if a string" do
+ result = @scope.function_is_float(["asdf"])
+ result.should(eq(false))
+ end
+
+ it "should return false if not an integer" do
+ result = @scope.function_is_float([3])
+ result.should(eq(false))
+ end
+
end
lambda { @scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should return true if passed a hash" do
+ result = @scope.function_is_hash([{"a"=>1,"b"=>2}])
+ result.should(eq(true))
+ end
+
+ it "should return false if passed an array" do
+ result = @scope.function_is_hash([["a","b"]])
+ result.should(eq(false))
+ end
+
+ it "should return false if passed a string" do
+ result = @scope.function_is_hash(["asdf"])
+ result.should(eq(false))
+ end
+
end
lambda { @scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should return true if an integer" do
+ result = @scope.function_is_integer([3])
+ result.should(eq(true))
+ end
+
+ it "should return false if a float" do
+ result = @scope.function_is_integer([3.2])
+ result.should(eq(false))
+ end
+
+ it "should return false if a string" do
+ result = @scope.function_is_integer(["asdf"])
+ result.should(eq(false))
+ end
+
end