1 #! /usr/bin/env ruby -S rspec
4 describe "the flatten function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
7 expect(Puppet::Parser::Functions.function("flatten")).to eq("function_flatten")
10 it "should raise a ParseError if there is less than 1 arguments" do
11 expect { scope.function_flatten([]) }.to( raise_error(Puppet::ParseError))
14 it "should raise a ParseError if there is more than 1 argument" do
15 expect { scope.function_flatten([[], []]) }.to( raise_error(Puppet::ParseError))
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"]))
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"]))