d0f37de1d4fcbe3e212389751f0115a0bfb32ef0
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / uriescape_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the uriescape function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("uriescape")).to eq("function_uriescape")
9   end
10
11   it "should raise a ParseError if there is less than 1 arguments" do
12     expect { scope.function_uriescape([]) }.to( raise_error(Puppet::ParseError))
13   end
14
15   it "should uriescape a string" do
16     result = scope.function_uriescape([":/?#[]@!$&'()*+,;= \"{}"])
17     expect(result).to(eq(':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'))
18   end
19
20   it "should uriescape an array of strings, while not touching up nonstrings" do
21     teststring = ":/?#[]@!$&'()*+,;= \"{}"
22     expectstring = ':/?%23[]@!$&\'()*+,;=%20%22%7B%7D'
23     result = scope.function_uriescape([[teststring, teststring, 1]])
24     expect(result).to(eq([expectstring, expectstring, 1]))
25   end
26
27   it "should do nothing if a string is already safe" do
28     result = scope.function_uriescape(["ABCdef"])
29     expect(result).to(eq('ABCdef'))
30   end
31
32   it "should accept objects which extend String" do
33     class AlsoString < String
34     end
35
36     value = AlsoString.new('abc')
37     result = scope.function_uriescape([value])
38     result.should(eq('abc'))
39   end
40 end