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