4673daaa68701aee902a15a6573912a32e545348
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / shuffle_spec.rb
1 require 'spec_helper'
2
3 describe 'shuffle' 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 {
7     pending("Current implementation ignores parameters after the first.")
8     is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
9   }
10   it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
11   it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
12   it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
13
14   context 'when running with a specific seed' do
15     # make tests deterministic
16     before(:each) { srand(2) }
17
18     it { is_expected.to run.with_params([]).and_return([]) }
19     it { is_expected.to run.with_params(['a']).and_return(['a']) }
20     it { is_expected.to run.with_params(['one']).and_return(['one']) }
21     it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(['two', 'one', 'three']) }
22     it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(['four', 'three', 'two', 'one']) }
23
24     it { is_expected.to run.with_params('').and_return('') }
25     it { is_expected.to run.with_params('a').and_return('a') }
26     it { is_expected.to run.with_params('abc').and_return('bac') }
27     it { is_expected.to run.with_params('abcd').and_return('dcba') }
28
29     context 'should run with UTF8 and double byte characters' do
30       it { is_expected.to run.with_params('ůţƒ8 ŧέχŧ şŧґíńģ').and_return('ģńş ůχţέƒŧí8ґŧŧ ') }
31       it { is_expected.to run.with_params('日本語の文字列').and_return('字本日語文列の') }
32     end
33
34     context 'when using a class extending String' do
35       it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return('lkhdsfajg') }
36     end
37   end
38 end