36dbe70e64c2bd83e08d170c97226d8b2e85e34f
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / regexpescape_spec.rb
1 require 'spec_helper'
2
3 describe 'regexpescape' 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 {
8       pending("Current implementation ignores parameters after the first.")
9       is_expected.to run.with_params('', '').and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
10     }
11     it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
12     it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
13     it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
14   end
15
16   describe 'handling normal strings' do
17     it 'should call ruby\'s Regexp.escape function' do
18       Regexp.expects(:escape).with('regexp_string').returns('escaped_regexp_string').once
19       is_expected.to run.with_params('regexp_string').and_return('escaped_regexp_string')
20     end
21   end
22
23   describe 'handling classes derived from String' do
24     it 'should call ruby\'s Regexp.escape function' do
25       regexp_string = AlsoString.new('regexp_string')
26       Regexp.expects(:escape).with(regexp_string).returns('escaped_regexp_string').once
27       is_expected.to run.with_params(regexp_string).and_return("escaped_regexp_string")
28     end
29   end
30
31   describe 'strings in arrays handling' do
32     it { is_expected.to run.with_params([]).and_return([]) }
33     it { is_expected.to run.with_params(['one*', "two"]).and_return(['one\*', "two"]) }
34     it { is_expected.to run.with_params(['one*', 1, true, {}, "two"]).and_return(['one\*', 1, true, {}, "two"]) }
35
36     context 'should run with UTF8 and double byte characters' do
37       it { is_expected.to run.with_params(['ŏʼnε*']).and_return(['ŏʼnε\*']) }
38       it { is_expected.to run.with_params(['インターネット*']).and_return(['インターネット\*']) }
39     end
40   end
41 end