Note that exim contains tracker-specific configuration
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / join_keys_to_values_spec.rb
1 require 'spec_helper'
2
3 describe 'join_keys_to_values' do
4   it { is_expected.not_to eq(nil) }
5   it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Takes exactly two arguments}) }
6   it { is_expected.to run.with_params({}, '', '').and_raise_error(Puppet::ParseError, %r{Takes exactly two arguments}) }
7   it { is_expected.to run.with_params('one', '').and_raise_error(TypeError, %r{The first argument must be a hash}) }
8   it { is_expected.to run.with_params({}, 2).and_raise_error(TypeError, %r{The second argument must be a string}) }
9
10   it { is_expected.to run.with_params({}, '').and_return([]) }
11   it { is_expected.to run.with_params({}, ':').and_return([]) }
12   it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return(['keyvalue']) }
13   it { is_expected.to run.with_params({ 'key' => 'value' }, ':').and_return(['key:value']) }
14
15   context 'with UTF8 and double byte characters' do
16     it { is_expected.to run.with_params({ 'ҝẽγ' => '√ạĺűē' }, ':').and_return(['ҝẽγ:√ạĺűē']) }
17     it { is_expected.to run.with_params({ 'ҝẽγ' => '√ạĺűē' }, '万').and_return(['ҝẽγ万√ạĺűē']) }
18   end
19
20   if Puppet::Util::Package.versioncmp(Puppet.version, '5.5.7') == 0
21     it { is_expected.to run.with_params({ 'key' => '' }, ':').and_return(['key:']) }
22   else
23     it { is_expected.to run.with_params({ 'key' => nil }, ':').and_return(['key:']) }
24   end
25
26   it 'runs join_keys_to_values(<hash with multiple keys>, ":") and return the proper array' do
27     is_expected.to run.with_params({ 'key1' => 'value1', 'key2' => 'value2' }, ':').and_return(['key1:value1', 'key2:value2'])
28   end
29
30   it 'runs join_keys_to_values(<hash with array value>, " ") and return the proper array' do
31     expected_result = ['key1 value1', 'key2 value2', 'key2 value3']
32     is_expected.to run.with_params({ 'key1' => 'value1', 'key2' => ['value2', 'value3'] }, ' ').and_return(expected_result)
33   end
34 end