1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
require 'spec_helper'
require 'puppet_spec/compiler'
require 'matchers/resource'
describe 'the chomp function' do
include PuppetSpec::Compiler
include Matchers::Resource
it 'removes line endings CR LF from a string' do
expect(compile_to_catalog("notify { String(\"abc\r\n\".chomp == 'abc'): }")).to have_resource('Notify[true]')
end
it 'removes line ending CR from a string' do
expect(compile_to_catalog("notify { String(\"abc\r\".chomp == 'abc'): }")).to have_resource('Notify[true]')
end
it 'removes line ending LF from a string' do
expect(compile_to_catalog("notify { String(\"abc\n\".chomp == 'abc'): }")).to have_resource('Notify[true]')
end
it 'does not removes LF before CR line ending from a string' do
expect(compile_to_catalog("notify { String(\"abc\n\r\".chomp == \"abc\n\"): }")).to have_resource('Notify[true]')
end
it 'returns empty string for an empty string' do
expect(compile_to_catalog("notify { String(''.chomp == ''): }")).to have_resource('Notify[true]')
end
it 'returns the value if Numeric' do
expect(compile_to_catalog("notify { String(42.chomp == 42): }")).to have_resource('Notify[true]')
end
it 'returns chomped version of each entry in an array' do
expect(compile_to_catalog("notify { String([\"a\n\", \"b\n\", \"c\n\"].chomp == ['a', 'b', 'c']): }")).to have_resource('Notify[true]')
end
it 'returns chopped version of each entry in an Iterator' do
expect(compile_to_catalog("notify { String([\"a\n\", \"b\n\", \"c\n\"].reverse_each.chomp == ['c', 'b', 'a']): }")).to have_resource('Notify[true]')
end
it 'errors when given a a nested Array' do
expect { compile_to_catalog("['a', 'b', ['c']].chomp")}.to raise_error(/'chomp' parameter 'arg' expects a value of type Numeric, String, or Iterable/)
end
end
|