5 (Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0) ? :undef : nil
43 context 'with single values' do
45 is_expected.not_to be_nil
48 it 'requires two arguments' do
49 is_expected.to run.with_params.and_raise_error(ArgumentError)
52 it 'fails if the data is not a structure' do
53 is_expected.to run.with_params('test', []).and_raise_error(Puppet::Error)
56 it 'fails if the path is not an array' do
57 is_expected.to run.with_params({}, '').and_raise_error(Puppet::Error)
60 it 'returns the value if the value is string' do
61 is_expected.to run.with_params(data, ['d'], 'default').and_return('1')
64 it 'returns true if the value is true' do
65 is_expected.to run.with_params(data, ['b'], 'default').and_return(true)
68 it 'returns false if the value is false' do
69 is_expected.to run.with_params(data, ['c'], 'default').and_return(false)
72 it 'returns the default if the value is nil' do
73 is_expected.to run.with_params(data, ['f'], 'default').and_return('default')
76 it 'returns the default if the value is :undef (same as nil)' do
77 is_expected.to run.with_params(data, ['e'], 'default').and_return('default')
80 it 'returns the default if the path is not found' do
81 is_expected.to run.with_params(data, ['missing'], 'default').and_return('default')
85 context 'with structured values' do
86 it 'is able to extract a deeply nested hash value' do
87 is_expected.to run.with_params(data, ['a', 'g'], 'default').and_return('2')
90 it 'returns the default value if the path is too long' do
91 is_expected.to run.with_params(data, ['a', 'g', 'c', 'd'], 'default').and_return('default')
94 it 'supports an array index (number) in the path' do
95 is_expected.to run.with_params(data, ['a', 'e', 1], 'default').and_return('f1')
98 it 'supports an array index (string) in the path' do
99 is_expected.to run.with_params(data, ['a', 'e', '1'], 'default').and_return('f1')
102 it 'returns the default value if an array index is not a number' do
103 is_expected.to run.with_params(data, ['a', 'b', 'c'], 'default').and_return('default')
106 it 'returns the default value if and index is out of array length' do
107 is_expected.to run.with_params(data, ['a', 'e', '5'], 'default').and_return('default')
110 it 'is able to path though both arrays and hashes' do
111 is_expected.to run.with_params(data, ['a', 'e', '2', 'x', 'y'], 'default').and_return('z')
114 it 'returns "nil" if value is not found and no default value is provided' do
115 is_expected.to run.with_params(data, ['a', '1']).and_return(nil)
119 context 'with internationalization (i18N) values' do
120 it 'is able to return a unicode character' do
121 is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 0]).and_return('©')
124 it 'is able to return a utf8 character' do
125 is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 1]).and_return('ĝ')
128 it 'is able to return a double byte character' do
129 is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 2]).and_return('に')