Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / squeeze_spec.rb
1 require 'spec_helper'
2
3 describe 'squeeze' 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}i) }
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(1).and_raise_error(NoMethodError) }
8   it { is_expected.to run.with_params({}).and_raise_error(NoMethodError) }
9   it { is_expected.to run.with_params(true).and_raise_error(NoMethodError) }
10
11   context 'when squeezing a single string' do
12     it { is_expected.to run.with_params('').and_return('') }
13     it { is_expected.to run.with_params('a').and_return('a') }
14     it { is_expected.to run.with_params('aaaaaaaaa').and_return('a') }
15     it { is_expected.to run.with_params('aaaaaaaaa', 'a').and_return('a') }
16     it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') }
17   end
18
19   context 'with UTF8 and double byte characters' do
20     it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậậậậ').and_return('ậ') }
21     it { is_expected.to run.with_params('語語語語語語語', '語').and_return('語') }
22     it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậ語語語語©©©©©', '©').and_return('ậậậậậậậậậậậậậậậậậ語語語語©') }
23   end
24
25   context 'when squeezing values in an array' do
26     it {
27       is_expected.to run \
28         .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc']) \
29         .and_return(['', 'a', 'a', 'abc'])
30     }
31     it {
32       is_expected.to run \
33         .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'a') \
34         .and_return(['', 'a', 'a', 'abbbbbbbbbbcccccccccc'])
35     }
36     it {
37       is_expected.to run \
38         .with_params(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabbbbbbbbbbcccccccccc'], 'b-c') \
39         .and_return(['', 'a', 'aaaaaaaaa', 'aaaaaaaaabc'])
40     }
41   end
42
43   context 'when using a class extending String' do
44     it 'calls its squeeze method' do
45       value = AlsoString.new('aaaaaaaaa')
46       expect_any_instance_of(AlsoString).to receive(:squeeze).and_return('foo') # rubocop:disable RSpec/AnyInstance
47       expect(subject).to run.with_params(value).and_return('foo')
48     end
49   end
50 end