]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(#1) provide some more detailed tests for a number of functions.
authorKen Barber <ken@bob.sh>
Fri, 29 Jul 2011 19:57:10 +0000 (20:57 +0100)
committerKen Barber <ken@bob.sh>
Fri, 29 Jul 2011 19:57:10 +0000 (20:57 +0100)
spec/unit/parser/functions/abs_spec.rb
spec/unit/parser/functions/downcase_spec.rb
spec/unit/parser/functions/empty_spec.rb
spec/unit/parser/functions/flatten_spec.rb
spec/unit/parser/functions/is_array_spec.rb
spec/unit/parser/functions/is_float_spec.rb
spec/unit/parser/functions/num2bool_spec.rb
spec/unit/parser/functions/shuffle_spec.rb
spec/unit/parser/functions/strftime_spec.rb
spec/unit/parser/functions/time_spec.rb
spec/unit/parser/functions/type_spec.rb

index 6bf0b41e4c4acd30d43b14514aaaf0a755ad5840..65ba2e8cc7b6606348798e0b890dd88e534e0f9c 100755 (executable)
@@ -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
index 0d53220d6c8ea8e9f200d0c01560ea17357e263f..0bccd5f12955ff9e6b8093d93a32cf3c79f5e667 100755 (executable)
@@ -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
index 6c0fe695594d5ed91f7f0610a2de6de03de9608d..cb0021f74f057ac6eeba84c7893e9e6b9c387d0e 100755 (executable)
@@ -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
index 91cf4ef7ae5808f8a8250443376d22d66419ea23..7bedeb2367106a3aaa986746c522bd30ac960ad1 100755 (executable)
@@ -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
index 15b563c9e1a27cdee2273a32d6a332ac8cfa894c..537595c0765bb0e8493d9a01d95b036204ffc8fe 100644 (file)
@@ -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
index 35c0dd6af836d6557403a4020bb00a4c8e43d908..55ba8cfc04aacc69c2df51dd0e3f17ced7d06358 100644 (file)
@@ -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
index 2f6435d1824604c0740523c73274d5e6d9986704..6585273c41301fe82d288553afe6debd2292a5f1 100644 (file)
@@ -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
index cf063c67c481f2365ddcd45e6cb4af07c6e5ade4..936c2fdba1a6e7c13f57e01083a59456e403ef72 100644 (file)
@@ -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
index e3779547369a09cb8fe1ee7a6555c130490c3f61..f7a2cd9b5a558cf9a3c6bcd2bbc44322a8a31c08 100644 (file)
@@ -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
index 8bf5982eece68b0b7661573436d867e036390027..666e8e0fe6ced64d0574815219e3d828f21ffce2 100644 (file)
@@ -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
index fddb87df05674501136f819c043c19bcdb50ec47..36c382364b1bff8e8dd43d718f431e49e0ec61be 100644 (file)
@@ -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