Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / delete_spec.rb
1 require 'spec_helper'
2
3 describe 'delete' do
4   it { is_expected.not_to eq(nil) }
5   it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
6   it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
7   it { is_expected.to run.with_params([], 'two') }
8   it { is_expected.to run.with_params([], 'two', 'three').and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) }
9   it { is_expected.to run.with_params(1, 'two').and_raise_error(TypeError, %r{First argument must be an Array, String, or Hash}) }
10
11   describe 'deleting from an array' do
12     it { is_expected.to run.with_params([], '').and_return([]) }
13     it { is_expected.to run.with_params([], 'two').and_return([]) }
14     it { is_expected.to run.with_params(['two'], 'two').and_return([]) }
15     it { is_expected.to run.with_params(['two', 'two'], 'two').and_return([]) }
16     it { is_expected.to run.with_params(['ab', 'b', 'c', 'b'], 'b').and_return(['ab', 'c']) }
17     it { is_expected.to run.with_params(['one', 'two', 'three'], 'four').and_return(['one', 'two', 'three']) }
18     it { is_expected.to run.with_params(['one', 'two', 'three'], 'e').and_return(['one', 'two', 'three']) }
19     it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
20     it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
21     it { is_expected.to run.with_params(['one', 'two', 'three', 'two'], ['one', 'two']).and_return(['three']) }
22     it { is_expected.to run.with_params(['ồאּẻ', 'ŧẅơ', 'ŧңŗё℮', 'ŧẅơ'], ['ồאּẻ', 'ŧẅơ']).and_return(['ŧңŗё℮']) }
23   end
24
25   describe 'deleting from a string' do
26     it { is_expected.to run.with_params('', '').and_return('') }
27     it { is_expected.to run.with_params('bar', '').and_return('bar') }
28     it { is_expected.to run.with_params('', 'bar').and_return('') }
29     it { is_expected.to run.with_params('bar', 'bar').and_return('') }
30     it { is_expected.to run.with_params('barbar', 'bar').and_return('') }
31     it { is_expected.to run.with_params('barfoobar', 'bar').and_return('foo') }
32     it { is_expected.to run.with_params('foobarbabarz', 'bar').and_return('foobaz') }
33     it { is_expected.to run.with_params('foobarbabarz', ['foo', 'bar']).and_return('baz') }
34     it { is_expected.to run.with_params('ƒōōβậяβậβậяź', ['ƒōō', 'βậя']).and_return('βậź') }
35
36     it { is_expected.to run.with_params('barfoobar', ['barbar', 'foo']).and_return('barbar') }
37     it { is_expected.to run.with_params('barfoobar', ['foo', 'barbar']).and_return('') }
38   end
39
40   describe 'deleting from an array' do
41     it { is_expected.to run.with_params({}, '').and_return({}) }
42     it { is_expected.to run.with_params({}, 'key').and_return({}) }
43     it { is_expected.to run.with_params({ 'key' => 'value' }, 'key').and_return({}) }
44     it {
45       is_expected.to run \
46         .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, 'key2') \
47         .and_return('key1' => 'value1', 'key3' => 'value3')
48     }
49     it {
50       is_expected.to run \
51         .with_params({ 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }, ['key1', 'key2']) \
52         .and_return('key3' => 'value3')
53     }
54     it {
55       is_expected.to run \
56         .with_params({ 'ĸəұ1' => 'νãŀủĕ1', 'ĸəұ2' => 'νãŀủĕ2', 'ĸəұ3' => 'νãŀủĕ3' }, ['ĸəұ1', 'ĸəұ2']) \
57         .and_return('ĸəұ3' => 'νãŀủĕ3')
58     }
59   end
60
61   it 'leaves the original array intact' do
62     argument1 = ['one', 'two', 'three']
63     original1 = argument1.dup
64     _result = subject.execute(argument1, 'two')
65     expect(argument1).to eq(original1)
66   end
67   it 'leaves the original string intact' do
68     argument1 = 'onetwothree'
69     original1 = argument1.dup
70     _result = subject.execute(argument1, 'two')
71     expect(argument1).to eq(original1)
72   end
73   it 'leaves the original hash intact' do
74     argument1 = { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }
75     original1 = argument1.dup
76     _result = subject.execute(argument1, 'key2')
77     expect(argument1).to eq(original1)
78   end
79 end