b267d9ad52c74e417fa855ede42ebdbaf5b938b6
[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, /wrong number of arguments/i) }
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(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 'should run 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 'should call its squeeze method' do
45       value = AlsoString.new('aaaaaaaaa')
46       value.expects(:squeeze).returns('foo')
47       expect(subject).to run.with_params(value).and_return('foo')
48     end
49   end
50 end