File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
lib/puppet/parser/functions Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -13,22 +13,27 @@ module Puppet::Parser::Functions
1313Will return:
1414
1515 ASDF
16- EOS
16+ EOS
1717 ) do |arguments |
1818
1919 raise ( Puppet ::ParseError , "upcase(): Wrong number of arguments " +
20- "given (#{ arguments . size } for 1)" ) if arguments . size < 1
20+ "given (#{ arguments . size } for 1)" ) if arguments . size < 1
2121
2222 value = arguments [ 0 ]
2323
24- unless value . is_a? ( Array ) || value . is_a? ( String )
25- raise ( Puppet ::ParseError , 'upcase(): Requires either ' +
26- 'array or string to work with' )
24+ unless value . is_a? ( Array ) || value . is_a? ( String ) || value . is_a? ( Hash )
25+ raise ( Puppet ::ParseError , 'upcase(): Requires an ' +
26+ 'array, string or hash to work with' )
2727 end
2828
2929 if value . is_a? ( Array )
3030 # Numbers in Puppet are often string-encoded which is troublesome ...
3131 result = value . collect { |i | i . is_a? ( String ) ? i . upcase : i }
32+ elsif value . is_a? ( Hash )
33+ result = { }
34+ result << value . each_pair do |k , v |
35+ return { k . upcase => v . collect! { |p | p . upcase } }
36+ end
3237 else
3338 result = value . upcase
3439 end
Original file line number Diff line number Diff line change 99 end
1010
1111 it "should raise a ParseError if there is less than 1 arguments" do
12- expect { scope . function_upcase ( [ ] ) } . to ( raise_error ( Puppet ::ParseError ) )
12+ expect { scope . function_upcase ( [ ] ) } . to ( raise_error ( Puppet ::ParseError ) )
1313 end
1414
1515 it "should upcase a string" do
@@ -30,4 +30,10 @@ class AlsoString < String
3030 result = scope . function_upcase ( [ value ] )
3131 result . should ( eq ( 'ABC' ) )
3232 end
33+
34+ it 'should accept hashes and return uppercase' do
35+ expect (
36+ scope . function_upcase ( [ { 'test' => %w( this that and other thing ) } ] )
37+ ) . to eq ( { 'TEST' => %w( THIS THAT AND OTHER THING ) } )
38+ end
3339end
You can’t perform that action at this time.
0 commit comments