]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/acceptance/zip_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / zip_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
3 require 'puppet'
4
5 describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
6   describe 'success' do
7     it 'zips two arrays of numbers together' do
8       pp = <<-EOS
9       $one = [1,2,3,4]
10       $two = [5,6,7,8]
11       $output = zip($one,$two)
12       notice(inline_template('<%= @output.inspect %>'))
13       EOS
14       if is_future_parser_enabled?
15         expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\], \[3, 7\], \[4, 8\]\]/)
16       else
17         expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/)
18       end
19     end
20     it 'zips two arrays of numbers & bools together' do
21       pp = <<-EOS
22       $one = [1,2,"three",4]
23       $two = [true,true,false,false]
24       $output = zip($one,$two)
25       notice(inline_template('<%= @output.inspect %>'))
26       EOS
27       if is_future_parser_enabled?
28         expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, true\], \[2, true\], \["three", false\], \[4, false\]\]/)
29       else
30         expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/)
31       end
32     end
33     it 'zips two arrays of numbers together and flattens them' do
34       # XXX This only tests the argument `true`, even though the following are valid:
35       # 1 t y true yes
36       # 0 f n false no
37       # undef undefined
38       pp = <<-EOS
39       $one = [1,2,3,4]
40       $two = [5,6,7,8]
41       $output = zip($one,$two,true)
42       notice(inline_template('<%= @output.inspect %>'))
43       EOS
44       if is_future_parser_enabled?
45         expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 5, 2, 6, 3, 7, 4, 8\]/)
46       else
47         expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/)
48       end
49     end
50     it 'handles unmatched length' do
51       # XXX Is this expected behavior?
52       pp = <<-EOS
53       $one = [1,2]
54       $two = [5,6,7,8]
55       $output = zip($one,$two)
56       notice(inline_template('<%= @output.inspect %>'))
57       EOS
58       if is_future_parser_enabled?
59         expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\]\]/)
60       else
61         expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/)
62       end
63     end
64   end
65   describe 'failure' do
66     it 'handles improper number of arguments' do
67       pp = <<-EOS
68       $one = [1,2]
69       $output = zip($one)
70       notice(inline_template('<%= @output.inspect %>'))
71       EOS
72
73       expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/)
74     end
75     it 'handles improper argument types' do
76       pp = <<-EOS
77       $one = "a string"
78       $two = [5,6,7,8]
79       $output = zip($one,$two)
80       notice(inline_template('<%= @output.inspect %>'))
81       EOS
82
83       expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires array/)
84     end
85   end
86 end