summaryrefslogtreecommitdiff
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorKen Barber <ken@bob.sh>2011-06-29 21:21:55 +0100
committerKen Barber <ken@bob.sh>2011-06-29 21:21:55 +0100
commit790818116e953118ba9eab5e5bef6d63f7bbc1fa (patch)
tree3f56e221af94f481159a6848338c9f31d3b31e72 /lib/puppet/parser
parente071b05ab631f4b73fed7178c52d0416f7629cb8 (diff)
Added tests for each function, fixing functions as we hit bugs.
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/functions/date.rb6
-rw-r--r--lib/puppet/parser/functions/delete.rb6
-rw-r--r--lib/puppet/parser/functions/grep.rb6
-rw-r--r--lib/puppet/parser/functions/is_float.rb6
-rw-r--r--lib/puppet/parser/functions/is_integer.rb6
-rw-r--r--lib/puppet/parser/functions/is_numeric.rb6
-rw-r--r--lib/puppet/parser/functions/is_valid_domain_name.rb10
-rw-r--r--lib/puppet/parser/functions/is_valid_ip_address.rb6
-rw-r--r--lib/puppet/parser/functions/is_valid_mac_address.rb6
-rw-r--r--lib/puppet/parser/functions/is_valid_netmask.rb6
-rw-r--r--lib/puppet/parser/functions/load_json.rb12
-rw-r--r--lib/puppet/parser/functions/load_yaml.rb10
-rw-r--r--lib/puppet/parser/functions/rand.rb6
-rw-r--r--lib/puppet/parser/functions/sort.rb6
-rw-r--r--lib/puppet/parser/functions/squeeze.rb6
-rw-r--r--lib/puppet/parser/functions/time.rb5
16 files changed, 107 insertions, 2 deletions
diff --git a/lib/puppet/parser/functions/date.rb b/lib/puppet/parser/functions/date.rb
index ea11265..4d0543e 100644
--- a/lib/puppet/parser/functions/date.rb
+++ b/lib/puppet/parser/functions/date.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:date, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_valid_netmask(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb
index b8376d1..88f3448 100644
--- a/lib/puppet/parser/functions/delete.rb
+++ b/lib/puppet/parser/functions/delete.rb
@@ -9,6 +9,12 @@ module Puppet::Parser::Functions
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 2) then
+ raise(Puppet::ParseError, "is_valid_netmask(): Wrong number of arguments "+
+ "given #{arguments.size} for 2")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/grep.rb b/lib/puppet/parser/functions/grep.rb
index 1663fe7..8549218 100644
--- a/lib/puppet/parser/functions/grep.rb
+++ b/lib/puppet/parser/functions/grep.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:grep, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 2) then
+ raise(Puppet::ParseError, "grep(): Wrong number of arguments "+
+ "given #{arguments.size} for 2")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb
index 2a5a923..39d097f 100644
--- a/lib/puppet/parser/functions/is_float.rb
+++ b/lib/puppet/parser/functions/is_float.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:is_float, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb
index 44337f0..9813cf1 100644
--- a/lib/puppet/parser/functions/is_integer.rb
+++ b/lib/puppet/parser/functions/is_integer.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb
index 7a64091..96e8674 100644
--- a/lib/puppet/parser/functions/is_numeric.rb
+++ b/lib/puppet/parser/functions/is_numeric.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/is_valid_domain_name.rb b/lib/puppet/parser/functions/is_valid_domain_name.rb
index 05d64be..c0b319c 100644
--- a/lib/puppet/parser/functions/is_valid_domain_name.rb
+++ b/lib/puppet/parser/functions/is_valid_domain_name.rb
@@ -1,11 +1,17 @@
#
-# is_valid_doman_name.rb
+# is_valid_domain_name.rb
#
module Puppet::Parser::Functions
- newfunction(:is_valid_doman_name, :type => :rvalue, :doc => <<-EOS
+ newfunction(:is_valid_domain_name, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_valid_domain_name(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/is_valid_ip_address.rb b/lib/puppet/parser/functions/is_valid_ip_address.rb
index e6b68a8..e91dda8 100644
--- a/lib/puppet/parser/functions/is_valid_ip_address.rb
+++ b/lib/puppet/parser/functions/is_valid_ip_address.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:is_valid_ip_address, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_valid_ip_address(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/is_valid_mac_address.rb b/lib/puppet/parser/functions/is_valid_mac_address.rb
index 5e354c9..0b91d0d 100644
--- a/lib/puppet/parser/functions/is_valid_mac_address.rb
+++ b/lib/puppet/parser/functions/is_valid_mac_address.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:is_valid_mac_address, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_valid_mac_address(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/is_valid_netmask.rb b/lib/puppet/parser/functions/is_valid_netmask.rb
index 2aeb374..41e4843 100644
--- a/lib/puppet/parser/functions/is_valid_netmask.rb
+++ b/lib/puppet/parser/functions/is_valid_netmask.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:is_valid_netmask, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_valid_netmask(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/load_json.rb b/lib/puppet/parser/functions/load_json.rb
index 9ec8c78..7c3f187 100644
--- a/lib/puppet/parser/functions/load_json.rb
+++ b/lib/puppet/parser/functions/load_json.rb
@@ -6,6 +6,18 @@ module Puppet::Parser::Functions
newfunction(:load_json, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "load_json(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ json = arguments[0]
+
+ require 'json'
+
+ JSON.load(json)
+
end
end
diff --git a/lib/puppet/parser/functions/load_yaml.rb b/lib/puppet/parser/functions/load_yaml.rb
index 684a721..1bc2f36 100644
--- a/lib/puppet/parser/functions/load_yaml.rb
+++ b/lib/puppet/parser/functions/load_yaml.rb
@@ -6,6 +6,16 @@ module Puppet::Parser::Functions
newfunction(:load_yaml, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "load_yaml(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ require 'yaml'
+
+ YAML::load(arguments[0])
+
end
end
diff --git a/lib/puppet/parser/functions/rand.rb b/lib/puppet/parser/functions/rand.rb
index 2cb9acb..6d870dc 100644
--- a/lib/puppet/parser/functions/rand.rb
+++ b/lib/puppet/parser/functions/rand.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:rand, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 0) and (arguments.size != 1) then
+ raise(Puppet::ParseError, "rand(): Wrong number of arguments "+
+ "given #{arguments.size} for 0 or 1")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb
index 85e5ba0..974141c 100644
--- a/lib/puppet/parser/functions/sort.rb
+++ b/lib/puppet/parser/functions/sort.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:sort, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 0) then
+ raise(Puppet::ParseError, "sort(): Wrong number of arguments "+
+ "given #{arguments.size} for 0")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/squeeze.rb b/lib/puppet/parser/functions/squeeze.rb
index a135bd3..02eb00c 100644
--- a/lib/puppet/parser/functions/squeeze.rb
+++ b/lib/puppet/parser/functions/squeeze.rb
@@ -6,6 +6,12 @@ module Puppet::Parser::Functions
newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
+
+ if (arguments.size != 2) then
+ raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+
+ "given #{arguments.size} for 2")
+ end
+
end
end
diff --git a/lib/puppet/parser/functions/time.rb b/lib/puppet/parser/functions/time.rb
index f7c1041..e1f5b6f 100644
--- a/lib/puppet/parser/functions/time.rb
+++ b/lib/puppet/parser/functions/time.rb
@@ -10,6 +10,11 @@ module Puppet::Parser::Functions
# The Time Zone argument is optional ...
time_zone = arguments[0] if arguments[0]
+ if (arguments.size != 0) and (arguments.size != 1) then
+ raise(Puppet::ParseError, "time(): Wrong number of arguments "+
+ "given #{arguments.size} for 0 or 1")
+ end
+
time = Time.new
# There is probably a better way to handle Time Zone ...