Update stdlib
[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, /Takes exactly two arguments/) }
6   it { is_expected.to run.with_params({}, '', '').and_raise_error(Puppet::ParseError, /Takes exactly two arguments/) }
7   it { is_expected.to run.with_params('one', '').and_raise_error(TypeError, /The first argument must be a hash/) }
8   it { is_expected.to run.with_params({}, 2).and_raise_error(TypeError, /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 'should run 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   it { is_expected.to run.with_params({ 'key' => nil }, ':').and_return(['key:']) }
21   it 'should run join_keys_to_values(<hash with multiple keys>, ":") and return the proper array' do
22     result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }, ':'])
23     expect(result.sort).to eq(['key1:value1', 'key2:value2'].sort)
24   end
25   it 'should run join_keys_to_values(<hash with array value>, " ") and return the proper array' do
26     result = subject.call([{ 'key1' => 'value1', 'key2' => ['value2', 'value3'] }, ' '])
27     expect(result.sort).to eq(['key1 value1', 'key2 value2', 'key2 value3'].sort)
28   end
29 end
30