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, /wrong number of arguments/i) }
7 it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
9 pending("Current implementation ignores parameters after the first two.")
10 is_expected.to run.with_params([], 0, 1).and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
12 it { is_expected.to run.with_params('', 1).and_raise_error(Puppet::ParseError, /Requires array/i) }
13 it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /Requires array/i) }
14 it { is_expected.to run.with_params(true, 1).and_raise_error(Puppet::ParseError, /Requires array/i) }
15 it { is_expected.to run.with_params(1, 1).and_raise_error(Puppet::ParseError, /Requires array/i) }
16 it { is_expected.to run.with_params([0,1,2], 'two').and_raise_error(Puppet::ParseError, /Unknown format of given index/) }
17 it { is_expected.to run.with_params([0,1,2], []).and_raise_error(Puppet::ParseError, /provide at least one positive index/) }
18 it { is_expected.to run.with_params([0,1,2], '-1-1').and_raise_error(Puppet::ParseError, /Unknown format of given index/) }
19 it { is_expected.to run.with_params([0,1,2], '2-1').and_raise_error(Puppet::ParseError, /Stop index in given indices range is smaller than the start index/) }
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, /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, /index exceeds array size/) }
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(['の']) }
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, /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, /index exceeds array size/) }
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]) }
49 pending('fix this bounds check')
50 is_expected.to run.with_params([0, 1, 2], '0...3').and_return([0, 1, 2])