Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / values_at_spec.rb
1 require 'spec_helper'
2
3 describe 'values_at' do
4   describe 'signature validation' do
5     it { is_expected.not_to eq(nil) }
6     it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
7     it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
8     it {
9       pending('Current implementation ignores parameters after the first two.')
10       is_expected.to run.with_params([], 0, 1).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i)
11     }
12     it { is_expected.to run.with_params('', 1).and_raise_error(Puppet::ParseError, %r{Requires array}i) }
13     it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, %r{Requires array}i) }
14     it { is_expected.to run.with_params(true, 1).and_raise_error(Puppet::ParseError, %r{Requires array}i) }
15     it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError, %r{Requires array}i) }
16     it { is_expected.to run.with_params([0, 1, 2], 'two').and_raise_error(Puppet::ParseError, %r{Unknown format of given index}) }
17     it { is_expected.to run.with_params([0, 1, 2], []).and_raise_error(Puppet::ParseError, %r{provide at least one positive index}) }
18     it { is_expected.to run.with_params([0, 1, 2], '-1-1').and_raise_error(Puppet::ParseError, %r{Unknown format of given index}) }
19     it { is_expected.to run.with_params([0, 1, 2], '2-1').and_raise_error(Puppet::ParseError, %r{Stop index in given indices range is smaller than the start index}) }
20   end
21
22   context 'when requesting a single item' do
23     it { is_expected.to run.with_params([0, 1, 2], -1).and_raise_error(Puppet::ParseError, %r{Unknown format of given index}) }
24     it { is_expected.to run.with_params([0, 1, 2], 0).and_return([0]) }
25     it { is_expected.to run.with_params([0, 1, 2], 1).and_return([1]) }
26     it { is_expected.to run.with_params([0, 1, 2], [1]).and_return([1]) }
27     it { is_expected.to run.with_params([0, 1, 2], '1').and_return([1]) }
28     it { is_expected.to run.with_params([0, 1, 2], '1-1').and_return([1]) }
29     it { is_expected.to run.with_params([0, 1, 2], 2).and_return([2]) }
30     it { is_expected.to run.with_params([0, 1, 2], 3).and_raise_error(Puppet::ParseError, %r{index exceeds array size}) }
31   end
32
33   context 'when requesting a single item using UTF8 and double byte characters' do
34     it { is_expected.to run.with_params(['ẩ', 'β', 'с', 'ď'], 0).and_return(['ẩ']) }
35     it { is_expected.to run.with_params(['文', '字', 'の', '値'], 2).and_return(['の']) }
36   end
37
38   context 'when requesting multiple items' do
39     it { is_expected.to run.with_params([0, 1, 2], [1, -1]).and_raise_error(Puppet::ParseError, %r{Unknown format of given index}) }
40     it { is_expected.to run.with_params([0, 1, 2], [0, 2]).and_return([0, 2]) }
41     it { is_expected.to run.with_params([0, 1, 2], ['0-2', 1, 2]).and_return([0, 1, 2, 1, 2]) }
42     it { is_expected.to run.with_params([0, 1, 2], [3, 2]).and_raise_error(Puppet::ParseError, %r{index exceeds array size}) }
43
44     describe 'different range syntaxes' do
45       it { is_expected.to run.with_params([0, 1, 2], '0-2').and_return([0, 1, 2]) }
46       it { is_expected.to run.with_params([0, 1, 2], '0..2').and_return([0, 1, 2]) }
47       it { is_expected.to run.with_params([0, 1, 2], '0...2').and_return([0, 1]) }
48       it {
49         pending('fix this bounds check')
50         is_expected.to run.with_params([0, 1, 2], '0...3').and_return([0, 1, 2])
51       }
52     end
53   end
54 end