From 157531cd290e53c9a174171bb29de293bade2ed4 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Wed, 29 Jun 2011 12:25:43 +0100 Subject: Copied function test scaffolding from puppet. --- spec/lib/puppet_spec/files.rb | 53 ++++++++++++++++++ spec/lib/puppet_spec/fixtures.rb | 28 ++++++++++ spec/lib/puppet_spec/matchers.rb | 87 +++++++++++++++++++++++++++++ spec/lib/puppet_spec/verbose.rb | 9 +++ spec/monkey_patches/alias_should_to_must.rb | 8 +++ spec/monkey_patches/publicize_methods.rb | 11 ++++ spec/spec.opts | 4 ++ spec/spec_helper.rb | 78 ++++++++++++++++++++++++++ 8 files changed, 278 insertions(+) create mode 100755 spec/lib/puppet_spec/files.rb create mode 100755 spec/lib/puppet_spec/fixtures.rb create mode 100644 spec/lib/puppet_spec/matchers.rb create mode 100755 spec/lib/puppet_spec/verbose.rb create mode 100755 spec/monkey_patches/alias_should_to_must.rb create mode 100755 spec/monkey_patches/publicize_methods.rb create mode 100644 spec/spec.opts create mode 100755 spec/spec_helper.rb (limited to 'spec') diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb new file mode 100755 index 0000000..30fb4fc --- /dev/null +++ b/spec/lib/puppet_spec/files.rb @@ -0,0 +1,53 @@ +require 'fileutils' +require 'tempfile' + +# A support module for testing files. +module PuppetSpec::Files + # This code exists only to support tests that run as root, pretty much. + # Once they have finally been eliminated this can all go... --daniel 2011-04-08 + if Puppet.features.posix? then + def self.in_tmp(path) + path =~ /^\/tmp/ or path =~ /^\/var\/folders/ + end + elsif Puppet.features.microsoft_windows? + def self.in_tmp(path) + tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp")) + path =~ /^#{tempdir}/ + end + else + fail "Help! Can't find in_tmp for this platform" + end + + def self.cleanup + $global_tempfiles ||= [] + while path = $global_tempfiles.pop do + fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path) + + begin + FileUtils.rm_r path, :secure => true + rescue Errno::ENOENT + # nothing to do + end + end + end + + def tmpfile(name) + # Generate a temporary file, just for the name... + source = Tempfile.new(name) + path = source.path + source.close! + + # ...record it for cleanup, + $global_tempfiles ||= [] + $global_tempfiles << File.expand_path(path) + + # ...and bam. + path + end + + def tmpdir(name) + path = tmpfile(name) + FileUtils.mkdir_p(path) + path + end +end diff --git a/spec/lib/puppet_spec/fixtures.rb b/spec/lib/puppet_spec/fixtures.rb new file mode 100755 index 0000000..7f6bc2a --- /dev/null +++ b/spec/lib/puppet_spec/fixtures.rb @@ -0,0 +1,28 @@ +module PuppetSpec::Fixtures + def fixtures(*rest) + File.join(PuppetSpec::FIXTURE_DIR, *rest) + end + def my_fixture_dir + callers = caller + while line = callers.shift do + next unless found = line.match(%r{/spec/(.*)_spec\.rb:}) + return fixtures(found[1]) + end + fail "sorry, I couldn't work out your path from the caller stack!" + end + def my_fixture(name) + file = File.join(my_fixture_dir, name) + unless File.readable? file then + fail Puppet::DevError, "fixture '#{name}' for #{my_fixture_dir} is not readable" + end + return file + end + def my_fixtures(glob = '*', flags = 0) + files = Dir.glob(File.join(my_fixture_dir, glob), flags) + unless files.length > 0 then + fail Puppet::DevError, "fixture '#{glob}' for #{my_fixture_dir} had no files!" + end + block_given? and files.each do |file| yield file end + files + end +end diff --git a/spec/lib/puppet_spec/matchers.rb b/spec/lib/puppet_spec/matchers.rb new file mode 100644 index 0000000..77f5803 --- /dev/null +++ b/spec/lib/puppet_spec/matchers.rb @@ -0,0 +1,87 @@ +require 'stringio' + +######################################################################## +# Backward compatibility for Jenkins outdated environment. +module RSpec + module Matchers + module BlockAliases + alias_method :to, :should unless method_defined? :to + alias_method :to_not, :should_not unless method_defined? :to_not + alias_method :not_to, :should_not unless method_defined? :not_to + end + end +end + + +######################################################################## +# Custom matchers... +RSpec::Matchers.define :have_matching_element do |expected| + match do |actual| + actual.any? { |item| item =~ expected } + end +end + + +RSpec::Matchers.define :exit_with do |expected| + actual = nil + match do |block| + begin + block.call + rescue SystemExit => e + actual = e.status + end + actual and actual == expected + end + failure_message_for_should do |block| + "expected exit with code #{expected} but " + + (actual.nil? ? " exit was not called" : "we exited with #{actual} instead") + end + failure_message_for_should_not do |block| + "expected that exit would not be called with #{expected}" + end + description do + "expect exit with #{expected}" + end +end + + +RSpec::Matchers.define :have_printed do |expected| + match do |block| + $stderr = $stdout = StringIO.new + + begin + block.call + ensure + $stdout.rewind + @actual = $stdout.read + + $stdout = STDOUT + $stderr = STDERR + end + + if @actual then + case expected + when String + @actual.include? expected + when Regexp + expected.match @actual + else + raise ArgumentError, "No idea how to match a #{@actual.class.name}" + end + end + end + + failure_message_for_should do |actual| + if actual.nil? then + "expected #{expected.inspect}, but nothing was printed" + else + "expected #{expected.inspect} to be printed; got:\n#{actual}" + end + end + + description do + "expect #{expected.inspect} to be printed" + end + + diffable +end diff --git a/spec/lib/puppet_spec/verbose.rb b/spec/lib/puppet_spec/verbose.rb new file mode 100755 index 0000000..d9834f2 --- /dev/null +++ b/spec/lib/puppet_spec/verbose.rb @@ -0,0 +1,9 @@ +# Support code for running stuff with warnings disabled. +module Kernel + def with_verbose_disabled + verbose, $VERBOSE = $VERBOSE, nil + result = yield + $VERBOSE = verbose + return result + end +end diff --git a/spec/monkey_patches/alias_should_to_must.rb b/spec/monkey_patches/alias_should_to_must.rb new file mode 100755 index 0000000..1a11117 --- /dev/null +++ b/spec/monkey_patches/alias_should_to_must.rb @@ -0,0 +1,8 @@ +require 'rspec' + +class Object + # This is necessary because the RAL has a 'should' + # method. + alias :must :should + alias :must_not :should_not +end diff --git a/spec/monkey_patches/publicize_methods.rb b/spec/monkey_patches/publicize_methods.rb new file mode 100755 index 0000000..b39e9c0 --- /dev/null +++ b/spec/monkey_patches/publicize_methods.rb @@ -0,0 +1,11 @@ +# Some monkey-patching to allow us to test private methods. +class Class + def publicize_methods(*methods) + saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods + + self.class_eval { public(*saved_private_instance_methods) } + yield + self.class_eval { private(*saved_private_instance_methods) } + end +end + diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..425f0ed --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,4 @@ +--format +s +--colour +--backtrace diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100755 index 0000000..fdc04bc --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,78 @@ +dir = File.expand_path(File.dirname(__FILE__)) +$LOAD_PATH.unshift File.join(dir, 'lib') + +p dir + +# Don't want puppet getting the command line arguments for rake or autotest +ARGV.clear + +require 'puppet' +require 'mocha' +gem 'rspec', '>=2.0.0' +require 'rspec/expectations' + +# So everyone else doesn't have to include this base constant. +module PuppetSpec + FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR) +end + +require 'pathname' +require 'tmpdir' + +require 'puppet_spec/verbose' +require 'puppet_spec/files' +require 'puppet_spec/fixtures' +require 'puppet_spec/matchers' +require 'monkey_patches/alias_should_to_must' +require 'monkey_patches/publicize_methods' + +Pathname.glob("#{dir}/shared_behaviours/**/*.rb") do |behaviour| + require behaviour.relative_path_from(Pathname.new(dir)) +end + +RSpec.configure do |config| + include PuppetSpec::Fixtures + + config.mock_with :mocha + + config.before :each do + GC.disable + + # these globals are set by Application + $puppet_application_mode = nil + $puppet_application_name = nil + + # REVISIT: I think this conceals other bad tests, but I don't have time to + # fully diagnose those right now. When you read this, please come tell me + # I suck for letting this float. --daniel 2011-04-21 + Signal.stubs(:trap) + + # Set the confdir and vardir to gibberish so that tests + # have to be correctly mocked. + Puppet[:confdir] = "/dev/null" + Puppet[:vardir] = "/dev/null" + + # Avoid opening ports to the outside world + Puppet.settings[:bindaddress] = "127.0.0.1" + + @logs = [] + Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) + + @log_level = Puppet::Util::Log.level + end + + config.after :each do + Puppet.settings.clear + Puppet::Node::Environment.clear + Puppet::Util::Storage.clear + Puppet::Util::ExecutionStub.reset + + PuppetSpec::Files.cleanup + + @logs.clear + Puppet::Util::Log.close_all + Puppet::Util::Log.level = @log_level + + GC.enable + end +end -- cgit v1.2.3 From e071b05ab631f4b73fed7178c52d0416f7629cb8 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Wed, 29 Jun 2011 12:30:07 +0100 Subject: Added kwalify function. --- spec/unit/parser/functions/kwalify_spec.rb | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 spec/unit/parser/functions/kwalify_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/kwalify_spec.rb b/spec/unit/parser/functions/kwalify_spec.rb new file mode 100755 index 0000000..b2afa12 --- /dev/null +++ b/spec/unit/parser/functions/kwalify_spec.rb @@ -0,0 +1,61 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the kwalify 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("kwalify").should == "function_kwalify" + end + + it "should raise a ParseError if there is less than 2 arguments" do + lambda { @scope.function_kwalify([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should validate a simple array schema" do + schema = { + 'type' => 'seq', + 'sequence' => [ + { 'type' => 'str' } + ] + } + document = ['a','b','c'] + @scope.function_kwalify([schema, document]) + end + + it "should not validate a simple array schema when invalid" do + schema = { + 'type' => 'seq', + 'sequence' => [ + { 'type' => 'str' } + ] + } + document = ['a','b',{'a' => 'b'}] + lambda { @scope.function_kwalify([schema, document]) }.should(raise_error(Puppet::ParseError)) + end + + it "should validate a hash schema" do + schema = { + 'type' => 'map', + 'mapping' => { + 'key1' => { + 'type' => 'str', + }, + 'key2' => { + 'type' => 'str', + }, + } + } + document = { + 'key1' => 'b', + 'key2' => 'c', + } + end + +end -- 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. --- 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 +++++++++++++++ 57 files changed, 1195 insertions(+) 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 'spec') 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 ff56d9917e52b1a0d14478af74411e81e3633e4f Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Wed, 29 Jun 2011 21:59:18 +0100 Subject: New abs test. --- spec/unit/parser/functions/abs_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/unit/parser/functions/abs_spec.rb b/spec/unit/parser/functions/abs_spec.rb index cd2902a..6bf0b41 100755 --- a/spec/unit/parser/functions/abs_spec.rb +++ b/spec/unit/parser/functions/abs_spec.rb @@ -18,4 +18,9 @@ describe "the abs function" do lambda { @scope.function_abs([]) }.should( raise_error(Puppet::ParseError)) end + it "should convert a negative number into a positive" do + result = @scope.function_abs([-34]) + result.should(eq(34)) + end + end -- cgit v1.2.3 From 464fb1f41b9c7197fcaade6831b80d6390829ec7 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Wed, 29 Jun 2011 23:37:37 +0100 Subject: Add some more functional tests. --- spec/unit/parser/functions/delete_at_spec.rb | 5 +++++ spec/unit/parser/functions/delete_spec.rb | 5 +++++ spec/unit/parser/functions/downcase_spec.rb | 5 +++++ spec/unit/parser/functions/empty_spec.rb | 5 +++++ spec/unit/parser/functions/fact_spec.rb | 21 --------------------- spec/unit/parser/functions/flatten_spec.rb | 5 +++++ spec/unit/parser/functions/grep_spec.rb | 5 +++++ spec/unit/parser/functions/hash_spec.rb | 5 +++++ spec/unit/parser/functions/is_array_spec.rb | 10 ++++++++++ spec/unit/parser/functions/is_float_spec.rb | 15 +++++++++++++++ spec/unit/parser/functions/is_hash_spec.rb | 15 +++++++++++++++ spec/unit/parser/functions/is_integer_spec.rb | 15 +++++++++++++++ 12 files changed, 90 insertions(+), 21 deletions(-) delete mode 100755 spec/unit/parser/functions/fact_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/delete_at_spec.rb b/spec/unit/parser/functions/delete_at_spec.rb index a0b5b06..27db0c8 100755 --- a/spec/unit/parser/functions/delete_at_spec.rb +++ b/spec/unit/parser/functions/delete_at_spec.rb @@ -18,4 +18,9 @@ describe "the delete_at function" do lambda { @scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError)) end + it "should delete an item at specified location from an array" do + result = @scope.function_delete_at([['a','b','c'],1]) + result.should(eq(['a','c'])) + end + end diff --git a/spec/unit/parser/functions/delete_spec.rb b/spec/unit/parser/functions/delete_spec.rb index b0729ab..fab3230 100755 --- a/spec/unit/parser/functions/delete_spec.rb +++ b/spec/unit/parser/functions/delete_spec.rb @@ -18,4 +18,9 @@ describe "the delete function" do lambda { @scope.function_delete([]) }.should( raise_error(Puppet::ParseError)) end + it "should delete an item from an array" do + result = @scope.function_delete([['a','b','c'],'b']) + result.should(eq(['a','c'])) + end + end diff --git a/spec/unit/parser/functions/downcase_spec.rb b/spec/unit/parser/functions/downcase_spec.rb index 162291c..0d53220 100755 --- a/spec/unit/parser/functions/downcase_spec.rb +++ b/spec/unit/parser/functions/downcase_spec.rb @@ -18,4 +18,9 @@ describe "the downcase function" do lambda { @scope.function_downcase([]) }.should( raise_error(Puppet::ParseError)) end + it "should downcase a string" do + result = @scope.function_downcase(["ASFD"]) + result.should(eq("asfd")) + end + end diff --git a/spec/unit/parser/functions/empty_spec.rb b/spec/unit/parser/functions/empty_spec.rb index beaf45c..6c0fe69 100755 --- a/spec/unit/parser/functions/empty_spec.rb +++ b/spec/unit/parser/functions/empty_spec.rb @@ -18,4 +18,9 @@ describe "the empty function" do lambda { @scope.function_empty([]) }.should( raise_error(Puppet::ParseError)) end + it "should return a true for an empty string" do + result = @scope.function_empty(['']) + result.should(eq(true)) + end + end diff --git a/spec/unit/parser/functions/fact_spec.rb b/spec/unit/parser/functions/fact_spec.rb deleted file mode 100755 index c013ae0..0000000 --- a/spec/unit/parser/functions/fact_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/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 index 7af23c1..91cf4ef 100755 --- a/spec/unit/parser/functions/flatten_spec.rb +++ b/spec/unit/parser/functions/flatten_spec.rb @@ -18,4 +18,9 @@ describe "the flatten function" do lambda { @scope.function_flatten([]) }.should( raise_error(Puppet::ParseError)) end + it "should flatten a complex data structure" do + result = @scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) + result.should(eq(["a","b","c","d","e","f","g"])) + end + end diff --git a/spec/unit/parser/functions/grep_spec.rb b/spec/unit/parser/functions/grep_spec.rb index 1c949da..b1f647c 100755 --- a/spec/unit/parser/functions/grep_spec.rb +++ b/spec/unit/parser/functions/grep_spec.rb @@ -18,4 +18,9 @@ describe "the grep function" do lambda { @scope.function_grep([]) }.should( raise_error(Puppet::ParseError)) end + it "should grep contents from an array" do + result = @scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"]) + result.should(eq(["aaabbb","bbbccc"])) + end + end diff --git a/spec/unit/parser/functions/hash_spec.rb b/spec/unit/parser/functions/hash_spec.rb index 09b0d50..6d3d48c 100644 --- a/spec/unit/parser/functions/hash_spec.rb +++ b/spec/unit/parser/functions/hash_spec.rb @@ -18,4 +18,9 @@ describe "the hash function" do lambda { @scope.function_hash([]) }.should( raise_error(Puppet::ParseError)) end + it "should convert an array to a hash" do + result = @scope.function_hash([['a',1,'b',2,'c',3]]) + result.should(eq({'a'=>1,'b'=>2,'c'=>3})) + end + end diff --git a/spec/unit/parser/functions/is_array_spec.rb b/spec/unit/parser/functions/is_array_spec.rb index b2843b0..15b563c 100644 --- a/spec/unit/parser/functions/is_array_spec.rb +++ b/spec/unit/parser/functions/is_array_spec.rb @@ -18,4 +18,14 @@ describe "the is_array function" do lambda { @scope.function_is_array([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if passed an array" do + result = @scope.function_is_array([[1,2,3]]) + result.should(eq(true)) + end + + it "should return false if passed a hash" do + result = @scope.function_is_array([{'a'=>1}]) + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/is_float_spec.rb b/spec/unit/parser/functions/is_float_spec.rb index e3dc8fc..3d58017 100644 --- a/spec/unit/parser/functions/is_float_spec.rb +++ b/spec/unit/parser/functions/is_float_spec.rb @@ -18,4 +18,19 @@ describe "the is_float function" do lambda { @scope.function_is_float([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if a float" do + result = @scope.function_is_float([0.12]) + result.should(eq(true)) + end + + it "should return false if a string" do + result = @scope.function_is_float(["asdf"]) + result.should(eq(false)) + end + + it "should return false if not an integer" do + result = @scope.function_is_float([3]) + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/is_hash_spec.rb b/spec/unit/parser/functions/is_hash_spec.rb index 66dfdeb..94364f5 100644 --- a/spec/unit/parser/functions/is_hash_spec.rb +++ b/spec/unit/parser/functions/is_hash_spec.rb @@ -18,4 +18,19 @@ describe "the is_hash function" do lambda { @scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if passed a hash" do + result = @scope.function_is_hash([{"a"=>1,"b"=>2}]) + result.should(eq(true)) + end + + it "should return false if passed an array" do + result = @scope.function_is_hash([["a","b"]]) + result.should(eq(false)) + end + + it "should return false if passed a string" do + result = @scope.function_is_hash(["asdf"]) + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/is_integer_spec.rb b/spec/unit/parser/functions/is_integer_spec.rb index 131251c..596bd33 100644 --- a/spec/unit/parser/functions/is_integer_spec.rb +++ b/spec/unit/parser/functions/is_integer_spec.rb @@ -18,4 +18,19 @@ describe "the is_integer function" do lambda { @scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if an integer" do + result = @scope.function_is_integer([3]) + result.should(eq(true)) + end + + it "should return false if a float" do + result = @scope.function_is_integer([3.2]) + result.should(eq(false)) + end + + it "should return false if a string" do + result = @scope.function_is_integer(["asdf"]) + result.should(eq(false)) + end + end -- cgit v1.2.3 From 1abf4b62fc8e97c7096c9da3d350e3e6268c5c72 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 30 Jun 2011 01:00:32 +0200 Subject: Few more tests. --- spec/unit/parser/functions/bool2num_spec.rb | 10 ++++++++++ spec/unit/parser/functions/capitalize_spec.rb | 5 +++++ spec/unit/parser/functions/chomp_spec.rb | 5 +++++ spec/unit/parser/functions/chop_spec.rb | 5 +++++ spec/unit/parser/functions/count_spec.rb | 5 +++++ 5 files changed, 30 insertions(+) (limited to 'spec') diff --git a/spec/unit/parser/functions/bool2num_spec.rb b/spec/unit/parser/functions/bool2num_spec.rb index a2585e9..d5da18c 100755 --- a/spec/unit/parser/functions/bool2num_spec.rb +++ b/spec/unit/parser/functions/bool2num_spec.rb @@ -18,4 +18,14 @@ describe "the bool2num function" do lambda { @scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError)) end + it "should convert true to 1" do + result = @scope.function_bool2num([true]) + result.should(eq(1)) + end + + it "should convert false to 0" do + result = @scope.function_bool2num([false]) + result.should(eq(0)) + end + end diff --git a/spec/unit/parser/functions/capitalize_spec.rb b/spec/unit/parser/functions/capitalize_spec.rb index bb1fe2a..1c45821 100755 --- a/spec/unit/parser/functions/capitalize_spec.rb +++ b/spec/unit/parser/functions/capitalize_spec.rb @@ -18,4 +18,9 @@ describe "the capitalize function" do lambda { @scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError)) end + it "should capitalize the beginning of a string" do + result = @scope.function_capitalize(["abc"]) + result.should(eq("Abc")) + end + end diff --git a/spec/unit/parser/functions/chomp_spec.rb b/spec/unit/parser/functions/chomp_spec.rb index 150a7c8..0592115 100755 --- a/spec/unit/parser/functions/chomp_spec.rb +++ b/spec/unit/parser/functions/chomp_spec.rb @@ -18,4 +18,9 @@ describe "the chomp function" do lambda { @scope.function_chomp([]) }.should( raise_error(Puppet::ParseError)) end + it "should chomp the end of a string" do + result = @scope.function_chomp(["abc\n"]) + result.should(eq("abc")) + end + end diff --git a/spec/unit/parser/functions/chop_spec.rb b/spec/unit/parser/functions/chop_spec.rb index ae636cb..0c456a8 100755 --- a/spec/unit/parser/functions/chop_spec.rb +++ b/spec/unit/parser/functions/chop_spec.rb @@ -18,4 +18,9 @@ describe "the chop function" do lambda { @scope.function_chop([]) }.should( raise_error(Puppet::ParseError)) end + it "should chop the end of a string" do + result = @scope.function_chop(["asdf\n"]) + result.should(eq("asdf")) + end + end diff --git a/spec/unit/parser/functions/count_spec.rb b/spec/unit/parser/functions/count_spec.rb index 28617c9..62d005a 100755 --- a/spec/unit/parser/functions/count_spec.rb +++ b/spec/unit/parser/functions/count_spec.rb @@ -18,4 +18,9 @@ describe "the count function" do lambda { @scope.function_count([]) }.should( raise_error(Puppet::ParseError)) end + it "should return the size of an array" do + result = @scope.function_count([['a','c','b']]) + result.should(eq(3)) + end + end -- 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. --- spec/unit/parser/functions/is_valid_domain_name_spec.rb | 10 ++++++++++ spec/unit/parser/functions/is_valid_ip_address_spec.rb | 10 ++++++++++ spec/unit/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 +++++ 25 files changed, 172 insertions(+), 2 deletions(-) (limited to 'spec') 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 a55930368afe2e8177608472653c4696eccec92f Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 15:38:19 +0100 Subject: (#2) - Added is_float and is_integer functionality. --- spec/unit/parser/functions/is_float_spec.rb | 4 ++-- spec/unit/parser/functions/is_integer_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/unit/parser/functions/is_float_spec.rb b/spec/unit/parser/functions/is_float_spec.rb index 3d58017..35c0dd6 100644 --- a/spec/unit/parser/functions/is_float_spec.rb +++ b/spec/unit/parser/functions/is_float_spec.rb @@ -19,7 +19,7 @@ describe "the is_float function" do end it "should return true if a float" do - result = @scope.function_is_float([0.12]) + result = @scope.function_is_float(["0.12"]) result.should(eq(true)) end @@ -29,7 +29,7 @@ describe "the is_float function" do end it "should return false if not an integer" do - result = @scope.function_is_float([3]) + result = @scope.function_is_float(["3"]) result.should(eq(false)) end diff --git a/spec/unit/parser/functions/is_integer_spec.rb b/spec/unit/parser/functions/is_integer_spec.rb index 596bd33..faf6f2d 100644 --- a/spec/unit/parser/functions/is_integer_spec.rb +++ b/spec/unit/parser/functions/is_integer_spec.rb @@ -19,12 +19,12 @@ describe "the is_integer function" do end it "should return true if an integer" do - result = @scope.function_is_integer([3]) + result = @scope.function_is_integer(["3"]) result.should(eq(true)) end it "should return false if a float" do - result = @scope.function_is_integer([3.2]) + result = @scope.function_is_integer(["3.2"]) result.should(eq(false)) end -- cgit v1.2.3 From 7efd6ec5819775226d669c15b58649d375f72959 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 15:44:26 +0100 Subject: (#1) - added new test for upcase. --- spec/unit/parser/functions/upcase_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/unit/parser/functions/upcase_spec.rb b/spec/unit/parser/functions/upcase_spec.rb index 10e4c8a..5d18846 100644 --- a/spec/unit/parser/functions/upcase_spec.rb +++ b/spec/unit/parser/functions/upcase_spec.rb @@ -23,4 +23,9 @@ describe "the upcase function" do result.should(eq('ABC')) end + it "should do nothing if a string is already upcase" do + result = @scope.function_upcase(["ABC"]) + result.should(eq('ABC')) + end + end -- cgit v1.2.3 From 635ed82e5cae38b0ba82098c340cbeed70d483c3 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 18:10:16 +0100 Subject: (#2) - unstubbed is_valid_ip_address --- .../parser/functions/is_valid_ip_address_spec.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'spec') 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 ee53ee1..2883aaa 100644 --- a/spec/unit/parser/functions/is_valid_ip_address_spec.rb +++ b/spec/unit/parser/functions/is_valid_ip_address_spec.rb @@ -18,14 +18,28 @@ 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") + it "should return true if an IPv4 address" do + result = @scope.function_is_valid_ip_address(["1.2.3.4"]) + result.should(eq(true)) + end + + it "should return true if a full IPv6 address" do + result = @scope.function_is_valid_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) + result.should(eq(true)) + end + + it "should return true if a compressed IPv6 address" do + result = @scope.function_is_valid_ip_address(["fe00::1"]) result.should(eq(true)) end it "should return false if not valid" do - result = @scope.function_is_valid_ip_address("asdf") + result = @scope.function_is_valid_ip_address(["asdf"]) result.should(eq(false)) end + it "should return false if IP octets out of range" do + result = @scope.function_is_valid_ip_address(["1.1.1.300"]) + result.should(eq(false)) + end end -- cgit v1.2.3 From 313df566bf5cfcbef73fc8182ccb07ddf2f13feb Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 21:03:33 +0100 Subject: (#2) unstub is_numeric function. --- spec/unit/parser/functions/is_numeric_spec.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/unit/parser/functions/is_numeric_spec.rb b/spec/unit/parser/functions/is_numeric_spec.rb index 3a49f5d..2191b7b 100644 --- a/spec/unit/parser/functions/is_numeric_spec.rb +++ b/spec/unit/parser/functions/is_numeric_spec.rb @@ -14,8 +14,23 @@ describe "the is_numeric function" 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 + it "should raise a ParseError if there is less than 1 argument" do lambda { @scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if an integer" do + result = @scope.function_is_numeric(["3"]) + result.should(eq(true)) + end + + it "should return true if a float" do + result = @scope.function_is_numeric(["3.2"]) + result.should(eq(true)) + end + + it "should return false if a string" do + result = @scope.function_is_numeric(["asdf"]) + result.should(eq(false)) + end + end -- cgit v1.2.3 From 1a7bd1ae8321bfc3d2ae87f1d5184828abf56916 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 21:10:33 +0100 Subject: Remove is_valid_netmask instead of unstubbing. Doesn't seem like a sensible function on its own. --- spec/unit/parser/functions/is_valid_netmask_spec.rb | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 spec/unit/parser/functions/is_valid_netmask_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/is_valid_netmask_spec.rb b/spec/unit/parser/functions/is_valid_netmask_spec.rb deleted file mode 100644 index 97cbb7c..0000000 --- a/spec/unit/parser/functions/is_valid_netmask_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/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 -- cgit v1.2.3 From a47853502d7681edd8173e05249ce43d44bede7c Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 21:15:43 +0100 Subject: Removed load_variables. load_yaml is sufficient to solve this problem on its own. --- spec/unit/parser/functions/load_variables_spec.rb | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 spec/unit/parser/functions/load_variables_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/load_variables_spec.rb b/spec/unit/parser/functions/load_variables_spec.rb deleted file mode 100644 index dc29e61..0000000 --- a/spec/unit/parser/functions/load_variables_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/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 -- cgit v1.2.3 From 4915eff575801e73ab15a77b500eb2e0d42b579c Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 21:23:53 +0100 Subject: Removed crontab functions instead of unstubbing them. --- .../functions/persistent_crontab_minutes_spec.rb | 21 --------------------- .../parser/functions/random_crontab_minutes_spec.rb | 21 --------------------- 2 files changed, 42 deletions(-) delete mode 100644 spec/unit/parser/functions/persistent_crontab_minutes_spec.rb delete mode 100644 spec/unit/parser/functions/random_crontab_minutes_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/persistent_crontab_minutes_spec.rb b/spec/unit/parser/functions/persistent_crontab_minutes_spec.rb deleted file mode 100644 index 1d8cbe7..0000000 --- a/spec/unit/parser/functions/persistent_crontab_minutes_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/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/random_crontab_minutes_spec.rb b/spec/unit/parser/functions/random_crontab_minutes_spec.rb deleted file mode 100644 index b47b3ae..0000000 --- a/spec/unit/parser/functions/random_crontab_minutes_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/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 -- cgit v1.2.3 From 7d6ae5d57ce45ff1293f02b90c816a7f938a3af6 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Thu, 28 Jul 2011 21:30:02 +0100 Subject: Count functionality overlaps with size - so removing it. --- spec/unit/parser/functions/count_spec.rb | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100755 spec/unit/parser/functions/count_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/count_spec.rb b/spec/unit/parser/functions/count_spec.rb deleted file mode 100755 index 62d005a..0000000 --- a/spec/unit/parser/functions/count_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the count function" do - before :all do - Puppet::Parser::Functions.autoloader.loadall - end - - before :each do - @scope = Puppet::Parser::Scope.new - end - - it "should exist" do - Puppet::Parser::Functions.function("count").should == "function_count" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_count([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return the size of an array" do - result = @scope.function_count([['a','c','b']]) - result.should(eq(3)) - end - -end -- 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. --- spec/unit/parser/functions/sort_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') 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 4080c0534e76cf68b935344c75b2382f0184a226 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 17:55:45 +0100 Subject: (#2) unstub is_valid_mac_address. --- spec/unit/parser/functions/is_valid_mac_address_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'spec') 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 c4eb468..62e6fee 100644 --- a/spec/unit/parser/functions/is_valid_mac_address_spec.rb +++ b/spec/unit/parser/functions/is_valid_mac_address_spec.rb @@ -19,12 +19,17 @@ describe "the is_valid_mac_address function" do 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 = @scope.function_is_valid_mac_address(["00:a0:1f:12:7f:a0"]) result.should(eq(true)) end + it "should return false if octets are out of range" do + result = @scope.function_is_valid_mac_address(["00:a0:1f:12:7f:g0"]) + result.should(eq(false)) + end + it "should return false if not valid" do - result = @scope.function_is_valid_mac_address("not valid") + result = @scope.function_is_valid_mac_address(["not valid"]) result.should(eq(false)) end -- cgit v1.2.3 From db7e06e301b689efcd421fd56fb1c23e3595e173 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 18:00:32 +0100 Subject: Removed join_with_prefix. --- .../unit/parser/functions/join_with_prefix_spec.rb | 26 ---------------------- 1 file changed, 26 deletions(-) delete mode 100644 spec/unit/parser/functions/join_with_prefix_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/join_with_prefix_spec.rb b/spec/unit/parser/functions/join_with_prefix_spec.rb deleted file mode 100644 index 70e6965..0000000 --- a/spec/unit/parser/functions/join_with_prefix_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - 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 -- cgit v1.2.3 From 56a402e6542105ec63c5071e685d5af93fd4d0f3 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 20:08:31 +0100 Subject: (#2) unstub is_valid_domain_name --- .../parser/functions/is_valid_domain_name_spec.rb | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'spec') 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 f03f6e8..3339447 100644 --- a/spec/unit/parser/functions/is_valid_domain_name_spec.rb +++ b/spec/unit/parser/functions/is_valid_domain_name_spec.rb @@ -19,13 +19,38 @@ describe "the is_valid_domain_name function" do 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)) + result = @scope.function_is_valid_domain_name(["foo.bar.com"]) + result.should(be_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)) + it "should allow domain parts to start with numbers" do + result = @scope.function_is_valid_domain_name(["3foo.2bar.com"]) + result.should(be_true) + end + + it "should allow domain to end with a dot" do + result = @scope.function_is_valid_domain_name(["3foo.2bar.com."]) + result.should(be_true) + end + + it "should allow a single part domain" do + result = @scope.function_is_valid_domain_name(["orange"]) + result.should(be_true) + end + + it "should return false if domain parts start with hyphens" do + result = @scope.function_is_valid_domain_name(["-3foo.2bar.com"]) + result.should(be_false) + end + + it "should return true if domain contains hyphens" do + result = @scope.function_is_valid_domain_name(["3foo-bar.2bar-fuzz.com"]) + result.should(be_true) + end + + it "should return false if domain name contains spaces" do + result = @scope.function_is_valid_domain_name(["not valid"]) + result.should(be_false) end end -- cgit v1.2.3 From 18e5302614bce168ac07e35dc23b058064e9e41c Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 20:11:47 +0100 Subject: (#2) fix is_string finally so it also makes sure numbers return false. --- spec/unit/parser/functions/is_string_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec') diff --git a/spec/unit/parser/functions/is_string_spec.rb b/spec/unit/parser/functions/is_string_spec.rb index 8c0061e..4f3f5fd 100644 --- a/spec/unit/parser/functions/is_string_spec.rb +++ b/spec/unit/parser/functions/is_string_spec.rb @@ -18,4 +18,24 @@ describe "the is_string function" do lambda { @scope.function_is_string([]) }.should( raise_error(Puppet::ParseError)) end + it "should return true if a string" do + result = @scope.function_is_string(["asdf"]) + result.should(eq(true)) + end + + it "should return false if an integer" do + result = @scope.function_is_string(["3"]) + result.should(eq(false)) + end + + it "should return false if a float" do + result = @scope.function_is_string(["3.23"]) + result.should(eq(false)) + end + + it "should return false if an array" do + result = @scope.function_is_string([["a","b","c"]]) + result.should(eq(false)) + end + end -- cgit v1.2.3 From aa023c1e5d23b2a5a66dbe9a36d0e8765a8d8cff Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 20:56:40 +0100 Subject: Removed date stub since this functinality is available in strftime anyway. --- spec/unit/parser/functions/date_spec.rb | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100755 spec/unit/parser/functions/date_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/date_spec.rb b/spec/unit/parser/functions/date_spec.rb deleted file mode 100755 index dcba4af..0000000 --- a/spec/unit/parser/functions/date_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/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 -- cgit v1.2.3 From 6827ad804f2eb44839f9a3e99f40f1bb2284f491 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 20:57:10 +0100 Subject: (#1) provide some more detailed tests for a number of functions. --- spec/unit/parser/functions/abs_spec.rb | 7 ++++++- spec/unit/parser/functions/downcase_spec.rb | 5 +++++ spec/unit/parser/functions/empty_spec.rb | 5 +++++ spec/unit/parser/functions/flatten_spec.rb | 5 +++++ spec/unit/parser/functions/is_array_spec.rb | 5 +++++ spec/unit/parser/functions/is_float_spec.rb | 2 +- spec/unit/parser/functions/num2bool_spec.rb | 7 ++++++- spec/unit/parser/functions/shuffle_spec.rb | 10 ++++++++++ spec/unit/parser/functions/strftime_spec.rb | 15 +++++++++++++++ spec/unit/parser/functions/time_spec.rb | 15 +++++++++++++++ spec/unit/parser/functions/type_spec.rb | 12 +++++++++++- 11 files changed, 84 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/unit/parser/functions/abs_spec.rb b/spec/unit/parser/functions/abs_spec.rb index 6bf0b41..65ba2e8 100755 --- a/spec/unit/parser/functions/abs_spec.rb +++ b/spec/unit/parser/functions/abs_spec.rb @@ -19,8 +19,13 @@ describe "the abs function" do end it "should convert a negative number into a positive" do - result = @scope.function_abs([-34]) + result = @scope.function_abs(["-34"]) result.should(eq(34)) end + it "should do nothing with a positive number" do + result = @scope.function_abs(["5678"]) + result.should(eq(5678)) + end + end diff --git a/spec/unit/parser/functions/downcase_spec.rb b/spec/unit/parser/functions/downcase_spec.rb index 0d53220..0bccd5f 100755 --- a/spec/unit/parser/functions/downcase_spec.rb +++ b/spec/unit/parser/functions/downcase_spec.rb @@ -23,4 +23,9 @@ describe "the downcase function" do result.should(eq("asfd")) end + it "should do nothing to a string that is already downcase" do + result = @scope.function_downcase(["asdf asdf"]) + result.should(eq("asdf asdf")) + end + end diff --git a/spec/unit/parser/functions/empty_spec.rb b/spec/unit/parser/functions/empty_spec.rb index 6c0fe69..cb0021f 100755 --- a/spec/unit/parser/functions/empty_spec.rb +++ b/spec/unit/parser/functions/empty_spec.rb @@ -23,4 +23,9 @@ describe "the empty function" do result.should(eq(true)) end + it "should return a false for a non-empty string" do + result = @scope.function_empty(['asdf']) + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/flatten_spec.rb b/spec/unit/parser/functions/flatten_spec.rb index 91cf4ef..7bedeb2 100755 --- a/spec/unit/parser/functions/flatten_spec.rb +++ b/spec/unit/parser/functions/flatten_spec.rb @@ -23,4 +23,9 @@ describe "the flatten function" do result.should(eq(["a","b","c","d","e","f","g"])) end + it "should do nothing to a structure that is already flat" do + result = @scope.function_flatten([["a","b","c","d"]]) + result.should(eq(["a","b","c","d"])) + end + end diff --git a/spec/unit/parser/functions/is_array_spec.rb b/spec/unit/parser/functions/is_array_spec.rb index 15b563c..537595c 100644 --- a/spec/unit/parser/functions/is_array_spec.rb +++ b/spec/unit/parser/functions/is_array_spec.rb @@ -28,4 +28,9 @@ describe "the is_array function" do result.should(eq(false)) end + it "should return false if passed a string" do + result = @scope.function_is_array(["asdf"]) + result.should(eq(false)) + end + end diff --git a/spec/unit/parser/functions/is_float_spec.rb b/spec/unit/parser/functions/is_float_spec.rb index 35c0dd6..55ba8cf 100644 --- a/spec/unit/parser/functions/is_float_spec.rb +++ b/spec/unit/parser/functions/is_float_spec.rb @@ -28,7 +28,7 @@ describe "the is_float function" do result.should(eq(false)) end - it "should return false if not an integer" do + it "should return false if an integer" do result = @scope.function_is_float(["3"]) result.should(eq(false)) end diff --git a/spec/unit/parser/functions/num2bool_spec.rb b/spec/unit/parser/functions/num2bool_spec.rb index 2f6435d..6585273 100644 --- a/spec/unit/parser/functions/num2bool_spec.rb +++ b/spec/unit/parser/functions/num2bool_spec.rb @@ -20,7 +20,12 @@ describe "the num2bool function" do it "should return true if 1" do result = @scope.function_num2bool(["1"]) - result.should(eq(true)) + result.should(be_true) + end + + it "should return false if 0" do + result = @scope.function_num2bool(["0"]) + result.should(be_false) end end diff --git a/spec/unit/parser/functions/shuffle_spec.rb b/spec/unit/parser/functions/shuffle_spec.rb index cf063c6..936c2fd 100644 --- a/spec/unit/parser/functions/shuffle_spec.rb +++ b/spec/unit/parser/functions/shuffle_spec.rb @@ -18,4 +18,14 @@ describe "the shuffle function" do lambda { @scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError)) end + it "should shuffle a string and the result should be the same size" do + result = @scope.function_shuffle(["asdf"]) + result.size.should(eq(4)) + end + + 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")) + end + end diff --git a/spec/unit/parser/functions/strftime_spec.rb b/spec/unit/parser/functions/strftime_spec.rb index e377954..f7a2cd9 100644 --- a/spec/unit/parser/functions/strftime_spec.rb +++ b/spec/unit/parser/functions/strftime_spec.rb @@ -18,4 +18,19 @@ describe "the strftime function" do lambda { @scope.function_strftime([]) }.should( raise_error(Puppet::ParseError)) end + it "using %s should be higher then when I wrote this test" do + result = @scope.function_strftime(["%s"]) + result.to_i.should(be > 1311953157) + end + + it "using %s should be lower then 1.5 trillion" do + result = @scope.function_strftime(["%s"]) + result.to_i.should(be < 1500000000) + end + + it "should return a date when given %Y-%m-%d" do + result = @scope.function_strftime(["%Y-%m-%d"]) + result.should =~ /^\d{4}-\d{2}-\d{2}$/ + end + end diff --git a/spec/unit/parser/functions/time_spec.rb b/spec/unit/parser/functions/time_spec.rb index 8bf5982..666e8e0 100644 --- a/spec/unit/parser/functions/time_spec.rb +++ b/spec/unit/parser/functions/time_spec.rb @@ -18,4 +18,19 @@ describe "the time function" do lambda { @scope.function_time(['','']) }.should( raise_error(Puppet::ParseError)) end + it "should return a number" do + result = @scope.function_time([]) + result.class.should(eq(Fixnum)) + end + + it "should be higher then when I wrote this test" do + result = @scope.function_time([]) + result.should(be > 1311953157) + end + + it "should be lower then 1.5 trillion" do + result = @scope.function_time([]) + result.should(be < 1500000000) + end + end diff --git a/spec/unit/parser/functions/type_spec.rb b/spec/unit/parser/functions/type_spec.rb index fddb87d..36c3823 100644 --- a/spec/unit/parser/functions/type_spec.rb +++ b/spec/unit/parser/functions/type_spec.rb @@ -18,9 +18,19 @@ 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 + it "should return String when given a string" do result = @scope.function_type(["aaabbbbcccc"]) result.should(eq('String')) end + it "should return Array when given an array" do + result = @scope.function_type([["aaabbbbcccc","asdf"]]) + result.should(eq('Array')) + end + + it "should return Hash when given a hash" do + result = @scope.function_type([{"a"=>1,"b"=>2}]) + result.should(eq('Hash')) + end + end -- cgit v1.2.3 From 284843bd968acd3c361907aadc7921e1eda94822 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 21:17:19 +0100 Subject: Some improvements to values_at tests. --- spec/unit/parser/functions/values_at_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'spec') diff --git a/spec/unit/parser/functions/values_at_spec.rb b/spec/unit/parser/functions/values_at_spec.rb index ec8730b..6c45316 100644 --- a/spec/unit/parser/functions/values_at_spec.rb +++ b/spec/unit/parser/functions/values_at_spec.rb @@ -18,9 +18,28 @@ describe "the values_at function" do lambda { @scope.function_values_at([]) }.should( raise_error(Puppet::ParseError)) end + it "should raise a ParseError if you try to use a range where stop is greater then start" do + lambda { @scope.function_values_at([['a','b'],["3-1"]]) }.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 + it "should return a value at from an array when passed a range" do + result = @scope.function_values_at([['a','b','c'],"0-1"]) + result.should(eq(['a','b'])) + end + + it "should return chosen values from an array when passed number of indexes" do + result = @scope.function_values_at([['a','b','c'],["0","2"]]) + result.should(eq(['a','c'])) + end + + it "should return chosen values from an array when passed ranges and multiple indexes" do + result = @scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]]) + result.should(eq(['a','c','e','f'])) + end + end -- cgit v1.2.3 From f9634b7f9b03be86e25dc740cdcda754a0d2bf7d Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 22:08:09 +0100 Subject: Remove rand. --- spec/unit/parser/functions/rand_spec.rb | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 spec/unit/parser/functions/rand_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/rand_spec.rb b/spec/unit/parser/functions/rand_spec.rb deleted file mode 100644 index 818d1c5..0000000 --- a/spec/unit/parser/functions/rand_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/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 -- 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. --- spec/unit/parser/functions/type_spec.rb | 22 ++++++++++++++++------ spec/unit/parser/functions/unique_spec.rb | 9 +++++++-- spec/unit/parser/functions/values_spec.rb | 4 ++++ 3 files changed, 27 insertions(+), 8 deletions(-) (limited to 'spec') 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 a1cae426f1d6b8f2c19184ec8aac3ebc47d97744 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 23:09:30 +0100 Subject: (#3) Provide documentation for remaining functions. --- spec/unit/parser/functions/type_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec') diff --git a/spec/unit/parser/functions/type_spec.rb b/spec/unit/parser/functions/type_spec.rb index 53071f3..e3c28ed 100644 --- a/spec/unit/parser/functions/type_spec.rb +++ b/spec/unit/parser/functions/type_spec.rb @@ -43,4 +43,9 @@ describe "the type function" do result.should(eq('float')) end + it "should return boolean when given a boolean" do + result = @scope.function_type([true]) + result.should(eq('boolean')) + 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. --- spec/unit/parser/functions/shuffle_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') 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 From 681a1c7971d78c53dc9a0747ae4d983ff6b0d670 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 5 Aug 2011 08:25:03 +0100 Subject: Prep for stdlib merge * Renamed load_yaml & load_json to parseyaml & parsejson * Renamed is_valid_* functions and remove the 'valid_' --- spec/unit/parser/functions/is_domain_name_spec.rb | 56 ++++++++++++++++++++++ spec/unit/parser/functions/is_ip_address_spec.rb | 45 +++++++++++++++++ spec/unit/parser/functions/is_mac_address_spec.rb | 36 ++++++++++++++ .../parser/functions/is_valid_domain_name_spec.rb | 56 ---------------------- .../parser/functions/is_valid_ip_address_spec.rb | 45 ----------------- .../parser/functions/is_valid_mac_address_spec.rb | 36 -------------- spec/unit/parser/functions/load_json_spec.rb | 29 ----------- spec/unit/parser/functions/load_yaml_spec.rb | 31 ------------ spec/unit/parser/functions/parsejson_spec.rb | 29 +++++++++++ spec/unit/parser/functions/parseyaml_spec.rb | 31 ++++++++++++ 10 files changed, 197 insertions(+), 197 deletions(-) create mode 100644 spec/unit/parser/functions/is_domain_name_spec.rb create mode 100644 spec/unit/parser/functions/is_ip_address_spec.rb create mode 100644 spec/unit/parser/functions/is_mac_address_spec.rb delete mode 100644 spec/unit/parser/functions/is_valid_domain_name_spec.rb delete mode 100644 spec/unit/parser/functions/is_valid_ip_address_spec.rb delete mode 100644 spec/unit/parser/functions/is_valid_mac_address_spec.rb delete mode 100644 spec/unit/parser/functions/load_json_spec.rb delete mode 100644 spec/unit/parser/functions/load_yaml_spec.rb create mode 100644 spec/unit/parser/functions/parsejson_spec.rb create mode 100644 spec/unit/parser/functions/parseyaml_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/is_domain_name_spec.rb b/spec/unit/parser/functions/is_domain_name_spec.rb new file mode 100644 index 0000000..ec7c7f5 --- /dev/null +++ b/spec/unit/parser/functions/is_domain_name_spec.rb @@ -0,0 +1,56 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_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_domain_name").should == "function_is_domain_name" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a valid domain name" do + result = @scope.function_is_domain_name(["foo.bar.com"]) + result.should(be_true) + end + + it "should allow domain parts to start with numbers" do + result = @scope.function_is_domain_name(["3foo.2bar.com"]) + result.should(be_true) + end + + it "should allow domain to end with a dot" do + result = @scope.function_is_domain_name(["3foo.2bar.com."]) + result.should(be_true) + end + + it "should allow a single part domain" do + result = @scope.function_is_domain_name(["orange"]) + result.should(be_true) + end + + it "should return false if domain parts start with hyphens" do + result = @scope.function_is_domain_name(["-3foo.2bar.com"]) + result.should(be_false) + end + + it "should return true if domain contains hyphens" do + result = @scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"]) + result.should(be_true) + end + + it "should return false if domain name contains spaces" do + result = @scope.function_is_domain_name(["not valid"]) + result.should(be_false) + end + +end diff --git a/spec/unit/parser/functions/is_ip_address_spec.rb b/spec/unit/parser/functions/is_ip_address_spec.rb new file mode 100644 index 0000000..98ce828 --- /dev/null +++ b/spec/unit/parser/functions/is_ip_address_spec.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_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_ip_address").should == "function_is_ip_address" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if an IPv4 address" do + result = @scope.function_is_ip_address(["1.2.3.4"]) + result.should(eq(true)) + end + + it "should return true if a full IPv6 address" do + result = @scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) + result.should(eq(true)) + end + + it "should return true if a compressed IPv6 address" do + result = @scope.function_is_ip_address(["fe00::1"]) + result.should(eq(true)) + end + + it "should return false if not valid" do + result = @scope.function_is_ip_address(["asdf"]) + result.should(eq(false)) + end + + it "should return false if IP octets out of range" do + result = @scope.function_is_ip_address(["1.1.1.300"]) + result.should(eq(false)) + end +end diff --git a/spec/unit/parser/functions/is_mac_address_spec.rb b/spec/unit/parser/functions/is_mac_address_spec.rb new file mode 100644 index 0000000..c9b9637 --- /dev/null +++ b/spec/unit/parser/functions/is_mac_address_spec.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_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_mac_address").should == "function_is_mac_address" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a valid mac address" do + result = @scope.function_is_mac_address(["00:a0:1f:12:7f:a0"]) + result.should(eq(true)) + end + + it "should return false if octets are out of range" do + result = @scope.function_is_mac_address(["00:a0:1f:12:7f:g0"]) + result.should(eq(false)) + end + + it "should return false if not valid" do + result = @scope.function_is_mac_address(["not valid"]) + result.should(eq(false)) + 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 deleted file mode 100644 index 3339447..0000000 --- a/spec/unit/parser/functions/is_valid_domain_name_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -#!/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 - - it "should return true if a valid domain name" do - result = @scope.function_is_valid_domain_name(["foo.bar.com"]) - result.should(be_true) - end - - it "should allow domain parts to start with numbers" do - result = @scope.function_is_valid_domain_name(["3foo.2bar.com"]) - result.should(be_true) - end - - it "should allow domain to end with a dot" do - result = @scope.function_is_valid_domain_name(["3foo.2bar.com."]) - result.should(be_true) - end - - it "should allow a single part domain" do - result = @scope.function_is_valid_domain_name(["orange"]) - result.should(be_true) - end - - it "should return false if domain parts start with hyphens" do - result = @scope.function_is_valid_domain_name(["-3foo.2bar.com"]) - result.should(be_false) - end - - it "should return true if domain contains hyphens" do - result = @scope.function_is_valid_domain_name(["3foo-bar.2bar-fuzz.com"]) - result.should(be_true) - end - - it "should return false if domain name contains spaces" do - result = @scope.function_is_valid_domain_name(["not valid"]) - result.should(be_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 deleted file mode 100644 index 2883aaa..0000000 --- a/spec/unit/parser/functions/is_valid_ip_address_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/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 - - it "should return true if an IPv4 address" do - result = @scope.function_is_valid_ip_address(["1.2.3.4"]) - result.should(eq(true)) - end - - it "should return true if a full IPv6 address" do - result = @scope.function_is_valid_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) - result.should(eq(true)) - end - - it "should return true if a compressed IPv6 address" do - result = @scope.function_is_valid_ip_address(["fe00::1"]) - 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 - - it "should return false if IP octets out of range" do - result = @scope.function_is_valid_ip_address(["1.1.1.300"]) - 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 deleted file mode 100644 index 62e6fee..0000000 --- a/spec/unit/parser/functions/is_valid_mac_address_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 - - 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 octets are out of range" do - result = @scope.function_is_valid_mac_address(["00:a0:1f:12:7f:g0"]) - result.should(eq(false)) - 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/load_json_spec.rb b/spec/unit/parser/functions/load_json_spec.rb deleted file mode 100644 index 73a4566..0000000 --- a/spec/unit/parser/functions/load_json_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#!/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_yaml_spec.rb b/spec/unit/parser/functions/load_yaml_spec.rb deleted file mode 100644 index 2498d12..0000000 --- a/spec/unit/parser/functions/load_yaml_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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/parsejson_spec.rb b/spec/unit/parser/functions/parsejson_spec.rb new file mode 100644 index 0000000..26eea36 --- /dev/null +++ b/spec/unit/parser/functions/parsejson_spec.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the parsejson 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("parsejson").should == "function_parsejson" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert JSON to a data structure" do + json = <<-EOS +["aaa","bbb","ccc"] +EOS + result = @scope.function_parsejson([json]) + result.should(eq(['aaa','bbb','ccc'])) + end + +end diff --git a/spec/unit/parser/functions/parseyaml_spec.rb b/spec/unit/parser/functions/parseyaml_spec.rb new file mode 100644 index 0000000..f9cb049 --- /dev/null +++ b/spec/unit/parser/functions/parseyaml_spec.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the parseyaml 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("parseyaml").should == "function_parseyaml" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert YAML to a data structure" do + yaml = <<-EOS +- aaa +- bbb +- ccc +EOS + result = @scope.function_parseyaml([yaml]) + result.should(eq(['aaa','bbb','ccc'])) + end + +end -- cgit v1.2.3 From 1b73a66fc67af0e33fa41aacf50654d4a7a4903c Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 5 Aug 2011 08:46:38 +0100 Subject: * Moved kwalify to puppetlabs-kwalify project * Re-arranged tests in line with puppetlabs-stdlib --- spec/unit/parser/functions/abs_spec.rb | 31 ----------- spec/unit/parser/functions/bool2num_spec.rb | 31 ----------- spec/unit/parser/functions/capitalize_spec.rb | 26 --------- spec/unit/parser/functions/chomp_spec.rb | 26 --------- spec/unit/parser/functions/chop_spec.rb | 26 --------- spec/unit/parser/functions/delete_at_spec.rb | 26 --------- spec/unit/parser/functions/delete_spec.rb | 26 --------- spec/unit/parser/functions/downcase_spec.rb | 31 ----------- spec/unit/parser/functions/empty_spec.rb | 31 ----------- spec/unit/parser/functions/flatten_spec.rb | 31 ----------- spec/unit/parser/functions/grep_spec.rb | 26 --------- spec/unit/parser/functions/hash_spec.rb | 26 --------- spec/unit/parser/functions/is_array_spec.rb | 36 ------------- spec/unit/parser/functions/is_domain_name_spec.rb | 56 ------------------- spec/unit/parser/functions/is_float_spec.rb | 36 ------------- spec/unit/parser/functions/is_hash_spec.rb | 36 ------------- spec/unit/parser/functions/is_integer_spec.rb | 36 ------------- spec/unit/parser/functions/is_ip_address_spec.rb | 45 ---------------- spec/unit/parser/functions/is_mac_address_spec.rb | 36 ------------- spec/unit/parser/functions/is_numeric_spec.rb | 36 ------------- spec/unit/parser/functions/is_string_spec.rb | 41 -------------- spec/unit/parser/functions/join_spec.rb | 26 --------- spec/unit/parser/functions/keys_spec.rb | 26 --------- spec/unit/parser/functions/kwalify_spec.rb | 62 ---------------------- spec/unit/parser/functions/lstrip_spec.rb | 26 --------- spec/unit/parser/functions/member_spec.rb | 31 ----------- spec/unit/parser/functions/num2bool_spec.rb | 31 ----------- spec/unit/parser/functions/parsejson_spec.rb | 29 ---------- spec/unit/parser/functions/parseyaml_spec.rb | 31 ----------- spec/unit/parser/functions/prefix_spec.rb | 26 --------- spec/unit/parser/functions/range_spec.rb | 31 ----------- spec/unit/parser/functions/reverse_spec.rb | 26 --------- spec/unit/parser/functions/rstrip_spec.rb | 31 ----------- spec/unit/parser/functions/shuffle_spec.rb | 31 ----------- spec/unit/parser/functions/size_spec.rb | 31 ----------- spec/unit/parser/functions/sort_spec.rb | 31 ----------- spec/unit/parser/functions/squeeze_spec.rb | 31 ----------- spec/unit/parser/functions/str2bool_spec.rb | 31 ----------- spec/unit/parser/functions/strftime_spec.rb | 36 ------------- spec/unit/parser/functions/strip_spec.rb | 26 --------- spec/unit/parser/functions/swapcase_spec.rb | 26 --------- spec/unit/parser/functions/time_spec.rb | 36 ------------- spec/unit/parser/functions/type_spec.rb | 51 ------------------ spec/unit/parser/functions/unique_spec.rb | 31 ----------- spec/unit/parser/functions/upcase_spec.rb | 31 ----------- spec/unit/parser/functions/values_at_spec.rb | 45 ---------------- spec/unit/parser/functions/values_spec.rb | 30 ----------- spec/unit/parser/functions/zip_spec.rb | 26 --------- spec/unit/puppet/parser/functions/abs_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/bool2num_spec.rb | 31 +++++++++++ .../puppet/parser/functions/capitalize_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/chomp_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/chop_spec.rb | 26 +++++++++ .../unit/puppet/parser/functions/delete_at_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/delete_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/downcase_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/empty_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/flatten_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/grep_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/hash_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/is_array_spec.rb | 36 +++++++++++++ .../puppet/parser/functions/is_domain_name_spec.rb | 56 +++++++++++++++++++ spec/unit/puppet/parser/functions/is_float_spec.rb | 36 +++++++++++++ spec/unit/puppet/parser/functions/is_hash_spec.rb | 36 +++++++++++++ .../puppet/parser/functions/is_integer_spec.rb | 36 +++++++++++++ .../puppet/parser/functions/is_ip_address_spec.rb | 45 ++++++++++++++++ .../puppet/parser/functions/is_mac_address_spec.rb | 36 +++++++++++++ .../puppet/parser/functions/is_numeric_spec.rb | 36 +++++++++++++ .../unit/puppet/parser/functions/is_string_spec.rb | 41 ++++++++++++++ spec/unit/puppet/parser/functions/join_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/keys_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/lstrip_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/member_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/num2bool_spec.rb | 31 +++++++++++ .../unit/puppet/parser/functions/parsejson_spec.rb | 29 ++++++++++ .../unit/puppet/parser/functions/parseyaml_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/prefix_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/range_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/reverse_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/rstrip_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/shuffle_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/size_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/sort_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/squeeze_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/str2bool_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/strftime_spec.rb | 36 +++++++++++++ spec/unit/puppet/parser/functions/strip_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/swapcase_spec.rb | 26 +++++++++ spec/unit/puppet/parser/functions/time_spec.rb | 36 +++++++++++++ spec/unit/puppet/parser/functions/type_spec.rb | 51 ++++++++++++++++++ spec/unit/puppet/parser/functions/unique_spec.rb | 31 +++++++++++ spec/unit/puppet/parser/functions/upcase_spec.rb | 31 +++++++++++ .../unit/puppet/parser/functions/values_at_spec.rb | 45 ++++++++++++++++ spec/unit/puppet/parser/functions/values_spec.rb | 30 +++++++++++ spec/unit/puppet/parser/functions/zip_spec.rb | 26 +++++++++ 95 files changed, 1502 insertions(+), 1564 deletions(-) delete mode 100755 spec/unit/parser/functions/abs_spec.rb delete mode 100755 spec/unit/parser/functions/bool2num_spec.rb delete mode 100755 spec/unit/parser/functions/capitalize_spec.rb delete mode 100755 spec/unit/parser/functions/chomp_spec.rb delete mode 100755 spec/unit/parser/functions/chop_spec.rb delete mode 100755 spec/unit/parser/functions/delete_at_spec.rb delete mode 100755 spec/unit/parser/functions/delete_spec.rb delete mode 100755 spec/unit/parser/functions/downcase_spec.rb delete mode 100755 spec/unit/parser/functions/empty_spec.rb delete mode 100755 spec/unit/parser/functions/flatten_spec.rb delete mode 100755 spec/unit/parser/functions/grep_spec.rb delete mode 100644 spec/unit/parser/functions/hash_spec.rb delete mode 100644 spec/unit/parser/functions/is_array_spec.rb delete mode 100644 spec/unit/parser/functions/is_domain_name_spec.rb delete mode 100644 spec/unit/parser/functions/is_float_spec.rb delete mode 100644 spec/unit/parser/functions/is_hash_spec.rb delete mode 100644 spec/unit/parser/functions/is_integer_spec.rb delete mode 100644 spec/unit/parser/functions/is_ip_address_spec.rb delete mode 100644 spec/unit/parser/functions/is_mac_address_spec.rb delete mode 100644 spec/unit/parser/functions/is_numeric_spec.rb delete mode 100644 spec/unit/parser/functions/is_string_spec.rb delete mode 100644 spec/unit/parser/functions/join_spec.rb delete mode 100644 spec/unit/parser/functions/keys_spec.rb delete mode 100755 spec/unit/parser/functions/kwalify_spec.rb delete mode 100644 spec/unit/parser/functions/lstrip_spec.rb delete mode 100644 spec/unit/parser/functions/member_spec.rb delete mode 100644 spec/unit/parser/functions/num2bool_spec.rb delete mode 100644 spec/unit/parser/functions/parsejson_spec.rb delete mode 100644 spec/unit/parser/functions/parseyaml_spec.rb delete mode 100644 spec/unit/parser/functions/prefix_spec.rb delete mode 100644 spec/unit/parser/functions/range_spec.rb delete mode 100644 spec/unit/parser/functions/reverse_spec.rb delete mode 100644 spec/unit/parser/functions/rstrip_spec.rb delete mode 100644 spec/unit/parser/functions/shuffle_spec.rb delete mode 100644 spec/unit/parser/functions/size_spec.rb delete mode 100644 spec/unit/parser/functions/sort_spec.rb delete mode 100644 spec/unit/parser/functions/squeeze_spec.rb delete mode 100644 spec/unit/parser/functions/str2bool_spec.rb delete mode 100644 spec/unit/parser/functions/strftime_spec.rb delete mode 100644 spec/unit/parser/functions/strip_spec.rb delete mode 100644 spec/unit/parser/functions/swapcase_spec.rb delete mode 100644 spec/unit/parser/functions/time_spec.rb delete mode 100644 spec/unit/parser/functions/type_spec.rb delete mode 100644 spec/unit/parser/functions/unique_spec.rb delete mode 100644 spec/unit/parser/functions/upcase_spec.rb delete mode 100644 spec/unit/parser/functions/values_at_spec.rb delete mode 100644 spec/unit/parser/functions/values_spec.rb delete mode 100644 spec/unit/parser/functions/zip_spec.rb create mode 100755 spec/unit/puppet/parser/functions/abs_spec.rb create mode 100755 spec/unit/puppet/parser/functions/bool2num_spec.rb create mode 100755 spec/unit/puppet/parser/functions/capitalize_spec.rb create mode 100755 spec/unit/puppet/parser/functions/chomp_spec.rb create mode 100755 spec/unit/puppet/parser/functions/chop_spec.rb create mode 100755 spec/unit/puppet/parser/functions/delete_at_spec.rb create mode 100755 spec/unit/puppet/parser/functions/delete_spec.rb create mode 100755 spec/unit/puppet/parser/functions/downcase_spec.rb create mode 100755 spec/unit/puppet/parser/functions/empty_spec.rb create mode 100755 spec/unit/puppet/parser/functions/flatten_spec.rb create mode 100755 spec/unit/puppet/parser/functions/grep_spec.rb create mode 100644 spec/unit/puppet/parser/functions/hash_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_array_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_domain_name_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_float_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_hash_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_integer_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_ip_address_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_mac_address_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_numeric_spec.rb create mode 100644 spec/unit/puppet/parser/functions/is_string_spec.rb create mode 100644 spec/unit/puppet/parser/functions/join_spec.rb create mode 100644 spec/unit/puppet/parser/functions/keys_spec.rb create mode 100644 spec/unit/puppet/parser/functions/lstrip_spec.rb create mode 100644 spec/unit/puppet/parser/functions/member_spec.rb create mode 100644 spec/unit/puppet/parser/functions/num2bool_spec.rb create mode 100644 spec/unit/puppet/parser/functions/parsejson_spec.rb create mode 100644 spec/unit/puppet/parser/functions/parseyaml_spec.rb create mode 100644 spec/unit/puppet/parser/functions/prefix_spec.rb create mode 100644 spec/unit/puppet/parser/functions/range_spec.rb create mode 100644 spec/unit/puppet/parser/functions/reverse_spec.rb create mode 100644 spec/unit/puppet/parser/functions/rstrip_spec.rb create mode 100644 spec/unit/puppet/parser/functions/shuffle_spec.rb create mode 100644 spec/unit/puppet/parser/functions/size_spec.rb create mode 100644 spec/unit/puppet/parser/functions/sort_spec.rb create mode 100644 spec/unit/puppet/parser/functions/squeeze_spec.rb create mode 100644 spec/unit/puppet/parser/functions/str2bool_spec.rb create mode 100644 spec/unit/puppet/parser/functions/strftime_spec.rb create mode 100644 spec/unit/puppet/parser/functions/strip_spec.rb create mode 100644 spec/unit/puppet/parser/functions/swapcase_spec.rb create mode 100644 spec/unit/puppet/parser/functions/time_spec.rb create mode 100644 spec/unit/puppet/parser/functions/type_spec.rb create mode 100644 spec/unit/puppet/parser/functions/unique_spec.rb create mode 100644 spec/unit/puppet/parser/functions/upcase_spec.rb create mode 100644 spec/unit/puppet/parser/functions/values_at_spec.rb create mode 100644 spec/unit/puppet/parser/functions/values_spec.rb create mode 100644 spec/unit/puppet/parser/functions/zip_spec.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/abs_spec.rb b/spec/unit/parser/functions/abs_spec.rb deleted file mode 100755 index 65ba2e8..0000000 --- a/spec/unit/parser/functions/abs_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should convert a negative number into a positive" do - result = @scope.function_abs(["-34"]) - result.should(eq(34)) - end - - it "should do nothing with a positive number" do - result = @scope.function_abs(["5678"]) - result.should(eq(5678)) - end - -end diff --git a/spec/unit/parser/functions/bool2num_spec.rb b/spec/unit/parser/functions/bool2num_spec.rb deleted file mode 100755 index d5da18c..0000000 --- a/spec/unit/parser/functions/bool2num_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should convert true to 1" do - result = @scope.function_bool2num([true]) - result.should(eq(1)) - end - - it "should convert false to 0" do - result = @scope.function_bool2num([false]) - result.should(eq(0)) - end - -end diff --git a/spec/unit/parser/functions/capitalize_spec.rb b/spec/unit/parser/functions/capitalize_spec.rb deleted file mode 100755 index 1c45821..0000000 --- a/spec/unit/parser/functions/capitalize_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - it "should capitalize the beginning of a string" do - result = @scope.function_capitalize(["abc"]) - result.should(eq("Abc")) - end - -end diff --git a/spec/unit/parser/functions/chomp_spec.rb b/spec/unit/parser/functions/chomp_spec.rb deleted file mode 100755 index 0592115..0000000 --- a/spec/unit/parser/functions/chomp_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - it "should chomp the end of a string" do - result = @scope.function_chomp(["abc\n"]) - result.should(eq("abc")) - end - -end diff --git a/spec/unit/parser/functions/chop_spec.rb b/spec/unit/parser/functions/chop_spec.rb deleted file mode 100755 index 0c456a8..0000000 --- a/spec/unit/parser/functions/chop_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - it "should chop the end of a string" do - result = @scope.function_chop(["asdf\n"]) - result.should(eq("asdf")) - end - -end diff --git a/spec/unit/parser/functions/delete_at_spec.rb b/spec/unit/parser/functions/delete_at_spec.rb deleted file mode 100755 index 27db0c8..0000000 --- a/spec/unit/parser/functions/delete_at_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - it "should delete an item at specified location from an array" do - result = @scope.function_delete_at([['a','b','c'],1]) - result.should(eq(['a','c'])) - end - -end diff --git a/spec/unit/parser/functions/delete_spec.rb b/spec/unit/parser/functions/delete_spec.rb deleted file mode 100755 index fab3230..0000000 --- a/spec/unit/parser/functions/delete_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - it "should delete an item from an array" do - result = @scope.function_delete([['a','b','c'],'b']) - result.should(eq(['a','c'])) - end - -end diff --git a/spec/unit/parser/functions/downcase_spec.rb b/spec/unit/parser/functions/downcase_spec.rb deleted file mode 100755 index 0bccd5f..0000000 --- a/spec/unit/parser/functions/downcase_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should downcase a string" do - result = @scope.function_downcase(["ASFD"]) - result.should(eq("asfd")) - end - - it "should do nothing to a string that is already downcase" do - result = @scope.function_downcase(["asdf asdf"]) - result.should(eq("asdf asdf")) - end - -end diff --git a/spec/unit/parser/functions/empty_spec.rb b/spec/unit/parser/functions/empty_spec.rb deleted file mode 100755 index cb0021f..0000000 --- a/spec/unit/parser/functions/empty_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should return a true for an empty string" do - result = @scope.function_empty(['']) - result.should(eq(true)) - end - - it "should return a false for a non-empty string" do - result = @scope.function_empty(['asdf']) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/flatten_spec.rb b/spec/unit/parser/functions/flatten_spec.rb deleted file mode 100755 index 7bedeb2..0000000 --- a/spec/unit/parser/functions/flatten_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should flatten a complex data structure" do - result = @scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) - result.should(eq(["a","b","c","d","e","f","g"])) - end - - it "should do nothing to a structure that is already flat" do - result = @scope.function_flatten([["a","b","c","d"]]) - result.should(eq(["a","b","c","d"])) - end - -end diff --git a/spec/unit/parser/functions/grep_spec.rb b/spec/unit/parser/functions/grep_spec.rb deleted file mode 100755 index b1f647c..0000000 --- a/spec/unit/parser/functions/grep_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - it "should grep contents from an array" do - result = @scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"]) - result.should(eq(["aaabbb","bbbccc"])) - end - -end diff --git a/spec/unit/parser/functions/hash_spec.rb b/spec/unit/parser/functions/hash_spec.rb deleted file mode 100644 index 6d3d48c..0000000 --- a/spec/unit/parser/functions/hash_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - it "should convert an array to a hash" do - result = @scope.function_hash([['a',1,'b',2,'c',3]]) - result.should(eq({'a'=>1,'b'=>2,'c'=>3})) - end - -end diff --git a/spec/unit/parser/functions/is_array_spec.rb b/spec/unit/parser/functions/is_array_spec.rb deleted file mode 100644 index 537595c..0000000 --- a/spec/unit/parser/functions/is_array_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 - - it "should return true if passed an array" do - result = @scope.function_is_array([[1,2,3]]) - result.should(eq(true)) - end - - it "should return false if passed a hash" do - result = @scope.function_is_array([{'a'=>1}]) - result.should(eq(false)) - end - - it "should return false if passed a string" do - result = @scope.function_is_array(["asdf"]) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/is_domain_name_spec.rb b/spec/unit/parser/functions/is_domain_name_spec.rb deleted file mode 100644 index ec7c7f5..0000000 --- a/spec/unit/parser/functions/is_domain_name_spec.rb +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the is_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_domain_name").should == "function_is_domain_name" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if a valid domain name" do - result = @scope.function_is_domain_name(["foo.bar.com"]) - result.should(be_true) - end - - it "should allow domain parts to start with numbers" do - result = @scope.function_is_domain_name(["3foo.2bar.com"]) - result.should(be_true) - end - - it "should allow domain to end with a dot" do - result = @scope.function_is_domain_name(["3foo.2bar.com."]) - result.should(be_true) - end - - it "should allow a single part domain" do - result = @scope.function_is_domain_name(["orange"]) - result.should(be_true) - end - - it "should return false if domain parts start with hyphens" do - result = @scope.function_is_domain_name(["-3foo.2bar.com"]) - result.should(be_false) - end - - it "should return true if domain contains hyphens" do - result = @scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"]) - result.should(be_true) - end - - it "should return false if domain name contains spaces" do - result = @scope.function_is_domain_name(["not valid"]) - result.should(be_false) - end - -end diff --git a/spec/unit/parser/functions/is_float_spec.rb b/spec/unit/parser/functions/is_float_spec.rb deleted file mode 100644 index 55ba8cf..0000000 --- a/spec/unit/parser/functions/is_float_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 - - it "should return true if a float" do - result = @scope.function_is_float(["0.12"]) - result.should(eq(true)) - end - - it "should return false if a string" do - result = @scope.function_is_float(["asdf"]) - result.should(eq(false)) - end - - it "should return false if an integer" do - result = @scope.function_is_float(["3"]) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/is_hash_spec.rb b/spec/unit/parser/functions/is_hash_spec.rb deleted file mode 100644 index 94364f5..0000000 --- a/spec/unit/parser/functions/is_hash_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 - - it "should return true if passed a hash" do - result = @scope.function_is_hash([{"a"=>1,"b"=>2}]) - result.should(eq(true)) - end - - it "should return false if passed an array" do - result = @scope.function_is_hash([["a","b"]]) - result.should(eq(false)) - end - - it "should return false if passed a string" do - result = @scope.function_is_hash(["asdf"]) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/is_integer_spec.rb b/spec/unit/parser/functions/is_integer_spec.rb deleted file mode 100644 index faf6f2d..0000000 --- a/spec/unit/parser/functions/is_integer_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 - - it "should return true if an integer" do - result = @scope.function_is_integer(["3"]) - result.should(eq(true)) - end - - it "should return false if a float" do - result = @scope.function_is_integer(["3.2"]) - result.should(eq(false)) - end - - it "should return false if a string" do - result = @scope.function_is_integer(["asdf"]) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/is_ip_address_spec.rb b/spec/unit/parser/functions/is_ip_address_spec.rb deleted file mode 100644 index 98ce828..0000000 --- a/spec/unit/parser/functions/is_ip_address_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the is_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_ip_address").should == "function_is_ip_address" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if an IPv4 address" do - result = @scope.function_is_ip_address(["1.2.3.4"]) - result.should(eq(true)) - end - - it "should return true if a full IPv6 address" do - result = @scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) - result.should(eq(true)) - end - - it "should return true if a compressed IPv6 address" do - result = @scope.function_is_ip_address(["fe00::1"]) - result.should(eq(true)) - end - - it "should return false if not valid" do - result = @scope.function_is_ip_address(["asdf"]) - result.should(eq(false)) - end - - it "should return false if IP octets out of range" do - result = @scope.function_is_ip_address(["1.1.1.300"]) - result.should(eq(false)) - end -end diff --git a/spec/unit/parser/functions/is_mac_address_spec.rb b/spec/unit/parser/functions/is_mac_address_spec.rb deleted file mode 100644 index c9b9637..0000000 --- a/spec/unit/parser/functions/is_mac_address_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the is_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_mac_address").should == "function_is_mac_address" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if a valid mac address" do - result = @scope.function_is_mac_address(["00:a0:1f:12:7f:a0"]) - result.should(eq(true)) - end - - it "should return false if octets are out of range" do - result = @scope.function_is_mac_address(["00:a0:1f:12:7f:g0"]) - result.should(eq(false)) - end - - it "should return false if not valid" do - result = @scope.function_is_mac_address(["not valid"]) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/is_numeric_spec.rb b/spec/unit/parser/functions/is_numeric_spec.rb deleted file mode 100644 index 2191b7b..0000000 --- a/spec/unit/parser/functions/is_numeric_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 argument" do - lambda { @scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should return true if an integer" do - result = @scope.function_is_numeric(["3"]) - result.should(eq(true)) - end - - it "should return true if a float" do - result = @scope.function_is_numeric(["3.2"]) - result.should(eq(true)) - end - - it "should return false if a string" do - result = @scope.function_is_numeric(["asdf"]) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/is_string_spec.rb b/spec/unit/parser/functions/is_string_spec.rb deleted file mode 100644 index 4f3f5fd..0000000 --- a/spec/unit/parser/functions/is_string_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -#!/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 - - it "should return true if a string" do - result = @scope.function_is_string(["asdf"]) - result.should(eq(true)) - end - - it "should return false if an integer" do - result = @scope.function_is_string(["3"]) - result.should(eq(false)) - end - - it "should return false if a float" do - result = @scope.function_is_string(["3.23"]) - result.should(eq(false)) - end - - it "should return false if an array" do - result = @scope.function_is_string([["a","b","c"]]) - result.should(eq(false)) - end - -end diff --git a/spec/unit/parser/functions/join_spec.rb b/spec/unit/parser/functions/join_spec.rb deleted file mode 100644 index 1b3dec8..0000000 --- a/spec/unit/parser/functions/join_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - 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/keys_spec.rb b/spec/unit/parser/functions/keys_spec.rb deleted file mode 100644 index 927be96..0000000 --- a/spec/unit/parser/functions/keys_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - 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/kwalify_spec.rb b/spec/unit/parser/functions/kwalify_spec.rb deleted file mode 100755 index abdd529..0000000 --- a/spec/unit/parser/functions/kwalify_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the kwalify 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("kwalify").should == "function_kwalify" - end - - it "should raise a ParseError if there is less than 2 arguments" do - lambda { @scope.function_kwalify([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should validate a simple array schema" do - schema = { - 'type' => 'seq', - 'sequence' => [ - { 'type' => 'str' } - ] - } - document = ['a','b','c'] - @scope.function_kwalify([schema, document]) - end - - it "should not validate a simple array schema when invalid" do - schema = { - 'type' => 'seq', - 'sequence' => [ - { 'type' => 'str' } - ] - } - document = ['a','b',{'a' => 'b'}] - lambda { @scope.function_kwalify([schema, document]) }.should(raise_error(Puppet::ParseError)) - end - - it "should validate a hash schema" do - schema = { - 'type' => 'map', - 'mapping' => { - 'key1' => { - 'type' => 'str', - }, - 'key2' => { - 'type' => 'str', - }, - } - } - document = { - 'key1' => 'b', - 'key2' => 'c', - } - @scope.function_kwalify([schema, document]) - end - -end diff --git a/spec/unit/parser/functions/lstrip_spec.rb b/spec/unit/parser/functions/lstrip_spec.rb deleted file mode 100644 index ac331fa..0000000 --- a/spec/unit/parser/functions/lstrip_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - 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 deleted file mode 100644 index 2cebc0d..0000000 --- a/spec/unit/parser/functions/member_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - 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 deleted file mode 100644 index 6585273..0000000 --- a/spec/unit/parser/functions/num2bool_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should return true if 1" do - result = @scope.function_num2bool(["1"]) - result.should(be_true) - end - - it "should return false if 0" do - result = @scope.function_num2bool(["0"]) - result.should(be_false) - end - -end diff --git a/spec/unit/parser/functions/parsejson_spec.rb b/spec/unit/parser/functions/parsejson_spec.rb deleted file mode 100644 index 26eea36..0000000 --- a/spec/unit/parser/functions/parsejson_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the parsejson 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("parsejson").should == "function_parsejson" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert JSON to a data structure" do - json = <<-EOS -["aaa","bbb","ccc"] -EOS - result = @scope.function_parsejson([json]) - result.should(eq(['aaa','bbb','ccc'])) - end - -end diff --git a/spec/unit/parser/functions/parseyaml_spec.rb b/spec/unit/parser/functions/parseyaml_spec.rb deleted file mode 100644 index f9cb049..0000000 --- a/spec/unit/parser/functions/parseyaml_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env rspec -require 'spec_helper' - -describe "the parseyaml 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("parseyaml").should == "function_parseyaml" - end - - it "should raise a ParseError if there is less than 1 arguments" do - lambda { @scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should convert YAML to a data structure" do - yaml = <<-EOS -- aaa -- bbb -- ccc -EOS - result = @scope.function_parseyaml([yaml]) - result.should(eq(['aaa','bbb','ccc'])) - end - -end diff --git a/spec/unit/parser/functions/prefix_spec.rb b/spec/unit/parser/functions/prefix_spec.rb deleted file mode 100644 index a0cbcab..0000000 --- a/spec/unit/parser/functions/prefix_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - 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 deleted file mode 100644 index 8c2446a..0000000 --- a/spec/unit/parser/functions/range_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - 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 deleted file mode 100644 index 4fa50e4..0000000 --- a/spec/unit/parser/functions/reverse_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - 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 deleted file mode 100644 index af8cc12..0000000 --- a/spec/unit/parser/functions/rstrip_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - 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/shuffle_spec.rb b/spec/unit/parser/functions/shuffle_spec.rb deleted file mode 100644 index f04fda5..0000000 --- a/spec/unit/parser/functions/shuffle_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should shuffle a string and the result should be the same size" do - result = @scope.function_shuffle(["asdf"]) - result.size.should(eq(4)) - end - - it "should shuffle a string but the sorted contents should still be the same" do - result = @scope.function_shuffle(["adfs"]) - result.split("").sort.join("").should(eq("adfs")) - end - -end diff --git a/spec/unit/parser/functions/size_spec.rb b/spec/unit/parser/functions/size_spec.rb deleted file mode 100644 index ccaa335..0000000 --- a/spec/unit/parser/functions/size_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - 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 deleted file mode 100644 index fbe3073..0000000 --- a/spec/unit/parser/functions/sort_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 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 - - it "should sort a string" do - result = @scope.function_sort(["acb"]) - result.should(eq('abc')) - end - -end diff --git a/spec/unit/parser/functions/squeeze_spec.rb b/spec/unit/parser/functions/squeeze_spec.rb deleted file mode 100644 index 9355ad2..0000000 --- a/spec/unit/parser/functions/squeeze_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - 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 deleted file mode 100644 index d7f0ac9..0000000 --- a/spec/unit/parser/functions/str2bool_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - 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/strftime_spec.rb b/spec/unit/parser/functions/strftime_spec.rb deleted file mode 100644 index f7a2cd9..0000000 --- a/spec/unit/parser/functions/strftime_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 - - it "using %s should be higher then when I wrote this test" do - result = @scope.function_strftime(["%s"]) - result.to_i.should(be > 1311953157) - end - - it "using %s should be lower then 1.5 trillion" do - result = @scope.function_strftime(["%s"]) - result.to_i.should(be < 1500000000) - end - - it "should return a date when given %Y-%m-%d" do - result = @scope.function_strftime(["%Y-%m-%d"]) - result.should =~ /^\d{4}-\d{2}-\d{2}$/ - end - -end diff --git a/spec/unit/parser/functions/strip_spec.rb b/spec/unit/parser/functions/strip_spec.rb deleted file mode 100644 index 48a52dd..0000000 --- a/spec/unit/parser/functions/strip_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - 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 deleted file mode 100644 index 2686054..0000000 --- a/spec/unit/parser/functions/swapcase_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - it "should swapcase a string" do - result = @scope.function_swapcase(["aaBBccDD"]) - result.should(eq('AAbbCCdd')) - end - -end diff --git a/spec/unit/parser/functions/time_spec.rb b/spec/unit/parser/functions/time_spec.rb deleted file mode 100644 index 666e8e0..0000000 --- a/spec/unit/parser/functions/time_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -#!/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 - - it "should return a number" do - result = @scope.function_time([]) - result.class.should(eq(Fixnum)) - end - - it "should be higher then when I wrote this test" do - result = @scope.function_time([]) - result.should(be > 1311953157) - end - - it "should be lower then 1.5 trillion" do - result = @scope.function_time([]) - result.should(be < 1500000000) - end - -end diff --git a/spec/unit/parser/functions/type_spec.rb b/spec/unit/parser/functions/type_spec.rb deleted file mode 100644 index e3c28ed..0000000 --- a/spec/unit/parser/functions/type_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -#!/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 - - it "should return string when given a string" do - result = @scope.function_type(["aaabbbbcccc"]) - result.should(eq('string')) - end - - it "should return array when given an array" do - result = @scope.function_type([["aaabbbbcccc","asdf"]]) - result.should(eq('array')) - end - - it "should return hash when given a hash" do - result = @scope.function_type([{"a"=>1,"b"=>2}]) - 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 - - it "should return boolean when given a boolean" do - result = @scope.function_type([true]) - result.should(eq('boolean')) - end - -end diff --git a/spec/unit/parser/functions/unique_spec.rb b/spec/unit/parser/functions/unique_spec.rb deleted file mode 100644 index 627dc33..0000000 --- a/spec/unit/parser/functions/unique_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should remove duplicate elements in a string" do - 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/upcase_spec.rb b/spec/unit/parser/functions/upcase_spec.rb deleted file mode 100644 index 5d18846..0000000 --- a/spec/unit/parser/functions/upcase_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/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 - - it "should upcase a string" do - result = @scope.function_upcase(["abc"]) - result.should(eq('ABC')) - end - - it "should do nothing if a string is already upcase" 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 deleted file mode 100644 index 6c45316..0000000 --- a/spec/unit/parser/functions/values_at_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -#!/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 - - it "should raise a ParseError if you try to use a range where stop is greater then start" do - lambda { @scope.function_values_at([['a','b'],["3-1"]]) }.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 - - it "should return a value at from an array when passed a range" do - result = @scope.function_values_at([['a','b','c'],"0-1"]) - result.should(eq(['a','b'])) - end - - it "should return chosen values from an array when passed number of indexes" do - result = @scope.function_values_at([['a','b','c'],["0","2"]]) - result.should(eq(['a','c'])) - end - - it "should return chosen values from an array when passed ranges and multiple indexes" do - result = @scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]]) - result.should(eq(['a','c','e','f'])) - end - -end diff --git a/spec/unit/parser/functions/values_spec.rb b/spec/unit/parser/functions/values_spec.rb deleted file mode 100644 index f6eb5b6..0000000 --- a/spec/unit/parser/functions/values_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -#!/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 - - 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 - - it "should return values from a hash" do - lambda { @scope.function_values([['a','b','c']]) }.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 deleted file mode 100644 index 074f4df..0000000 --- a/spec/unit/parser/functions/zip_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 - - 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 diff --git a/spec/unit/puppet/parser/functions/abs_spec.rb b/spec/unit/puppet/parser/functions/abs_spec.rb new file mode 100755 index 0000000..65ba2e8 --- /dev/null +++ b/spec/unit/puppet/parser/functions/abs_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should convert a negative number into a positive" do + result = @scope.function_abs(["-34"]) + result.should(eq(34)) + end + + it "should do nothing with a positive number" do + result = @scope.function_abs(["5678"]) + result.should(eq(5678)) + end + +end diff --git a/spec/unit/puppet/parser/functions/bool2num_spec.rb b/spec/unit/puppet/parser/functions/bool2num_spec.rb new file mode 100755 index 0000000..d5da18c --- /dev/null +++ b/spec/unit/puppet/parser/functions/bool2num_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should convert true to 1" do + result = @scope.function_bool2num([true]) + result.should(eq(1)) + end + + it "should convert false to 0" do + result = @scope.function_bool2num([false]) + result.should(eq(0)) + end + +end diff --git a/spec/unit/puppet/parser/functions/capitalize_spec.rb b/spec/unit/puppet/parser/functions/capitalize_spec.rb new file mode 100755 index 0000000..1c45821 --- /dev/null +++ b/spec/unit/puppet/parser/functions/capitalize_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should capitalize the beginning of a string" do + result = @scope.function_capitalize(["abc"]) + result.should(eq("Abc")) + end + +end diff --git a/spec/unit/puppet/parser/functions/chomp_spec.rb b/spec/unit/puppet/parser/functions/chomp_spec.rb new file mode 100755 index 0000000..0592115 --- /dev/null +++ b/spec/unit/puppet/parser/functions/chomp_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should chomp the end of a string" do + result = @scope.function_chomp(["abc\n"]) + result.should(eq("abc")) + end + +end diff --git a/spec/unit/puppet/parser/functions/chop_spec.rb b/spec/unit/puppet/parser/functions/chop_spec.rb new file mode 100755 index 0000000..0c456a8 --- /dev/null +++ b/spec/unit/puppet/parser/functions/chop_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should chop the end of a string" do + result = @scope.function_chop(["asdf\n"]) + result.should(eq("asdf")) + end + +end diff --git a/spec/unit/puppet/parser/functions/delete_at_spec.rb b/spec/unit/puppet/parser/functions/delete_at_spec.rb new file mode 100755 index 0000000..27db0c8 --- /dev/null +++ b/spec/unit/puppet/parser/functions/delete_at_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should delete an item at specified location from an array" do + result = @scope.function_delete_at([['a','b','c'],1]) + result.should(eq(['a','c'])) + end + +end diff --git a/spec/unit/puppet/parser/functions/delete_spec.rb b/spec/unit/puppet/parser/functions/delete_spec.rb new file mode 100755 index 0000000..fab3230 --- /dev/null +++ b/spec/unit/puppet/parser/functions/delete_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should delete an item from an array" do + result = @scope.function_delete([['a','b','c'],'b']) + result.should(eq(['a','c'])) + end + +end diff --git a/spec/unit/puppet/parser/functions/downcase_spec.rb b/spec/unit/puppet/parser/functions/downcase_spec.rb new file mode 100755 index 0000000..0bccd5f --- /dev/null +++ b/spec/unit/puppet/parser/functions/downcase_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should downcase a string" do + result = @scope.function_downcase(["ASFD"]) + result.should(eq("asfd")) + end + + it "should do nothing to a string that is already downcase" do + result = @scope.function_downcase(["asdf asdf"]) + result.should(eq("asdf asdf")) + end + +end diff --git a/spec/unit/puppet/parser/functions/empty_spec.rb b/spec/unit/puppet/parser/functions/empty_spec.rb new file mode 100755 index 0000000..cb0021f --- /dev/null +++ b/spec/unit/puppet/parser/functions/empty_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should return a true for an empty string" do + result = @scope.function_empty(['']) + result.should(eq(true)) + end + + it "should return a false for a non-empty string" do + result = @scope.function_empty(['asdf']) + result.should(eq(false)) + end + +end diff --git a/spec/unit/puppet/parser/functions/flatten_spec.rb b/spec/unit/puppet/parser/functions/flatten_spec.rb new file mode 100755 index 0000000..7bedeb2 --- /dev/null +++ b/spec/unit/puppet/parser/functions/flatten_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should flatten a complex data structure" do + result = @scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) + result.should(eq(["a","b","c","d","e","f","g"])) + end + + it "should do nothing to a structure that is already flat" do + result = @scope.function_flatten([["a","b","c","d"]]) + result.should(eq(["a","b","c","d"])) + end + +end diff --git a/spec/unit/puppet/parser/functions/grep_spec.rb b/spec/unit/puppet/parser/functions/grep_spec.rb new file mode 100755 index 0000000..b1f647c --- /dev/null +++ b/spec/unit/puppet/parser/functions/grep_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should grep contents from an array" do + result = @scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"]) + result.should(eq(["aaabbb","bbbccc"])) + end + +end diff --git a/spec/unit/puppet/parser/functions/hash_spec.rb b/spec/unit/puppet/parser/functions/hash_spec.rb new file mode 100644 index 0000000..6d3d48c --- /dev/null +++ b/spec/unit/puppet/parser/functions/hash_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should convert an array to a hash" do + result = @scope.function_hash([['a',1,'b',2,'c',3]]) + result.should(eq({'a'=>1,'b'=>2,'c'=>3})) + end + +end diff --git a/spec/unit/puppet/parser/functions/is_array_spec.rb b/spec/unit/puppet/parser/functions/is_array_spec.rb new file mode 100644 index 0000000..537595c --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_array_spec.rb @@ -0,0 +1,36 @@ +#!/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 + + it "should return true if passed an array" do + result = @scope.function_is_array([[1,2,3]]) + result.should(eq(true)) + end + + it "should return false if passed a hash" do + result = @scope.function_is_array([{'a'=>1}]) + result.should(eq(false)) + end + + it "should return false if passed a string" do + result = @scope.function_is_array(["asdf"]) + result.should(eq(false)) + end + +end diff --git a/spec/unit/puppet/parser/functions/is_domain_name_spec.rb b/spec/unit/puppet/parser/functions/is_domain_name_spec.rb new file mode 100644 index 0000000..ec7c7f5 --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_domain_name_spec.rb @@ -0,0 +1,56 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_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_domain_name").should == "function_is_domain_name" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a valid domain name" do + result = @scope.function_is_domain_name(["foo.bar.com"]) + result.should(be_true) + end + + it "should allow domain parts to start with numbers" do + result = @scope.function_is_domain_name(["3foo.2bar.com"]) + result.should(be_true) + end + + it "should allow domain to end with a dot" do + result = @scope.function_is_domain_name(["3foo.2bar.com."]) + result.should(be_true) + end + + it "should allow a single part domain" do + result = @scope.function_is_domain_name(["orange"]) + result.should(be_true) + end + + it "should return false if domain parts start with hyphens" do + result = @scope.function_is_domain_name(["-3foo.2bar.com"]) + result.should(be_false) + end + + it "should return true if domain contains hyphens" do + result = @scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"]) + result.should(be_true) + end + + it "should return false if domain name contains spaces" do + result = @scope.function_is_domain_name(["not valid"]) + result.should(be_false) + end + +end diff --git a/spec/unit/puppet/parser/functions/is_float_spec.rb b/spec/unit/puppet/parser/functions/is_float_spec.rb new file mode 100644 index 0000000..55ba8cf --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_float_spec.rb @@ -0,0 +1,36 @@ +#!/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 + + it "should return true if a float" do + result = @scope.function_is_float(["0.12"]) + result.should(eq(true)) + end + + it "should return false if a string" do + result = @scope.function_is_float(["asdf"]) + result.should(eq(false)) + end + + it "should return false if an integer" do + result = @scope.function_is_float(["3"]) + result.should(eq(false)) + end + +end diff --git a/spec/unit/puppet/parser/functions/is_hash_spec.rb b/spec/unit/puppet/parser/functions/is_hash_spec.rb new file mode 100644 index 0000000..94364f5 --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_hash_spec.rb @@ -0,0 +1,36 @@ +#!/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 + + it "should return true if passed a hash" do + result = @scope.function_is_hash([{"a"=>1,"b"=>2}]) + result.should(eq(true)) + end + + it "should return false if passed an array" do + result = @scope.function_is_hash([["a","b"]]) + result.should(eq(false)) + end + + it "should return false if passed a string" do + result = @scope.function_is_hash(["asdf"]) + result.should(eq(false)) + end + +end diff --git a/spec/unit/puppet/parser/functions/is_integer_spec.rb b/spec/unit/puppet/parser/functions/is_integer_spec.rb new file mode 100644 index 0000000..faf6f2d --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_integer_spec.rb @@ -0,0 +1,36 @@ +#!/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 + + it "should return true if an integer" do + result = @scope.function_is_integer(["3"]) + result.should(eq(true)) + end + + it "should return false if a float" do + result = @scope.function_is_integer(["3.2"]) + result.should(eq(false)) + end + + it "should return false if a string" do + result = @scope.function_is_integer(["asdf"]) + result.should(eq(false)) + end + +end diff --git a/spec/unit/puppet/parser/functions/is_ip_address_spec.rb b/spec/unit/puppet/parser/functions/is_ip_address_spec.rb new file mode 100644 index 0000000..98ce828 --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_ip_address_spec.rb @@ -0,0 +1,45 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_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_ip_address").should == "function_is_ip_address" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if an IPv4 address" do + result = @scope.function_is_ip_address(["1.2.3.4"]) + result.should(eq(true)) + end + + it "should return true if a full IPv6 address" do + result = @scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) + result.should(eq(true)) + end + + it "should return true if a compressed IPv6 address" do + result = @scope.function_is_ip_address(["fe00::1"]) + result.should(eq(true)) + end + + it "should return false if not valid" do + result = @scope.function_is_ip_address(["asdf"]) + result.should(eq(false)) + end + + it "should return false if IP octets out of range" do + result = @scope.function_is_ip_address(["1.1.1.300"]) + result.should(eq(false)) + end +end diff --git a/spec/unit/puppet/parser/functions/is_mac_address_spec.rb b/spec/unit/puppet/parser/functions/is_mac_address_spec.rb new file mode 100644 index 0000000..c9b9637 --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_mac_address_spec.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_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_mac_address").should == "function_is_mac_address" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a valid mac address" do + result = @scope.function_is_mac_address(["00:a0:1f:12:7f:a0"]) + result.should(eq(true)) + end + + it "should return false if octets are out of range" do + result = @scope.function_is_mac_address(["00:a0:1f:12:7f:g0"]) + result.should(eq(false)) + end + + it "should return false if not valid" do + result = @scope.function_is_mac_address(["not valid"]) + result.should(eq(false)) + end + +end diff --git a/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/spec/unit/puppet/parser/functions/is_numeric_spec.rb new file mode 100644 index 0000000..2191b7b --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_numeric_spec.rb @@ -0,0 +1,36 @@ +#!/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 argument" do + lambda { @scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if an integer" do + result = @scope.function_is_numeric(["3"]) + result.should(eq(true)) + end + + it "should return true if a float" do + result = @scope.function_is_numeric(["3.2"]) + result.should(eq(true)) + end + + it "should return false if a string" do + result = @scope.function_is_numeric(["asdf"]) + result.should(eq(false)) + end + +end diff --git a/spec/unit/puppet/parser/functions/is_string_spec.rb b/spec/unit/puppet/parser/functions/is_string_spec.rb new file mode 100644 index 0000000..4f3f5fd --- /dev/null +++ b/spec/unit/puppet/parser/functions/is_string_spec.rb @@ -0,0 +1,41 @@ +#!/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 + + it "should return true if a string" do + result = @scope.function_is_string(["asdf"]) + result.should(eq(true)) + end + + it "should return false if an integer" do + result = @scope.function_is_string(["3"]) + result.should(eq(false)) + end + + it "should return false if a float" do + result = @scope.function_is_string(["3.23"]) + result.should(eq(false)) + end + + it "should return false if an array" do + result = @scope.function_is_string([["a","b","c"]]) + result.should(eq(false)) + end + +end diff --git a/spec/unit/puppet/parser/functions/join_spec.rb b/spec/unit/puppet/parser/functions/join_spec.rb new file mode 100644 index 0000000..1b3dec8 --- /dev/null +++ b/spec/unit/puppet/parser/functions/join_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + 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/puppet/parser/functions/keys_spec.rb b/spec/unit/puppet/parser/functions/keys_spec.rb new file mode 100644 index 0000000..927be96 --- /dev/null +++ b/spec/unit/puppet/parser/functions/keys_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + 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/puppet/parser/functions/lstrip_spec.rb b/spec/unit/puppet/parser/functions/lstrip_spec.rb new file mode 100644 index 0000000..ac331fa --- /dev/null +++ b/spec/unit/puppet/parser/functions/lstrip_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should lstrip a string" do + result = @scope.function_lstrip([" asdf"]) + result.should(eq('asdf')) + end + +end diff --git a/spec/unit/puppet/parser/functions/member_spec.rb b/spec/unit/puppet/parser/functions/member_spec.rb new file mode 100644 index 0000000..2cebc0d --- /dev/null +++ b/spec/unit/puppet/parser/functions/member_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + 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/puppet/parser/functions/num2bool_spec.rb b/spec/unit/puppet/parser/functions/num2bool_spec.rb new file mode 100644 index 0000000..6585273 --- /dev/null +++ b/spec/unit/puppet/parser/functions/num2bool_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should return true if 1" do + result = @scope.function_num2bool(["1"]) + result.should(be_true) + end + + it "should return false if 0" do + result = @scope.function_num2bool(["0"]) + result.should(be_false) + end + +end diff --git a/spec/unit/puppet/parser/functions/parsejson_spec.rb b/spec/unit/puppet/parser/functions/parsejson_spec.rb new file mode 100644 index 0000000..26eea36 --- /dev/null +++ b/spec/unit/puppet/parser/functions/parsejson_spec.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the parsejson 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("parsejson").should == "function_parsejson" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert JSON to a data structure" do + json = <<-EOS +["aaa","bbb","ccc"] +EOS + result = @scope.function_parsejson([json]) + result.should(eq(['aaa','bbb','ccc'])) + end + +end diff --git a/spec/unit/puppet/parser/functions/parseyaml_spec.rb b/spec/unit/puppet/parser/functions/parseyaml_spec.rb new file mode 100644 index 0000000..f9cb049 --- /dev/null +++ b/spec/unit/puppet/parser/functions/parseyaml_spec.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the parseyaml 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("parseyaml").should == "function_parseyaml" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert YAML to a data structure" do + yaml = <<-EOS +- aaa +- bbb +- ccc +EOS + result = @scope.function_parseyaml([yaml]) + result.should(eq(['aaa','bbb','ccc'])) + end + +end diff --git a/spec/unit/puppet/parser/functions/prefix_spec.rb b/spec/unit/puppet/parser/functions/prefix_spec.rb new file mode 100644 index 0000000..a0cbcab --- /dev/null +++ b/spec/unit/puppet/parser/functions/prefix_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + 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/puppet/parser/functions/range_spec.rb b/spec/unit/puppet/parser/functions/range_spec.rb new file mode 100644 index 0000000..8c2446a --- /dev/null +++ b/spec/unit/puppet/parser/functions/range_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + 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/puppet/parser/functions/reverse_spec.rb b/spec/unit/puppet/parser/functions/reverse_spec.rb new file mode 100644 index 0000000..4fa50e4 --- /dev/null +++ b/spec/unit/puppet/parser/functions/reverse_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should reverse a string" do + result = @scope.function_reverse(["asdfghijkl"]) + result.should(eq('lkjihgfdsa')) + end + +end diff --git a/spec/unit/puppet/parser/functions/rstrip_spec.rb b/spec/unit/puppet/parser/functions/rstrip_spec.rb new file mode 100644 index 0000000..af8cc12 --- /dev/null +++ b/spec/unit/puppet/parser/functions/rstrip_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + 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/puppet/parser/functions/shuffle_spec.rb b/spec/unit/puppet/parser/functions/shuffle_spec.rb new file mode 100644 index 0000000..f04fda5 --- /dev/null +++ b/spec/unit/puppet/parser/functions/shuffle_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should shuffle a string and the result should be the same size" do + result = @scope.function_shuffle(["asdf"]) + result.size.should(eq(4)) + end + + it "should shuffle a string but the sorted contents should still be the same" do + result = @scope.function_shuffle(["adfs"]) + result.split("").sort.join("").should(eq("adfs")) + end + +end diff --git a/spec/unit/puppet/parser/functions/size_spec.rb b/spec/unit/puppet/parser/functions/size_spec.rb new file mode 100644 index 0000000..ccaa335 --- /dev/null +++ b/spec/unit/puppet/parser/functions/size_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + 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/puppet/parser/functions/sort_spec.rb b/spec/unit/puppet/parser/functions/sort_spec.rb new file mode 100644 index 0000000..fbe3073 --- /dev/null +++ b/spec/unit/puppet/parser/functions/sort_spec.rb @@ -0,0 +1,31 @@ +#!/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 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 + + it "should sort a string" do + result = @scope.function_sort(["acb"]) + result.should(eq('abc')) + end + +end diff --git a/spec/unit/puppet/parser/functions/squeeze_spec.rb b/spec/unit/puppet/parser/functions/squeeze_spec.rb new file mode 100644 index 0000000..9355ad2 --- /dev/null +++ b/spec/unit/puppet/parser/functions/squeeze_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + 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/puppet/parser/functions/str2bool_spec.rb b/spec/unit/puppet/parser/functions/str2bool_spec.rb new file mode 100644 index 0000000..d7f0ac9 --- /dev/null +++ b/spec/unit/puppet/parser/functions/str2bool_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + 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/puppet/parser/functions/strftime_spec.rb b/spec/unit/puppet/parser/functions/strftime_spec.rb new file mode 100644 index 0000000..f7a2cd9 --- /dev/null +++ b/spec/unit/puppet/parser/functions/strftime_spec.rb @@ -0,0 +1,36 @@ +#!/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 + + it "using %s should be higher then when I wrote this test" do + result = @scope.function_strftime(["%s"]) + result.to_i.should(be > 1311953157) + end + + it "using %s should be lower then 1.5 trillion" do + result = @scope.function_strftime(["%s"]) + result.to_i.should(be < 1500000000) + end + + it "should return a date when given %Y-%m-%d" do + result = @scope.function_strftime(["%Y-%m-%d"]) + result.should =~ /^\d{4}-\d{2}-\d{2}$/ + end + +end diff --git a/spec/unit/puppet/parser/functions/strip_spec.rb b/spec/unit/puppet/parser/functions/strip_spec.rb new file mode 100644 index 0000000..48a52dd --- /dev/null +++ b/spec/unit/puppet/parser/functions/strip_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should strip a string" do + result = @scope.function_strip([" ab cd "]) + result.should(eq('ab cd')) + end + +end diff --git a/spec/unit/puppet/parser/functions/swapcase_spec.rb b/spec/unit/puppet/parser/functions/swapcase_spec.rb new file mode 100644 index 0000000..2686054 --- /dev/null +++ b/spec/unit/puppet/parser/functions/swapcase_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + it "should swapcase a string" do + result = @scope.function_swapcase(["aaBBccDD"]) + result.should(eq('AAbbCCdd')) + end + +end diff --git a/spec/unit/puppet/parser/functions/time_spec.rb b/spec/unit/puppet/parser/functions/time_spec.rb new file mode 100644 index 0000000..666e8e0 --- /dev/null +++ b/spec/unit/puppet/parser/functions/time_spec.rb @@ -0,0 +1,36 @@ +#!/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 + + it "should return a number" do + result = @scope.function_time([]) + result.class.should(eq(Fixnum)) + end + + it "should be higher then when I wrote this test" do + result = @scope.function_time([]) + result.should(be > 1311953157) + end + + it "should be lower then 1.5 trillion" do + result = @scope.function_time([]) + result.should(be < 1500000000) + end + +end diff --git a/spec/unit/puppet/parser/functions/type_spec.rb b/spec/unit/puppet/parser/functions/type_spec.rb new file mode 100644 index 0000000..e3c28ed --- /dev/null +++ b/spec/unit/puppet/parser/functions/type_spec.rb @@ -0,0 +1,51 @@ +#!/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 + + it "should return string when given a string" do + result = @scope.function_type(["aaabbbbcccc"]) + result.should(eq('string')) + end + + it "should return array when given an array" do + result = @scope.function_type([["aaabbbbcccc","asdf"]]) + result.should(eq('array')) + end + + it "should return hash when given a hash" do + result = @scope.function_type([{"a"=>1,"b"=>2}]) + 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 + + it "should return boolean when given a boolean" do + result = @scope.function_type([true]) + result.should(eq('boolean')) + end + +end diff --git a/spec/unit/puppet/parser/functions/unique_spec.rb b/spec/unit/puppet/parser/functions/unique_spec.rb new file mode 100644 index 0000000..627dc33 --- /dev/null +++ b/spec/unit/puppet/parser/functions/unique_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should remove duplicate elements in a string" do + 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/puppet/parser/functions/upcase_spec.rb b/spec/unit/puppet/parser/functions/upcase_spec.rb new file mode 100644 index 0000000..5d18846 --- /dev/null +++ b/spec/unit/puppet/parser/functions/upcase_spec.rb @@ -0,0 +1,31 @@ +#!/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 + + it "should upcase a string" do + result = @scope.function_upcase(["abc"]) + result.should(eq('ABC')) + end + + it "should do nothing if a string is already upcase" do + result = @scope.function_upcase(["ABC"]) + result.should(eq('ABC')) + end + +end diff --git a/spec/unit/puppet/parser/functions/values_at_spec.rb b/spec/unit/puppet/parser/functions/values_at_spec.rb new file mode 100644 index 0000000..6c45316 --- /dev/null +++ b/spec/unit/puppet/parser/functions/values_at_spec.rb @@ -0,0 +1,45 @@ +#!/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 + + it "should raise a ParseError if you try to use a range where stop is greater then start" do + lambda { @scope.function_values_at([['a','b'],["3-1"]]) }.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 + + it "should return a value at from an array when passed a range" do + result = @scope.function_values_at([['a','b','c'],"0-1"]) + result.should(eq(['a','b'])) + end + + it "should return chosen values from an array when passed number of indexes" do + result = @scope.function_values_at([['a','b','c'],["0","2"]]) + result.should(eq(['a','c'])) + end + + it "should return chosen values from an array when passed ranges and multiple indexes" do + result = @scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]]) + result.should(eq(['a','c','e','f'])) + end + +end diff --git a/spec/unit/puppet/parser/functions/values_spec.rb b/spec/unit/puppet/parser/functions/values_spec.rb new file mode 100644 index 0000000..f6eb5b6 --- /dev/null +++ b/spec/unit/puppet/parser/functions/values_spec.rb @@ -0,0 +1,30 @@ +#!/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 + + 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 + + it "should return values from a hash" do + lambda { @scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError)) + end + +end diff --git a/spec/unit/puppet/parser/functions/zip_spec.rb b/spec/unit/puppet/parser/functions/zip_spec.rb new file mode 100644 index 0000000..074f4df --- /dev/null +++ b/spec/unit/puppet/parser/functions/zip_spec.rb @@ -0,0 +1,26 @@ +#!/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 + + 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