From aafce9c99b779855e1e10e5a337848fa9f676a01 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sat, 30 Apr 2011 16:00:49 +0200 Subject: Moved more functions into lib/puppet/parser/functions/ --- lib/puppet/parser/functions/sort.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/puppet/parser/functions/sort.rb (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb new file mode 100644 index 0000000..85e5ba0 --- /dev/null +++ b/lib/puppet/parser/functions/sort.rb @@ -0,0 +1,12 @@ +# +# sort.rb +# + +module Puppet::Parser::Functions + newfunction(:sort, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : -- cgit v1.2.3 From 790818116e953118ba9eab5e5bef6d63f7bbc1fa Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Wed, 29 Jun 2011 21:21:55 +0100 Subject: Added tests for each function, fixing functions as we hit bugs. --- .gitignore | 1 + lib/puppet/parser/functions/date.rb | 6 +++++ lib/puppet/parser/functions/delete.rb | 6 +++++ lib/puppet/parser/functions/grep.rb | 6 +++++ lib/puppet/parser/functions/is_float.rb | 6 +++++ lib/puppet/parser/functions/is_integer.rb | 6 +++++ lib/puppet/parser/functions/is_numeric.rb | 6 +++++ .../parser/functions/is_valid_domain_name.rb | 10 +++++-- lib/puppet/parser/functions/is_valid_ip_address.rb | 6 +++++ .../parser/functions/is_valid_mac_address.rb | 6 +++++ lib/puppet/parser/functions/is_valid_netmask.rb | 6 +++++ lib/puppet/parser/functions/load_json.rb | 12 +++++++++ lib/puppet/parser/functions/load_yaml.rb | 10 +++++++ lib/puppet/parser/functions/rand.rb | 6 +++++ lib/puppet/parser/functions/sort.rb | 6 +++++ lib/puppet/parser/functions/squeeze.rb | 6 +++++ lib/puppet/parser/functions/time.rb | 5 ++++ spec/unit/parser/functions/abs_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/bool2num_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/capitalize_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/chomp_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/chop_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/count_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/date_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/delete_at_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/delete_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/downcase_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/empty_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/fact_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/flatten_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/grep_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/hash_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/is_array_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/is_float_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/is_hash_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/is_integer_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/is_numeric_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/is_string_spec.rb | 21 +++++++++++++++ .../parser/functions/is_valid_domain_name_spec.rb | 21 +++++++++++++++ .../parser/functions/is_valid_ip_address_spec.rb | 21 +++++++++++++++ .../parser/functions/is_valid_mac_address_spec.rb | 21 +++++++++++++++ .../unit/parser/functions/is_valid_netmask_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/join_spec.rb | 21 +++++++++++++++ .../unit/parser/functions/join_with_prefix_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/keys_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/kwalify_spec.rb | 1 + spec/unit/parser/functions/load_json_spec.rb | 29 ++++++++++++++++++++ spec/unit/parser/functions/load_variables_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/load_yaml_spec.rb | 31 ++++++++++++++++++++++ spec/unit/parser/functions/lstrip_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/member_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/num2bool_spec.rb | 21 +++++++++++++++ .../functions/persistent_crontab_minutes_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/prefix_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/rand_spec.rb | 21 +++++++++++++++ .../functions/random_crontab_minutes_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/range_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/reverse_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/rstrip_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/shuffle_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/size_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/sort_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/squeeze_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/str2bool_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/strftime_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/strip_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/swapcase_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/time_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/type_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/unique_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/upcase_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/values_at_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/values_spec.rb | 21 +++++++++++++++ spec/unit/parser/functions/zip_spec.rb | 21 +++++++++++++++ 74 files changed, 1303 insertions(+), 2 deletions(-) create mode 100755 spec/unit/parser/functions/abs_spec.rb create mode 100755 spec/unit/parser/functions/bool2num_spec.rb create mode 100755 spec/unit/parser/functions/capitalize_spec.rb create mode 100755 spec/unit/parser/functions/chomp_spec.rb create mode 100755 spec/unit/parser/functions/chop_spec.rb create mode 100755 spec/unit/parser/functions/count_spec.rb create mode 100755 spec/unit/parser/functions/date_spec.rb create mode 100755 spec/unit/parser/functions/delete_at_spec.rb create mode 100755 spec/unit/parser/functions/delete_spec.rb create mode 100755 spec/unit/parser/functions/downcase_spec.rb create mode 100755 spec/unit/parser/functions/empty_spec.rb create mode 100755 spec/unit/parser/functions/fact_spec.rb create mode 100755 spec/unit/parser/functions/flatten_spec.rb create mode 100755 spec/unit/parser/functions/grep_spec.rb create mode 100644 spec/unit/parser/functions/hash_spec.rb create mode 100644 spec/unit/parser/functions/is_array_spec.rb create mode 100644 spec/unit/parser/functions/is_float_spec.rb create mode 100644 spec/unit/parser/functions/is_hash_spec.rb create mode 100644 spec/unit/parser/functions/is_integer_spec.rb create mode 100644 spec/unit/parser/functions/is_numeric_spec.rb create mode 100644 spec/unit/parser/functions/is_string_spec.rb create mode 100644 spec/unit/parser/functions/is_valid_domain_name_spec.rb create mode 100644 spec/unit/parser/functions/is_valid_ip_address_spec.rb create mode 100644 spec/unit/parser/functions/is_valid_mac_address_spec.rb create mode 100644 spec/unit/parser/functions/is_valid_netmask_spec.rb create mode 100644 spec/unit/parser/functions/join_spec.rb create mode 100644 spec/unit/parser/functions/join_with_prefix_spec.rb create mode 100644 spec/unit/parser/functions/keys_spec.rb create mode 100644 spec/unit/parser/functions/load_json_spec.rb create mode 100644 spec/unit/parser/functions/load_variables_spec.rb create mode 100644 spec/unit/parser/functions/load_yaml_spec.rb create mode 100644 spec/unit/parser/functions/lstrip_spec.rb create mode 100644 spec/unit/parser/functions/member_spec.rb create mode 100644 spec/unit/parser/functions/num2bool_spec.rb create mode 100644 spec/unit/parser/functions/persistent_crontab_minutes_spec.rb create mode 100644 spec/unit/parser/functions/prefix_spec.rb create mode 100644 spec/unit/parser/functions/rand_spec.rb create mode 100644 spec/unit/parser/functions/random_crontab_minutes_spec.rb create mode 100644 spec/unit/parser/functions/range_spec.rb create mode 100644 spec/unit/parser/functions/reverse_spec.rb create mode 100644 spec/unit/parser/functions/rstrip_spec.rb create mode 100644 spec/unit/parser/functions/shuffle_spec.rb create mode 100644 spec/unit/parser/functions/size_spec.rb create mode 100644 spec/unit/parser/functions/sort_spec.rb create mode 100644 spec/unit/parser/functions/squeeze_spec.rb create mode 100644 spec/unit/parser/functions/str2bool_spec.rb create mode 100644 spec/unit/parser/functions/strftime_spec.rb create mode 100644 spec/unit/parser/functions/strip_spec.rb create mode 100644 spec/unit/parser/functions/swapcase_spec.rb create mode 100644 spec/unit/parser/functions/time_spec.rb create mode 100644 spec/unit/parser/functions/type_spec.rb create mode 100644 spec/unit/parser/functions/unique_spec.rb create mode 100644 spec/unit/parser/functions/upcase_spec.rb create mode 100644 spec/unit/parser/functions/values_at_spec.rb create mode 100644 spec/unit/parser/functions/values_spec.rb create mode 100644 spec/unit/parser/functions/zip_spec.rb (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/.gitignore b/.gitignore index 01d0a08..7ad8fca 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ pkg/ +coverage/ 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 ... diff --git a/spec/unit/parser/functions/abs_spec.rb b/spec/unit/parser/functions/abs_spec.rb new file mode 100755 index 0000000..cd2902a --- /dev/null +++ b/spec/unit/parser/functions/abs_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the abs 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("abs").should == "function_abs" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_abs([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/bool2num_spec.rb b/spec/unit/parser/functions/bool2num_spec.rb new file mode 100755 index 0000000..a2585e9 --- /dev/null +++ b/spec/unit/parser/functions/bool2num_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the bool2num 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("bool2num").should == "function_bool2num" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/capitalize_spec.rb b/spec/unit/parser/functions/capitalize_spec.rb new file mode 100755 index 0000000..bb1fe2a --- /dev/null +++ b/spec/unit/parser/functions/capitalize_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the capitalize 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("capitalize").should == "function_capitalize" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/chomp_spec.rb b/spec/unit/parser/functions/chomp_spec.rb new file mode 100755 index 0000000..150a7c8 --- /dev/null +++ b/spec/unit/parser/functions/chomp_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the chomp 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("chomp").should == "function_chomp" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_chomp([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/chop_spec.rb b/spec/unit/parser/functions/chop_spec.rb new file mode 100755 index 0000000..ae636cb --- /dev/null +++ b/spec/unit/parser/functions/chop_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the chop 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("chop").should == "function_chop" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_chop([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/count_spec.rb b/spec/unit/parser/functions/count_spec.rb new file mode 100755 index 0000000..28617c9 --- /dev/null +++ b/spec/unit/parser/functions/count_spec.rb @@ -0,0 +1,21 @@ +#!/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 + +end diff --git a/spec/unit/parser/functions/date_spec.rb b/spec/unit/parser/functions/date_spec.rb new file mode 100755 index 0000000..dcba4af --- /dev/null +++ b/spec/unit/parser/functions/date_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the date 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("date").should == "function_date" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_date([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/delete_at_spec.rb b/spec/unit/parser/functions/delete_at_spec.rb new file mode 100755 index 0000000..a0b5b06 --- /dev/null +++ b/spec/unit/parser/functions/delete_at_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the delete_at 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("delete_at").should == "function_delete_at" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/delete_spec.rb b/spec/unit/parser/functions/delete_spec.rb new file mode 100755 index 0000000..b0729ab --- /dev/null +++ b/spec/unit/parser/functions/delete_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the delete 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("delete").should == "function_delete" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_delete([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/downcase_spec.rb b/spec/unit/parser/functions/downcase_spec.rb new file mode 100755 index 0000000..162291c --- /dev/null +++ b/spec/unit/parser/functions/downcase_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the downcase 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("downcase").should == "function_downcase" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_downcase([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/empty_spec.rb b/spec/unit/parser/functions/empty_spec.rb new file mode 100755 index 0000000..beaf45c --- /dev/null +++ b/spec/unit/parser/functions/empty_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the empty 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("empty").should == "function_empty" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_empty([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/fact_spec.rb b/spec/unit/parser/functions/fact_spec.rb new file mode 100755 index 0000000..c013ae0 --- /dev/null +++ b/spec/unit/parser/functions/fact_spec.rb @@ -0,0 +1,21 @@ +#!/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 diff --git a/spec/unit/parser/functions/flatten_spec.rb b/spec/unit/parser/functions/flatten_spec.rb new file mode 100755 index 0000000..7af23c1 --- /dev/null +++ b/spec/unit/parser/functions/flatten_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the flatten 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("flatten").should == "function_flatten" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_flatten([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/grep_spec.rb b/spec/unit/parser/functions/grep_spec.rb new file mode 100755 index 0000000..1c949da --- /dev/null +++ b/spec/unit/parser/functions/grep_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the grep 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("grep").should == "function_grep" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_grep([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/hash_spec.rb b/spec/unit/parser/functions/hash_spec.rb new file mode 100644 index 0000000..09b0d50 --- /dev/null +++ b/spec/unit/parser/functions/hash_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the hash 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("hash").should == "function_hash" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_hash([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_array_spec.rb b/spec/unit/parser/functions/is_array_spec.rb new file mode 100644 index 0000000..b2843b0 --- /dev/null +++ b/spec/unit/parser/functions/is_array_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_array 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("is_array").should == "function_is_array" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_array([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_float_spec.rb b/spec/unit/parser/functions/is_float_spec.rb new file mode 100644 index 0000000..e3dc8fc --- /dev/null +++ b/spec/unit/parser/functions/is_float_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_float 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("is_float").should == "function_is_float" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_float([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_hash_spec.rb b/spec/unit/parser/functions/is_hash_spec.rb new file mode 100644 index 0000000..66dfdeb --- /dev/null +++ b/spec/unit/parser/functions/is_hash_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_hash 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("is_hash").should == "function_is_hash" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_integer_spec.rb b/spec/unit/parser/functions/is_integer_spec.rb new file mode 100644 index 0000000..131251c --- /dev/null +++ b/spec/unit/parser/functions/is_integer_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_integer 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("is_integer").should == "function_is_integer" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_numeric_spec.rb b/spec/unit/parser/functions/is_numeric_spec.rb new file mode 100644 index 0000000..3a49f5d --- /dev/null +++ b/spec/unit/parser/functions/is_numeric_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_numeric 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("is_numeric").should == "function_is_numeric" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_string_spec.rb b/spec/unit/parser/functions/is_string_spec.rb new file mode 100644 index 0000000..8c0061e --- /dev/null +++ b/spec/unit/parser/functions/is_string_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_string 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("is_string").should == "function_is_string" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_string([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_valid_domain_name_spec.rb b/spec/unit/parser/functions/is_valid_domain_name_spec.rb new file mode 100644 index 0000000..5cea285 --- /dev/null +++ b/spec/unit/parser/functions/is_valid_domain_name_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_valid_domain_name 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("is_valid_domain_name").should == "function_is_valid_domain_name" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_valid_domain_name([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_valid_ip_address_spec.rb b/spec/unit/parser/functions/is_valid_ip_address_spec.rb new file mode 100644 index 0000000..fa803dd --- /dev/null +++ b/spec/unit/parser/functions/is_valid_ip_address_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_valid_ip_address 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("is_valid_ip_address").should == "function_is_valid_ip_address" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_valid_ip_address([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_valid_mac_address_spec.rb b/spec/unit/parser/functions/is_valid_mac_address_spec.rb new file mode 100644 index 0000000..f2a8389 --- /dev/null +++ b/spec/unit/parser/functions/is_valid_mac_address_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_valid_mac_address 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("is_valid_mac_address").should == "function_is_valid_mac_address" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_valid_mac_address([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/is_valid_netmask_spec.rb b/spec/unit/parser/functions/is_valid_netmask_spec.rb new file mode 100644 index 0000000..97cbb7c --- /dev/null +++ b/spec/unit/parser/functions/is_valid_netmask_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_valid_netmask 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("is_valid_netmask").should == "function_is_valid_netmask" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_valid_netmask([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/join_spec.rb b/spec/unit/parser/functions/join_spec.rb new file mode 100644 index 0000000..a7dc0e5 --- /dev/null +++ b/spec/unit/parser/functions/join_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the join 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("join").should == "function_join" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_join([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/join_with_prefix_spec.rb b/spec/unit/parser/functions/join_with_prefix_spec.rb new file mode 100644 index 0000000..0182d8c --- /dev/null +++ b/spec/unit/parser/functions/join_with_prefix_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the join_with_prefix 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("join_with_prefix").should == "function_join_with_prefix" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_join_with_prefix([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/keys_spec.rb b/spec/unit/parser/functions/keys_spec.rb new file mode 100644 index 0000000..13dc260 --- /dev/null +++ b/spec/unit/parser/functions/keys_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the keys 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("keys").should == "function_keys" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_keys([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/kwalify_spec.rb b/spec/unit/parser/functions/kwalify_spec.rb index b2afa12..abdd529 100755 --- a/spec/unit/parser/functions/kwalify_spec.rb +++ b/spec/unit/parser/functions/kwalify_spec.rb @@ -56,6 +56,7 @@ describe "the kwalify function" do 'key1' => 'b', 'key2' => 'c', } + @scope.function_kwalify([schema, document]) end end diff --git a/spec/unit/parser/functions/load_json_spec.rb b/spec/unit/parser/functions/load_json_spec.rb new file mode 100644 index 0000000..73a4566 --- /dev/null +++ b/spec/unit/parser/functions/load_json_spec.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the load_json 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("load_json").should == "function_load_json" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_load_json([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert JSON to a data structure" do + json = <<-EOS +["aaa","bbb","ccc"] +EOS + result = @scope.function_load_json([json]) + result.should(eq(['aaa','bbb','ccc'])) + end + +end diff --git a/spec/unit/parser/functions/load_variables_spec.rb b/spec/unit/parser/functions/load_variables_spec.rb new file mode 100644 index 0000000..dc29e61 --- /dev/null +++ b/spec/unit/parser/functions/load_variables_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the load_variables 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("load_variables").should == "function_load_variables" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_load_variables([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/load_yaml_spec.rb b/spec/unit/parser/functions/load_yaml_spec.rb new file mode 100644 index 0000000..2498d12 --- /dev/null +++ b/spec/unit/parser/functions/load_yaml_spec.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the load_yaml 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("load_yaml").should == "function_load_yaml" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_load_yaml([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert YAML to a data structure" do + yaml = <<-EOS +- aaa +- bbb +- ccc +EOS + result = @scope.function_load_yaml([yaml]) + result.should(eq(['aaa','bbb','ccc'])) + end + +end diff --git a/spec/unit/parser/functions/lstrip_spec.rb b/spec/unit/parser/functions/lstrip_spec.rb new file mode 100644 index 0000000..9726675 --- /dev/null +++ b/spec/unit/parser/functions/lstrip_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the lstrip 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("lstrip").should == "function_lstrip" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/member_spec.rb b/spec/unit/parser/functions/member_spec.rb new file mode 100644 index 0000000..39b684f --- /dev/null +++ b/spec/unit/parser/functions/member_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the member 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("member").should == "function_member" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_member([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/num2bool_spec.rb b/spec/unit/parser/functions/num2bool_spec.rb new file mode 100644 index 0000000..fbd25c8 --- /dev/null +++ b/spec/unit/parser/functions/num2bool_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the num2bool 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("num2bool").should == "function_num2bool" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/persistent_crontab_minutes_spec.rb b/spec/unit/parser/functions/persistent_crontab_minutes_spec.rb new file mode 100644 index 0000000..1d8cbe7 --- /dev/null +++ b/spec/unit/parser/functions/persistent_crontab_minutes_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the persistent_crontab_minutes 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("persistent_crontab_minutes").should == "function_persistent_crontab_minutes" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_persistent_crontab_minutes([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/prefix_spec.rb b/spec/unit/parser/functions/prefix_spec.rb new file mode 100644 index 0000000..9ede439 --- /dev/null +++ b/spec/unit/parser/functions/prefix_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the prefix 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("prefix").should == "function_prefix" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_prefix([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/rand_spec.rb b/spec/unit/parser/functions/rand_spec.rb new file mode 100644 index 0000000..818d1c5 --- /dev/null +++ b/spec/unit/parser/functions/rand_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the rand 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("rand").should == "function_rand" + end + + it "should raise a ParseError if there is not 0 or 1 arguments" do + lambda { @scope.function_rand(['a','b']) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/random_crontab_minutes_spec.rb b/spec/unit/parser/functions/random_crontab_minutes_spec.rb new file mode 100644 index 0000000..b47b3ae --- /dev/null +++ b/spec/unit/parser/functions/random_crontab_minutes_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the random_crontab_minutes 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("random_crontab_minutes").should == "function_random_crontab_minutes" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_random_crontab_minutes([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/range_spec.rb b/spec/unit/parser/functions/range_spec.rb new file mode 100644 index 0000000..23310bc --- /dev/null +++ b/spec/unit/parser/functions/range_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the range 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("range").should == "function_range" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_range([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/reverse_spec.rb b/spec/unit/parser/functions/reverse_spec.rb new file mode 100644 index 0000000..27aa2cf --- /dev/null +++ b/spec/unit/parser/functions/reverse_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the reverse 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("reverse").should == "function_reverse" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_reverse([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/rstrip_spec.rb b/spec/unit/parser/functions/rstrip_spec.rb new file mode 100644 index 0000000..a6e73ec --- /dev/null +++ b/spec/unit/parser/functions/rstrip_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the rstrip 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("rstrip").should == "function_rstrip" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/shuffle_spec.rb b/spec/unit/parser/functions/shuffle_spec.rb new file mode 100644 index 0000000..cf063c6 --- /dev/null +++ b/spec/unit/parser/functions/shuffle_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the shuffle 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("shuffle").should == "function_shuffle" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/size_spec.rb b/spec/unit/parser/functions/size_spec.rb new file mode 100644 index 0000000..0d1f0c4 --- /dev/null +++ b/spec/unit/parser/functions/size_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the size 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("size").should == "function_size" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_size([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/sort_spec.rb b/spec/unit/parser/functions/sort_spec.rb new file mode 100644 index 0000000..ae62d5f --- /dev/null +++ b/spec/unit/parser/functions/sort_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the sort 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("sort").should == "function_sort" + end + + it "should raise a ParseError if there is not 0 arguments" do + lambda { @scope.function_sort(['']) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/squeeze_spec.rb b/spec/unit/parser/functions/squeeze_spec.rb new file mode 100644 index 0000000..da8965c --- /dev/null +++ b/spec/unit/parser/functions/squeeze_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the squeeze 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("squeeze").should == "function_squeeze" + end + + it "should raise a ParseError if there is less than 2 arguments" do + lambda { @scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/str2bool_spec.rb b/spec/unit/parser/functions/str2bool_spec.rb new file mode 100644 index 0000000..6a1ac95 --- /dev/null +++ b/spec/unit/parser/functions/str2bool_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the str2bool 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("str2bool").should == "function_str2bool" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/strftime_spec.rb b/spec/unit/parser/functions/strftime_spec.rb new file mode 100644 index 0000000..e377954 --- /dev/null +++ b/spec/unit/parser/functions/strftime_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the strftime 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("strftime").should == "function_strftime" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_strftime([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/strip_spec.rb b/spec/unit/parser/functions/strip_spec.rb new file mode 100644 index 0000000..ca06845 --- /dev/null +++ b/spec/unit/parser/functions/strip_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the strip 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("strip").should == "function_strip" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_strip([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/swapcase_spec.rb b/spec/unit/parser/functions/swapcase_spec.rb new file mode 100644 index 0000000..7c5ff30 --- /dev/null +++ b/spec/unit/parser/functions/swapcase_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the swapcase 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("swapcase").should == "function_swapcase" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/time_spec.rb b/spec/unit/parser/functions/time_spec.rb new file mode 100644 index 0000000..8bf5982 --- /dev/null +++ b/spec/unit/parser/functions/time_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the time 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("time").should == "function_time" + end + + it "should raise a ParseError if there is more than 2 arguments" do + lambda { @scope.function_time(['','']) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/type_spec.rb b/spec/unit/parser/functions/type_spec.rb new file mode 100644 index 0000000..4109da1 --- /dev/null +++ b/spec/unit/parser/functions/type_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the type 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("type").should == "function_type" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_type([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/unique_spec.rb b/spec/unit/parser/functions/unique_spec.rb new file mode 100644 index 0000000..fe7b3ca --- /dev/null +++ b/spec/unit/parser/functions/unique_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the unique 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("unique").should == "function_unique" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_unique([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/upcase_spec.rb b/spec/unit/parser/functions/upcase_spec.rb new file mode 100644 index 0000000..39884eb --- /dev/null +++ b/spec/unit/parser/functions/upcase_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the upcase 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("upcase").should == "function_upcase" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_upcase([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/values_at_spec.rb b/spec/unit/parser/functions/values_at_spec.rb new file mode 100644 index 0000000..af5dc25 --- /dev/null +++ b/spec/unit/parser/functions/values_at_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the values_at 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("values_at").should == "function_values_at" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_values_at([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/values_spec.rb b/spec/unit/parser/functions/values_spec.rb new file mode 100644 index 0000000..2c313a0 --- /dev/null +++ b/spec/unit/parser/functions/values_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the values 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("values").should == "function_values" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_values([]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/parser/functions/zip_spec.rb b/spec/unit/parser/functions/zip_spec.rb new file mode 100644 index 0000000..3d0392a --- /dev/null +++ b/spec/unit/parser/functions/zip_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the zip 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("zip").should == "function_zip" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_zip([]) }.should( raise_error(Puppet::ParseError)) + end + +end -- cgit v1.2.3 From fde64f37c98291f4a5b9ee1fcf634288e42b730a Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sun, 24 Jul 2011 00:39:17 +0100 Subject: (#1) - fleshed out some more tests. --- lib/puppet/parser/functions/sort.rb | 6 ++++-- lib/puppet/parser/functions/squeeze.rb | 21 +++++++++++++++++++-- .../parser/functions/is_valid_domain_name_spec.rb | 10 ++++++++++ .../parser/functions/is_valid_ip_address_spec.rb | 10 ++++++++++ .../parser/functions/is_valid_mac_address_spec.rb | 10 ++++++++++ spec/unit/parser/functions/join_spec.rb | 5 +++++ spec/unit/parser/functions/join_with_prefix_spec.rb | 5 +++++ spec/unit/parser/functions/keys_spec.rb | 5 +++++ spec/unit/parser/functions/lstrip_spec.rb | 5 +++++ spec/unit/parser/functions/member_spec.rb | 10 ++++++++++ spec/unit/parser/functions/num2bool_spec.rb | 5 +++++ spec/unit/parser/functions/prefix_spec.rb | 5 +++++ spec/unit/parser/functions/range_spec.rb | 10 ++++++++++ spec/unit/parser/functions/reverse_spec.rb | 5 +++++ spec/unit/parser/functions/rstrip_spec.rb | 10 ++++++++++ spec/unit/parser/functions/size_spec.rb | 10 ++++++++++ spec/unit/parser/functions/sort_spec.rb | 9 +++++++-- spec/unit/parser/functions/squeeze_spec.rb | 10 ++++++++++ spec/unit/parser/functions/str2bool_spec.rb | 10 ++++++++++ spec/unit/parser/functions/strip_spec.rb | 5 +++++ spec/unit/parser/functions/swapcase_spec.rb | 5 +++++ spec/unit/parser/functions/type_spec.rb | 5 +++++ spec/unit/parser/functions/unique_spec.rb | 5 +++++ spec/unit/parser/functions/upcase_spec.rb | 5 +++++ spec/unit/parser/functions/values_at_spec.rb | 5 +++++ spec/unit/parser/functions/values_spec.rb | 5 +++++ spec/unit/parser/functions/zip_spec.rb | 5 +++++ 27 files changed, 195 insertions(+), 6 deletions(-) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 974141c..54a4018 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -7,11 +7,13 @@ module Puppet::Parser::Functions EOS ) do |arguments| - if (arguments.size != 0) then + if (arguments.size != 1) then raise(Puppet::ParseError, "sort(): Wrong number of arguments "+ - "given #{arguments.size} for 0") + "given #{arguments.size} for 1") end + arguments[0].sort + end end diff --git a/lib/puppet/parser/functions/squeeze.rb b/lib/puppet/parser/functions/squeeze.rb index 02eb00c..9a1dd20 100644 --- a/lib/puppet/parser/functions/squeeze.rb +++ b/lib/puppet/parser/functions/squeeze.rb @@ -7,9 +7,26 @@ module Puppet::Parser::Functions EOS ) do |arguments| - if (arguments.size != 2) then + if ((arguments.size != 2) and (arguments.size != 1)) then raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+ - "given #{arguments.size} for 2") + "given #{arguments.size} for 2 or 1") + end + + item = arguments[0] + squeezeval = arguments[1] + + if item.is_a?(Array) then + if squeezeval then + item.collect { |i| i.squeeze(squeezeval) } + else + item.collect { |i| i.squeeze } + end + else + if squeezeval then + item.squeeze(squeezeval) + else + item.squeeze + end end end diff --git a/spec/unit/parser/functions/is_valid_domain_name_spec.rb b/spec/unit/parser/functions/is_valid_domain_name_spec.rb index 5cea285..f03f6e8 100644 --- a/spec/unit/parser/functions/is_valid_domain_name_spec.rb +++ b/spec/unit/parser/functions/is_valid_domain_name_spec.rb @@ -18,4 +18,14 @@ describe "the is_valid_domain_name function" do lambda { @scope.function_is_valid_domain_name([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if a valid domain name" do + result = @scope.function_is_valid_domain_name("foo.bar.com") + result.should(eq(true)) + end + + it "should return false if not a valid domain name" do + result = @scope.function_is_valid_domain_name("not valid") + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/is_valid_ip_address_spec.rb b/spec/unit/parser/functions/is_valid_ip_address_spec.rb index fa803dd..ee53ee1 100644 --- a/spec/unit/parser/functions/is_valid_ip_address_spec.rb +++ b/spec/unit/parser/functions/is_valid_ip_address_spec.rb @@ -18,4 +18,14 @@ describe "the is_valid_ip_address function" do lambda { @scope.function_is_valid_ip_address([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if an IP address" do + result = @scope.function_is_valid_ip_address("1.2.3.4") + result.should(eq(true)) + end + + it "should return false if not valid" do + result = @scope.function_is_valid_ip_address("asdf") + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/is_valid_mac_address_spec.rb b/spec/unit/parser/functions/is_valid_mac_address_spec.rb index f2a8389..c4eb468 100644 --- a/spec/unit/parser/functions/is_valid_mac_address_spec.rb +++ b/spec/unit/parser/functions/is_valid_mac_address_spec.rb @@ -18,4 +18,14 @@ describe "the is_valid_mac_address function" do lambda { @scope.function_is_valid_mac_address([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if a valid mac address" do + result = @scope.function_is_valid_mac_address("00:a0:1f:12:7f:a0") + result.should(eq(true)) + end + + it "should return false if not valid" do + result = @scope.function_is_valid_mac_address("not valid") + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/join_spec.rb b/spec/unit/parser/functions/join_spec.rb index a7dc0e5..1b3dec8 100644 --- a/spec/unit/parser/functions/join_spec.rb +++ b/spec/unit/parser/functions/join_spec.rb @@ -18,4 +18,9 @@ describe "the join function" do lambda { @scope.function_join([]) }.should( raise_error(Puppet::ParseError)) end + it "should join an array into a string" do + result = @scope.function_join([["a","b","c"], ":"]) + result.should(eq("a:b:c")) + end + end diff --git a/spec/unit/parser/functions/join_with_prefix_spec.rb b/spec/unit/parser/functions/join_with_prefix_spec.rb index 0182d8c..70e6965 100644 --- a/spec/unit/parser/functions/join_with_prefix_spec.rb +++ b/spec/unit/parser/functions/join_with_prefix_spec.rb @@ -18,4 +18,9 @@ describe "the join_with_prefix function" do lambda { @scope.function_join_with_prefix([]) }.should( raise_error(Puppet::ParseError)) end + it "should join an array into a string" do + result = @scope.function_join_with_prefix([["a","b","c"], ":", "p"]) + result.should(eq("pa:pb:pc")) + end + end diff --git a/spec/unit/parser/functions/keys_spec.rb b/spec/unit/parser/functions/keys_spec.rb index 13dc260..927be96 100644 --- a/spec/unit/parser/functions/keys_spec.rb +++ b/spec/unit/parser/functions/keys_spec.rb @@ -18,4 +18,9 @@ describe "the keys function" do lambda { @scope.function_keys([]) }.should( raise_error(Puppet::ParseError)) end + it "should return an array of keys when given a hash" do + result = @scope.function_keys([{'a'=>1, 'b' => 2}]) + result.should(eq(['a','b'])) + end + end diff --git a/spec/unit/parser/functions/lstrip_spec.rb b/spec/unit/parser/functions/lstrip_spec.rb index 9726675..ac331fa 100644 --- a/spec/unit/parser/functions/lstrip_spec.rb +++ b/spec/unit/parser/functions/lstrip_spec.rb @@ -18,4 +18,9 @@ describe "the lstrip function" do lambda { @scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError)) end + it "should lstrip a string" do + result = @scope.function_lstrip([" asdf"]) + result.should(eq('asdf')) + end + end diff --git a/spec/unit/parser/functions/member_spec.rb b/spec/unit/parser/functions/member_spec.rb index 39b684f..2cebc0d 100644 --- a/spec/unit/parser/functions/member_spec.rb +++ b/spec/unit/parser/functions/member_spec.rb @@ -18,4 +18,14 @@ describe "the member function" do lambda { @scope.function_member([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if a member is in an array" do + result = @scope.function_member([["a","b","c"], "a"]) + result.should(eq(true)) + end + + it "should return false if a member is not in an array" do + result = @scope.function_member([["a","b","c"], "d"]) + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/num2bool_spec.rb b/spec/unit/parser/functions/num2bool_spec.rb index fbd25c8..2f6435d 100644 --- a/spec/unit/parser/functions/num2bool_spec.rb +++ b/spec/unit/parser/functions/num2bool_spec.rb @@ -18,4 +18,9 @@ describe "the num2bool function" do lambda { @scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if 1" do + result = @scope.function_num2bool(["1"]) + result.should(eq(true)) + end + end diff --git a/spec/unit/parser/functions/prefix_spec.rb b/spec/unit/parser/functions/prefix_spec.rb index 9ede439..a0cbcab 100644 --- a/spec/unit/parser/functions/prefix_spec.rb +++ b/spec/unit/parser/functions/prefix_spec.rb @@ -18,4 +18,9 @@ describe "the prefix function" do lambda { @scope.function_prefix([]) }.should( raise_error(Puppet::ParseError)) end + it "should return a prefixed array" do + result = @scope.function_prefix([['a','b','c'], 'p']) + result.should(eq(['pa','pb','pc'])) + end + end diff --git a/spec/unit/parser/functions/range_spec.rb b/spec/unit/parser/functions/range_spec.rb index 23310bc..8c2446a 100644 --- a/spec/unit/parser/functions/range_spec.rb +++ b/spec/unit/parser/functions/range_spec.rb @@ -18,4 +18,14 @@ describe "the range function" do lambda { @scope.function_range([]) }.should( raise_error(Puppet::ParseError)) end + it "should return a letter range" do + result = @scope.function_range(["a","d"]) + result.should(eq(['a','b','c','d'])) + end + + it "should return a number range" do + result = @scope.function_range(["1","4"]) + result.should(eq([1,2,3,4])) + end + end diff --git a/spec/unit/parser/functions/reverse_spec.rb b/spec/unit/parser/functions/reverse_spec.rb index 27aa2cf..4fa50e4 100644 --- a/spec/unit/parser/functions/reverse_spec.rb +++ b/spec/unit/parser/functions/reverse_spec.rb @@ -18,4 +18,9 @@ describe "the reverse function" do lambda { @scope.function_reverse([]) }.should( raise_error(Puppet::ParseError)) end + it "should reverse a string" do + result = @scope.function_reverse(["asdfghijkl"]) + result.should(eq('lkjihgfdsa')) + end + end diff --git a/spec/unit/parser/functions/rstrip_spec.rb b/spec/unit/parser/functions/rstrip_spec.rb index a6e73ec..af8cc12 100644 --- a/spec/unit/parser/functions/rstrip_spec.rb +++ b/spec/unit/parser/functions/rstrip_spec.rb @@ -18,4 +18,14 @@ describe "the rstrip function" do lambda { @scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError)) end + it "should rstrip a string" do + result = @scope.function_rstrip(["asdf "]) + result.should(eq('asdf')) + end + + it "should rstrip each element in an array" do + result = @scope.function_rstrip([["a ","b ", "c "]]) + result.should(eq(['a','b','c'])) + end + end diff --git a/spec/unit/parser/functions/size_spec.rb b/spec/unit/parser/functions/size_spec.rb index 0d1f0c4..ccaa335 100644 --- a/spec/unit/parser/functions/size_spec.rb +++ b/spec/unit/parser/functions/size_spec.rb @@ -18,4 +18,14 @@ describe "the size function" do lambda { @scope.function_size([]) }.should( raise_error(Puppet::ParseError)) end + it "should return the size of a string" do + result = @scope.function_size(["asdf"]) + result.should(eq(4)) + end + + it "should return the size of an array" do + result = @scope.function_size([["a","b","c"]]) + result.should(eq(3)) + end + end diff --git a/spec/unit/parser/functions/sort_spec.rb b/spec/unit/parser/functions/sort_spec.rb index ae62d5f..da5db7a 100644 --- a/spec/unit/parser/functions/sort_spec.rb +++ b/spec/unit/parser/functions/sort_spec.rb @@ -14,8 +14,13 @@ describe "the sort function" do Puppet::Parser::Functions.function("sort").should == "function_sort" end - it "should raise a ParseError if there is not 0 arguments" do - lambda { @scope.function_sort(['']) }.should( raise_error(Puppet::ParseError)) + it "should raise a ParseError if there is not 1 arguments" do + lambda { @scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError)) + end + + it "should sort an array" do + result = @scope.function_sort([["a","c","b"]]) + result.should(eq(['a','b','c'])) end end diff --git a/spec/unit/parser/functions/squeeze_spec.rb b/spec/unit/parser/functions/squeeze_spec.rb index da8965c..9355ad2 100644 --- a/spec/unit/parser/functions/squeeze_spec.rb +++ b/spec/unit/parser/functions/squeeze_spec.rb @@ -18,4 +18,14 @@ describe "the squeeze function" do lambda { @scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError)) end + it "should squeeze a string" do + result = @scope.function_squeeze(["aaabbbbcccc"]) + result.should(eq('abc')) + end + + it "should squeeze all elements in an array" do + result = @scope.function_squeeze([["aaabbbbcccc","dddfff"]]) + result.should(eq(['abc','df'])) + end + end diff --git a/spec/unit/parser/functions/str2bool_spec.rb b/spec/unit/parser/functions/str2bool_spec.rb index 6a1ac95..d7f0ac9 100644 --- a/spec/unit/parser/functions/str2bool_spec.rb +++ b/spec/unit/parser/functions/str2bool_spec.rb @@ -18,4 +18,14 @@ describe "the str2bool function" do lambda { @scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError)) end + it "should convert string 'true' to true" do + result = @scope.function_str2bool(["true"]) + result.should(eq(true)) + end + + it "should convert string 'undef' to false" do + result = @scope.function_str2bool(["undef"]) + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/strip_spec.rb b/spec/unit/parser/functions/strip_spec.rb index ca06845..48a52dd 100644 --- a/spec/unit/parser/functions/strip_spec.rb +++ b/spec/unit/parser/functions/strip_spec.rb @@ -18,4 +18,9 @@ describe "the strip function" do lambda { @scope.function_strip([]) }.should( raise_error(Puppet::ParseError)) end + it "should strip a string" do + result = @scope.function_strip([" ab cd "]) + result.should(eq('ab cd')) + end + end diff --git a/spec/unit/parser/functions/swapcase_spec.rb b/spec/unit/parser/functions/swapcase_spec.rb index 7c5ff30..2686054 100644 --- a/spec/unit/parser/functions/swapcase_spec.rb +++ b/spec/unit/parser/functions/swapcase_spec.rb @@ -18,4 +18,9 @@ describe "the swapcase function" do lambda { @scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError)) end + it "should swapcase a string" do + result = @scope.function_swapcase(["aaBBccDD"]) + result.should(eq('AAbbCCdd')) + end + end diff --git a/spec/unit/parser/functions/type_spec.rb b/spec/unit/parser/functions/type_spec.rb index 4109da1..fddb87d 100644 --- a/spec/unit/parser/functions/type_spec.rb +++ b/spec/unit/parser/functions/type_spec.rb @@ -18,4 +18,9 @@ describe "the type function" do lambda { @scope.function_type([]) }.should( raise_error(Puppet::ParseError)) end + it "should return a type when given a string" do + result = @scope.function_type(["aaabbbbcccc"]) + result.should(eq('String')) + end + end diff --git a/spec/unit/parser/functions/unique_spec.rb b/spec/unit/parser/functions/unique_spec.rb index fe7b3ca..7b8b08d 100644 --- a/spec/unit/parser/functions/unique_spec.rb +++ b/spec/unit/parser/functions/unique_spec.rb @@ -18,4 +18,9 @@ describe "the unique function" do lambda { @scope.function_unique([]) }.should( raise_error(Puppet::ParseError)) end + it "should remove duplicate elements in a string" do + result = @scope.function_squeeze([["aabbc"]]) + result.should(eq(['abc'])) + end + end diff --git a/spec/unit/parser/functions/upcase_spec.rb b/spec/unit/parser/functions/upcase_spec.rb index 39884eb..10e4c8a 100644 --- a/spec/unit/parser/functions/upcase_spec.rb +++ b/spec/unit/parser/functions/upcase_spec.rb @@ -18,4 +18,9 @@ describe "the upcase function" do lambda { @scope.function_upcase([]) }.should( raise_error(Puppet::ParseError)) end + it "should upcase a string" do + result = @scope.function_upcase(["abc"]) + result.should(eq('ABC')) + end + end diff --git a/spec/unit/parser/functions/values_at_spec.rb b/spec/unit/parser/functions/values_at_spec.rb index af5dc25..ec8730b 100644 --- a/spec/unit/parser/functions/values_at_spec.rb +++ b/spec/unit/parser/functions/values_at_spec.rb @@ -18,4 +18,9 @@ describe "the values_at function" do lambda { @scope.function_values_at([]) }.should( raise_error(Puppet::ParseError)) end + it "should return a value at from an array" do + result = @scope.function_values_at([['a','b','c'],"1"]) + result.should(eq(['b'])) + end + end diff --git a/spec/unit/parser/functions/values_spec.rb b/spec/unit/parser/functions/values_spec.rb index 2c313a0..92f1311 100644 --- a/spec/unit/parser/functions/values_spec.rb +++ b/spec/unit/parser/functions/values_spec.rb @@ -18,4 +18,9 @@ describe "the values function" do lambda { @scope.function_values([]) }.should( raise_error(Puppet::ParseError)) end + it "should return values from a hash" do + result = @scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}]) + result.should(eq(['1','2','3'])) + end + end diff --git a/spec/unit/parser/functions/zip_spec.rb b/spec/unit/parser/functions/zip_spec.rb index 3d0392a..074f4df 100644 --- a/spec/unit/parser/functions/zip_spec.rb +++ b/spec/unit/parser/functions/zip_spec.rb @@ -18,4 +18,9 @@ describe "the zip function" do lambda { @scope.function_zip([]) }.should( raise_error(Puppet::ParseError)) end + it "should be able to zip an array" do + result = @scope.function_zip([['1','2','3'],['4','5','6']]) + result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]])) + end + end -- cgit v1.2.3 From ce48eb6e7a76f74e1f61c76ac3b185031c40772b Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 00:10:31 +0100 Subject: Allow sort for strings. --- lib/puppet/parser/functions/sort.rb | 8 +++++++- spec/unit/parser/functions/sort_spec.rb | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 54a4018..49ca20a 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -12,7 +12,13 @@ module Puppet::Parser::Functions "given #{arguments.size} for 1") end - arguments[0].sort + value = arguments[0] + + if value.is_a?(Array) then + value.sort + elsif value.is_a?(String) then + value.split("").sort.to_s + end end end diff --git a/spec/unit/parser/functions/sort_spec.rb b/spec/unit/parser/functions/sort_spec.rb index da5db7a..fbe3073 100644 --- a/spec/unit/parser/functions/sort_spec.rb +++ b/spec/unit/parser/functions/sort_spec.rb @@ -23,4 +23,9 @@ describe "the sort function" do result.should(eq(['a','b','c'])) end + it "should sort a string" do + result = @scope.function_sort(["acb"]) + result.should(eq('abc')) + end + end -- cgit v1.2.3 From 19313b43ea04066a88a0b78e83650ac52785e2e9 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 22:18:56 +0100 Subject: (#3) Apply missing documentation to more functions. --- lib/puppet/parser/functions/num2bool.rb | 2 + lib/puppet/parser/functions/prefix.rb | 7 +++ lib/puppet/parser/functions/range.rb | 12 +++++ lib/puppet/parser/functions/reverse.rb | 1 + lib/puppet/parser/functions/rstrip.rb | 1 + lib/puppet/parser/functions/shuffle.rb | 1 + lib/puppet/parser/functions/size.rb | 1 + lib/puppet/parser/functions/sort.rb | 1 + lib/puppet/parser/functions/squeeze.rb | 1 + lib/puppet/parser/functions/str2bool.rb | 3 ++ lib/puppet/parser/functions/strftime.rb | 63 ++++++++++++++++++++++++ lib/puppet/parser/functions/strip.rb | 8 +++ lib/puppet/parser/functions/swapcase.rb | 7 +++ lib/puppet/parser/functions/time.rb | 7 +++ lib/puppet/parser/functions/type.rb | 19 ++++++- lib/puppet/parser/functions/unique.rb | 17 +++++++ lib/puppet/parser/functions/upcase.rb | 9 ++++ lib/puppet/parser/functions/validate_resource.rb | 5 ++ lib/puppet/parser/functions/values.rb | 14 ++++++ lib/puppet/parser/functions/values_at.rb | 25 ++++++++-- lib/puppet/parser/functions/zip.rb | 9 ++++ spec/unit/parser/functions/type_spec.rb | 22 ++++++--- spec/unit/parser/functions/unique_spec.rb | 9 +++- spec/unit/parser/functions/values_spec.rb | 4 ++ 24 files changed, 235 insertions(+), 13 deletions(-) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/num2bool.rb b/lib/puppet/parser/functions/num2bool.rb index 2baef62..874db22 100644 --- a/lib/puppet/parser/functions/num2bool.rb +++ b/lib/puppet/parser/functions/num2bool.rb @@ -6,6 +6,8 @@ module Puppet::Parser::Functions newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS +This function converts a number into a true boolean. Zero becomes false. Numbers +higher then 0 become true. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/prefix.rb b/lib/puppet/parser/functions/prefix.rb index 0e0cee2..4593976 100644 --- a/lib/puppet/parser/functions/prefix.rb +++ b/lib/puppet/parser/functions/prefix.rb @@ -4,6 +4,13 @@ module Puppet::Parser::Functions newfunction(:prefix, :type => :rvalue, :doc => <<-EOS +This function applies a prefix to all elements in an array. + +*Examles:* + + prefix(['a','b','c'], 'p') + +Will return: ['pa','pb','pc'] EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb index 6afb50c..6e85422 100644 --- a/lib/puppet/parser/functions/range.rb +++ b/lib/puppet/parser/functions/range.rb @@ -6,6 +6,18 @@ module Puppet::Parser::Functions newfunction(:range, :type => :rvalue, :doc => <<-EOS +When given range in the form of (start, stop) it will extrapolate a range as +an array. + +*Examples:* + + range("0", "9") + +Will return: [0,1,2,3,4,5,6,7,8,9] + + range("a", "c") + +Will return: ["a","b","c"] EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/reverse.rb b/lib/puppet/parser/functions/reverse.rb index 79e9b93..fe04869 100644 --- a/lib/puppet/parser/functions/reverse.rb +++ b/lib/puppet/parser/functions/reverse.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:reverse, :type => :rvalue, :doc => <<-EOS +Reverses the order of a string or array. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/rstrip.rb b/lib/puppet/parser/functions/rstrip.rb index 56849d3..29b0998 100644 --- a/lib/puppet/parser/functions/rstrip.rb +++ b/lib/puppet/parser/functions/rstrip.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS +Strips leading spaces to the right of the string. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/shuffle.rb b/lib/puppet/parser/functions/shuffle.rb index 73e798c..18134ab 100644 --- a/lib/puppet/parser/functions/shuffle.rb +++ b/lib/puppet/parser/functions/shuffle.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:shuffle, :type => :rvalue, :doc => <<-EOS +Randomizes the order of a string or array elements. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb index aa4f4ad..cc207e3 100644 --- a/lib/puppet/parser/functions/size.rb +++ b/lib/puppet/parser/functions/size.rb @@ -6,6 +6,7 @@ module Puppet::Parser::Functions newfunction(:size, :type => :rvalue, :doc => <<-EOS +Returns the number of elements in a string or array. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 49ca20a..3785496 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:sort, :type => :rvalue, :doc => <<-EOS +Sorts strings and arrays lexically. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/squeeze.rb b/lib/puppet/parser/functions/squeeze.rb index 9a1dd20..65c174a 100644 --- a/lib/puppet/parser/functions/squeeze.rb +++ b/lib/puppet/parser/functions/squeeze.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS +Returns a new string where runs of the same character that occur in this set are replaced by a single character. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb index f3a6d6c..c320da6 100644 --- a/lib/puppet/parser/functions/str2bool.rb +++ b/lib/puppet/parser/functions/str2bool.rb @@ -4,6 +4,9 @@ module Puppet::Parser::Functions newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS +This converts a string to a boolean. This attempt to convert strings that +contain things like: y, 1, t, true to 'true' and strings that contain things +like: 0, f, n, false, no to 'false'. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/strftime.rb b/lib/puppet/parser/functions/strftime.rb index c919320..0b52ade 100644 --- a/lib/puppet/parser/functions/strftime.rb +++ b/lib/puppet/parser/functions/strftime.rb @@ -4,6 +4,69 @@ module Puppet::Parser::Functions newfunction(:strftime, :type => :rvalue, :doc => <<-EOS +This function returns formatted time. + +*Examples:* + +To return the time since epoch: + + strftime("%s") + +To return the date: + + strftime("%Y-%m-%d") + +*Format meaning:* + + %a - The abbreviated weekday name (``Sun'') + %A - The full weekday name (``Sunday'') + %b - The abbreviated month name (``Jan'') + %B - The full month name (``January'') + %c - The preferred local date and time representation + %C - Century (20 in 2009) + %d - Day of the month (01..31) + %D - Date (%m/%d/%y) + %e - Day of the month, blank-padded ( 1..31) + %F - Equivalent to %Y-%m-%d (the ISO 8601 date format) + %h - Equivalent to %b + %H - Hour of the day, 24-hour clock (00..23) + %I - Hour of the day, 12-hour clock (01..12) + %j - Day of the year (001..366) + %k - hour, 24-hour clock, blank-padded ( 0..23) + %l - hour, 12-hour clock, blank-padded ( 0..12) + %L - Millisecond of the second (000..999) + %m - Month of the year (01..12) + %M - Minute of the hour (00..59) + %n - Newline (\n) + %N - Fractional seconds digits, default is 9 digits (nanosecond) + %3N millisecond (3 digits) + %6N microsecond (6 digits) + %9N nanosecond (9 digits) + %p - Meridian indicator (``AM'' or ``PM'') + %P - Meridian indicator (``am'' or ``pm'') + %r - time, 12-hour (same as %I:%M:%S %p) + %R - time, 24-hour (%H:%M) + %s - Number of seconds since 1970-01-01 00:00:00 UTC. + %S - Second of the minute (00..60) + %t - Tab character (\t) + %T - time, 24-hour (%H:%M:%S) + %u - Day of the week as a decimal, Monday being 1. (1..7) + %U - Week number of the current year, + starting with the first Sunday as the first + day of the first week (00..53) + %v - VMS date (%e-%b-%Y) + %V - Week number of year according to ISO 8601 (01..53) + %W - Week number of the current year, + starting with the first Monday as the first + day of the first week (00..53) + %w - Day of the week (Sunday is 0, 0..6) + %x - Preferred representation for the date alone, no time + %X - Preferred representation for the time alone, no date + %y - Year without a century (00..99) + %Y - Year with century + %z - Time zone as hour offset from UTC (e.g. +0900) + %Z - Time zone name + %% - Literal ``%'' character EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb index ebab20e..5f4630d 100644 --- a/lib/puppet/parser/functions/strip.rb +++ b/lib/puppet/parser/functions/strip.rb @@ -4,6 +4,14 @@ module Puppet::Parser::Functions newfunction(:strip, :type => :rvalue, :doc => <<-EOS +This function removes leading and trailing whitespace from a string or from +every string inside an array. + +*Examples:* + + strip(" aaa ") + +Would result in: "aaa" EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/swapcase.rb b/lib/puppet/parser/functions/swapcase.rb index a0002a9..b9e6632 100644 --- a/lib/puppet/parser/functions/swapcase.rb +++ b/lib/puppet/parser/functions/swapcase.rb @@ -4,6 +4,13 @@ module Puppet::Parser::Functions newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS +This function will swap the existing case of a string. + +*Examples:* + + swapcase("aBcD") + +Would result in: "AbCd" EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/time.rb b/lib/puppet/parser/functions/time.rb index e1f5b6f..0cddaf8 100644 --- a/lib/puppet/parser/functions/time.rb +++ b/lib/puppet/parser/functions/time.rb @@ -4,6 +4,13 @@ module Puppet::Parser::Functions newfunction(:time, :type => :rvalue, :doc => <<-EOS +This function will return the current time since epoch as an integer. + +*Examples:* + + time() + +Will return something like: 1311972653 EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/type.rb b/lib/puppet/parser/functions/type.rb index 389a056..de6087e 100644 --- a/lib/puppet/parser/functions/type.rb +++ b/lib/puppet/parser/functions/type.rb @@ -4,6 +4,13 @@ module Puppet::Parser::Functions newfunction(:type, :type => :rvalue, :doc => <<-EOS +Returns the type when passed a variable. Type can be one of: + +* string +* array +* hash +* float +* integer EOS ) do |arguments| @@ -22,11 +29,19 @@ module Puppet::Parser::Functions # We note that Integer is the parent to Bignum and Fixnum ... result = case klass - when /^(?:Big|Fix)num$/ then 'Integer' + when /^(?:Big|Fix)num$/ then 'integer' else klass end - return result + if result == "String" then + if value == value.to_i.to_s then + result = "Integer" + elsif value == value.to_f.to_s then + result = "Float" + end + end + + return result.downcase end end diff --git a/lib/puppet/parser/functions/unique.rb b/lib/puppet/parser/functions/unique.rb index a922c94..8844a74 100644 --- a/lib/puppet/parser/functions/unique.rb +++ b/lib/puppet/parser/functions/unique.rb @@ -4,6 +4,23 @@ module Puppet::Parser::Functions newfunction(:unique, :type => :rvalue, :doc => <<-EOS +This function will remove duplicates from strings and arrays. + +*Examples:* + + unique("aabbcc") + +Will return: + + abc + +You can also use this with arrays: + + unique(["a","a","b","b","c","c"]) + +This returns: + + ["a","b","c"] EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index 8a9769d..fe6cadc 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -4,6 +4,15 @@ module Puppet::Parser::Functions newfunction(:upcase, :type => :rvalue, :doc => <<-EOS +Converts a string or an array of strings to uppercase. + +*Examples:* + + upcase("abcd") + +Will return: + + ASDF EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/validate_resource.rb b/lib/puppet/parser/functions/validate_resource.rb index bbb5a54..d71ef3f 100644 --- a/lib/puppet/parser/functions/validate_resource.rb +++ b/lib/puppet/parser/functions/validate_resource.rb @@ -4,6 +4,11 @@ module Puppet::Parser::Functions newfunction(:validate_resource, :type => :statement, :doc => <<-EOS +This function when placed at the beginning of a class, will go looking for a +valid kwalify schema by replacing the extension of the file with '.schema'. + +It will then validate the arguments passed to the function using that kwalify +schema. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/values.rb b/lib/puppet/parser/functions/values.rb index c1c4a77..1606756 100644 --- a/lib/puppet/parser/functions/values.rb +++ b/lib/puppet/parser/functions/values.rb @@ -4,6 +4,20 @@ module Puppet::Parser::Functions newfunction(:values, :type => :rvalue, :doc => <<-EOS +When given a hash this function will return the values of that hash. + +*Examples:* + + $hash = { + 'a' => 1, + 'b' => 2, + 'c' => 3, + } + values($hash) + +This example would return: + + [1,2,3] EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/values_at.rb b/lib/puppet/parser/functions/values_at.rb index 331af6a..7f1de8e 100644 --- a/lib/puppet/parser/functions/values_at.rb +++ b/lib/puppet/parser/functions/values_at.rb @@ -2,11 +2,30 @@ # values_at.rb # -# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ... -# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ... - module Puppet::Parser::Functions newfunction(:values_at, :type => :rvalue, :doc => <<-EOS +Finds value inside an array based on location. + +The first argument is the array you want to analyze, and the second element can +be a combination of: + +* A single numeric index +* A range in the form of 'start-stop' (eg. 4-9) +* An array combining the above + +*Examples*: + + values_at(['a','b','c'], 2) + +Would return ['c']. + + values_at(['a','b','c'], ["0-1"]) + +Would return ['a','b']. + + values_at(['a','b','c','d','e'], [0, "2-3"]) + +Would return ['a','c','d']. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/zip.rb b/lib/puppet/parser/functions/zip.rb index 024d64a..2b56e9c 100644 --- a/lib/puppet/parser/functions/zip.rb +++ b/lib/puppet/parser/functions/zip.rb @@ -4,6 +4,15 @@ module Puppet::Parser::Functions newfunction(:zip, :type => :rvalue, :doc => <<-EOS +Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments. + +*Example:* + + zip(['1','2','3'],['4','5','6']) + +Would result in: + + ["1", "4"], ["2", "5"], ["3", "6"] EOS ) do |arguments| diff --git a/spec/unit/parser/functions/type_spec.rb b/spec/unit/parser/functions/type_spec.rb index 36c3823..53071f3 100644 --- a/spec/unit/parser/functions/type_spec.rb +++ b/spec/unit/parser/functions/type_spec.rb @@ -18,19 +18,29 @@ describe "the type function" do lambda { @scope.function_type([]) }.should( raise_error(Puppet::ParseError)) end - it "should return String when given a string" do + it "should return string when given a string" do result = @scope.function_type(["aaabbbbcccc"]) - result.should(eq('String')) + result.should(eq('string')) end - it "should return Array when given an array" do + it "should return array when given an array" do result = @scope.function_type([["aaabbbbcccc","asdf"]]) - result.should(eq('Array')) + result.should(eq('array')) end - it "should return Hash when given a hash" do + it "should return hash when given a hash" do result = @scope.function_type([{"a"=>1,"b"=>2}]) - result.should(eq('Hash')) + result.should(eq('hash')) + end + + it "should return integer when given an integer" do + result = @scope.function_type(["1"]) + result.should(eq('integer')) + end + + it "should return float when given a float" do + result = @scope.function_type(["1.34"]) + result.should(eq('float')) end end diff --git a/spec/unit/parser/functions/unique_spec.rb b/spec/unit/parser/functions/unique_spec.rb index 7b8b08d..627dc33 100644 --- a/spec/unit/parser/functions/unique_spec.rb +++ b/spec/unit/parser/functions/unique_spec.rb @@ -19,8 +19,13 @@ describe "the unique function" do end it "should remove duplicate elements in a string" do - result = @scope.function_squeeze([["aabbc"]]) - result.should(eq(['abc'])) + result = @scope.function_unique(["aabbc"]) + result.should(eq('abc')) + end + + it "should remove duplicate elements in an array" do + result = @scope.function_unique([["a","a","b","b","c"]]) + result.should(eq(['a','b','c'])) end end diff --git a/spec/unit/parser/functions/values_spec.rb b/spec/unit/parser/functions/values_spec.rb index 92f1311..f6eb5b6 100644 --- a/spec/unit/parser/functions/values_spec.rb +++ b/spec/unit/parser/functions/values_spec.rb @@ -23,4 +23,8 @@ describe "the values function" do result.should(eq(['1','2','3'])) end + it "should return values from a hash" do + lambda { @scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError)) + end + end -- cgit v1.2.3 From 35fefe186546427963d8c8a446fa98875d65ccad Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sat, 30 Jul 2011 00:44:02 +0100 Subject: Fix some ruby 1.9.2 issues. --- lib/puppet/parser/functions/sort.rb | 2 +- lib/puppet/parser/functions/values_at.rb | 2 +- spec/unit/parser/functions/shuffle_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 3785496..cefbe54 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -18,7 +18,7 @@ Sorts strings and arrays lexically. if value.is_a?(Array) then value.sort elsif value.is_a?(String) then - value.split("").sort.to_s + value.split("").sort.join("") end end diff --git a/lib/puppet/parser/functions/values_at.rb b/lib/puppet/parser/functions/values_at.rb index 7f1de8e..d3e69d9 100644 --- a/lib/puppet/parser/functions/values_at.rb +++ b/lib/puppet/parser/functions/values_at.rb @@ -38,7 +38,7 @@ Would return ['a','c','d']. raise(Puppet::ParseError, 'values_at(): Requires array to work with') end - indices = *arguments # Get them all ... Pokemon ... + indices = [arguments.shift].flatten() # Get them all ... Pokemon ... if not indices or indices.empty? raise(Puppet::ParseError, 'values_at(): You must provide ' + diff --git a/spec/unit/parser/functions/shuffle_spec.rb b/spec/unit/parser/functions/shuffle_spec.rb index 936c2fd..f04fda5 100644 --- a/spec/unit/parser/functions/shuffle_spec.rb +++ b/spec/unit/parser/functions/shuffle_spec.rb @@ -25,7 +25,7 @@ describe "the shuffle function" do it "should shuffle a string but the sorted contents should still be the same" do result = @scope.function_shuffle(["adfs"]) - result.split("").sort.to_s.should(eq("adfs")) + result.split("").sort.join("").should(eq("adfs")) end end -- cgit v1.2.3