1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
4 describe 'zip function' do
6 it 'zips two arrays of numbers together' do
10 $output = zip($one,$two)
11 notice(inline_template('<%= @output.inspect %>'))
13 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\], \[3, 7\], \[4, 8\]\]/)
15 it 'zips two arrays of numbers & bools together' do
17 $one = [1,2,"three",4]
18 $two = [true,true,false,false]
19 $output = zip($one,$two)
20 notice(inline_template('<%= @output.inspect %>'))
22 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, true\], \[2, true\], \["three", false\], \[4, false\]\]/)
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:
32 $output = zip($one,$two,true)
33 notice(inline_template('<%= @output.inspect %>'))
35 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[1, 5, 2, 6, 3, 7, 4, 8\]/)
37 it 'handles unmatched length' do
38 # XXX Is this expected behavior?
42 $output = zip($one,$two)
43 notice(inline_template('<%= @output.inspect %>'))
45 expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/\[\[1, 5\], \[2, 6\]\]/)
49 it 'handles improper number of arguments' do
53 notice(inline_template('<%= @output.inspect %>'))
55 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Wrong number of arguments/)
57 it 'handles improper argument types' do
61 $output = zip($one,$two)
62 notice(inline_template('<%= @output.inspect %>'))
64 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Requires array/)