]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/flatten_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / flatten_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the flatten function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6   it "should exist" do
7     expect(Puppet::Parser::Functions.function("flatten")).to eq("function_flatten")
8   end
9
10   it "should raise a ParseError if there is less than 1 arguments" do
11     expect { scope.function_flatten([]) }.to( raise_error(Puppet::ParseError))
12   end
13
14   it "should raise a ParseError if there is more than 1 argument" do
15     expect { scope.function_flatten([[], []]) }.to( raise_error(Puppet::ParseError))
16   end
17
18   it "should flatten a complex data structure" do
19     result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
20     expect(result).to(eq(["a","b","c","d","e","f","g"]))
21   end
22
23   it "should do nothing to a structure that is already flat" do
24     result = scope.function_flatten([["a","b","c","d"]])
25     expect(result).to(eq(["a","b","c","d"]))
26   end
27 end