]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/concat_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / concat_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the concat function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should raise a ParseError if the client does not provide at least two arguments" do
8     expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError))
9     expect { scope.function_concat([[1]]) }.to(raise_error(Puppet::ParseError))
10   end
11
12   it "should raise a ParseError if the first parameter is not an array" do
13     expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError))
14   end
15
16   it "should not raise a ParseError if the client provides more than two arguments" do
17     expect { scope.function_concat([[1],[2],[3]]) }.not_to raise_error
18   end
19
20   it "should be able to concat an array" do
21     result = scope.function_concat([['1','2','3'],['4','5','6']])
22     expect(result).to(eq(['1','2','3','4','5','6']))
23   end
24
25   it "should be able to concat a primitive to an array" do
26     result = scope.function_concat([['1','2','3'],'4'])
27     expect(result).to(eq(['1','2','3','4']))
28   end
29
30   it "should not accidentally flatten nested arrays" do
31     result = scope.function_concat([['1','2','3'],[['4','5'],'6']])
32     expect(result).to(eq(['1','2','3',['4','5'],'6']))
33   end
34
35   it "should leave the original array intact" do
36     array_original = ['1','2','3']
37     result = scope.function_concat([array_original,['4','5','6']])
38     array_original.should(eq(['1','2','3']))
39   end
40
41   it "should be able to concat multiple arrays" do
42     result = scope.function_concat([['1','2','3'],['4','5','6'],['7','8','9']])
43     expect(result).to(eq(['1','2','3','4','5','6','7','8','9']))
44   end
45
46   it "should be able to concat mix of primitives and arrays to a final array" do
47     result = scope.function_concat([['1','2','3'],'4',['5','6','7']])
48     expect(result).to(eq(['1','2','3','4','5','6','7']))
49   end
50 end