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/unit/parser/functions') 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