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
13
13
Will return:
14
14
15
15
ASDF
16
- EOS
16
+ EOS
17
17
) do |arguments |
18
18
19
19
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
21
21
22
22
value = arguments [ 0 ]
23
23
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' )
27
27
end
28
28
29
29
if value . is_a? ( Array )
30
30
# Numbers in Puppet are often string-encoded which is troublesome ...
31
31
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
32
37
else
33
38
result = value . upcase
34
39
end
Original file line number Diff line number Diff line change 9
9
end
10
10
11
11
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 ) )
13
13
end
14
14
15
15
it "should upcase a string" do
@@ -30,4 +30,10 @@ class AlsoString < String
30
30
result = scope . function_upcase ( [ value ] )
31
31
result . should ( eq ( 'ABC' ) )
32
32
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
33
39
end
You can’t perform that action at this time.
0 commit comments