2012-07-20 00:27:52 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
2011-06-29 22:21:55 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe "the upcase function" do
|
2012-07-23 17:28:06 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
2011-06-29 22:21:55 +02:00
|
|
|
|
|
|
|
it "should exist" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(Puppet::Parser::Functions.function("upcase")).to eq("function_upcase")
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise a ParseError if there is less than 1 arguments" do
|
2015-02-25 20:39:27 +01:00
|
|
|
expect { scope.function_upcase([]) }.to(raise_error(Puppet::ParseError))
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2011-07-24 01:39:17 +02:00
|
|
|
it "should upcase a string" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_upcase(["abc"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(eq('ABC'))
|
2011-07-24 01:39:17 +02:00
|
|
|
end
|
|
|
|
|
2011-07-28 16:44:26 +02:00
|
|
|
it "should do nothing if a string is already upcase" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_upcase(["ABC"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(eq('ABC'))
|
2011-07-28 16:44:26 +02:00
|
|
|
end
|
2014-04-22 09:36:28 +02:00
|
|
|
|
|
|
|
it "should accept objects which extend String" do
|
|
|
|
class AlsoString < String
|
|
|
|
end
|
|
|
|
|
|
|
|
value = AlsoString.new('abc')
|
|
|
|
result = scope.function_upcase([value])
|
|
|
|
result.should(eq('ABC'))
|
|
|
|
end
|
2015-02-25 20:39:27 +01:00
|
|
|
|
|
|
|
it 'should accept hashes and return uppercase' do
|
|
|
|
expect(
|
|
|
|
scope.function_upcase([{'test' => %w(this that and other thing)}])
|
|
|
|
).to eq({'TEST' => %w(THIS THAT AND OTHER THING)})
|
|
|
|
end
|
2015-02-28 02:40:32 +01:00
|
|
|
|
|
|
|
if :test.respond_to?(:upcase)
|
|
|
|
it 'should accept hashes of symbols' do
|
|
|
|
expect(
|
|
|
|
scope.function_upcase([{:test => [:this, :that, :other]}])
|
|
|
|
).to eq({:TEST => [:THIS, :THAT, :OTHER]})
|
|
|
|
end
|
|
|
|
it 'should return upcase symbol' do
|
|
|
|
expect(
|
|
|
|
scope.function_upcase([:test])
|
|
|
|
).to eq(:TEST)
|
|
|
|
end
|
|
|
|
it 'should return mixed objects in upcease' do
|
|
|
|
expect(
|
|
|
|
scope.function_upcase([[:test, 'woot']])
|
|
|
|
).to eq([:TEST, 'WOOT'])
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|