]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Allow sort for strings.
authorKen Barber <ken@bob.sh>
Thu, 28 Jul 2011 23:10:31 +0000 (00:10 +0100)
committerKen Barber <ken@bob.sh>
Thu, 28 Jul 2011 23:10:31 +0000 (00:10 +0100)
lib/puppet/parser/functions/sort.rb
spec/unit/parser/functions/sort_spec.rb

index 54a40185198652957f007eddc3c905c95b6fc749..49ca20accb4076d457e0823649e2e60b4766a6d5 100644 (file)
@@ -12,7 +12,13 @@ module Puppet::Parser::Functions
         "given #{arguments.size} for 1")
     end
 
-    arguments[0].sort
+    value = arguments[0]
+
+    if value.is_a?(Array) then
+      value.sort
+    elsif value.is_a?(String) then
+      value.split("").sort.to_s
+    end
 
   end
 end
index da5db7a6c9f0f78d5620d9ccb6a89c38a90858e3..fbe3073f191e947fb7fd8b1a98f3d48995954e29 100644 (file)
@@ -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