1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
5 describe 'zip function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
7 it 'zips two arrays of numbers together' do
11 $output = zip($one,$two)
12 notice(inline_template('<%= @output.inspect %>'))
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\]\]/)
17 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\], \["3", "7"\], \["4", "8"\]\]/)
20 it 'zips two arrays of numbers & bools together' do
22 $one = [1,2,"three",4]
23 $two = [true,true,false,false]
24 $output = zip($one,$two)
25 notice(inline_template('<%= @output.inspect %>'))
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\]\]/)
30 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", true\], \["2", true\], \["three", false\], \["4", false\]\]/)
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:
41 $output = zip($one,$two,true)
42 notice(inline_template('<%= @output.inspect %>'))
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\]/)
47 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\["1", "5", "2", "6", "3", "7", "4", "8"\]/)
50 it 'handles unmatched length' do
51 # XXX Is this expected behavior?
55 $output = zip($one,$two)
56 notice(inline_template('<%= @output.inspect %>'))
58 if is_future_parser_enabled?
59 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\]\]/)
61 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\["1", "5"\], \["2", "6"\]\]/)
66 it 'handles improper number of arguments' do
70 notice(inline_template('<%= @output.inspect %>'))
73 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/)
75 it 'handles improper argument types' do
79 $output = zip($one,$two)
80 notice(inline_template('<%= @output.inspect %>'))
83 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires array/)