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, /wrong number of arguments/i) }
|
---|
7 | it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /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, /wrong number of arguments/i)
|
---|
11 | }
|
---|
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/) }
|
---|
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, /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/) }
|
---|
31 | end
|
---|
32 |
|
---|
33 | context 'when requesting multiple items' do
|
---|
34 | it { is_expected.to run.with_params([0, 1, 2], [1, -1]).and_raise_error(Puppet::ParseError, /Unknown format of given index/) }
|
---|
35 | it { is_expected.to run.with_params([0, 1, 2], [0, 2]).and_return([0, 2]) }
|
---|
36 | it { is_expected.to run.with_params([0, 1, 2], ['0-2', 1, 2]).and_return([0, 1, 2, 1, 2]) }
|
---|
37 | it { is_expected.to run.with_params([0, 1, 2], [3, 2]).and_raise_error(Puppet::ParseError, /index exceeds array size/) }
|
---|
38 |
|
---|
39 | describe 'different range syntaxes' do
|
---|
40 | it { is_expected.to run.with_params([0, 1, 2], '0-2').and_return([0, 1, 2]) }
|
---|
41 | it { is_expected.to run.with_params([0, 1, 2], '0..2').and_return([0, 1, 2]) }
|
---|
42 | it { is_expected.to run.with_params([0, 1, 2], '0...2').and_return([0, 1]) }
|
---|
43 | it {
|
---|
44 | pending('fix this bounds check')
|
---|
45 | is_expected.to run.with_params([0, 1, 2], '0...3').and_return([0, 1, 2])
|
---|
46 | }
|
---|
47 | end
|
---|
48 | end
|
---|
49 | end
|
---|