File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
lib/puppet/functions/stdlib Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ # @summary
2
+ # Return true if test_string ends with suffux
3
+ #
4
+ # @example
5
+ # 'foobar'.stdlib::end_with('bar') => true
6
+ # 'foobar'.stdlib::end_with('foo') => false
7
+ Puppet ::Functions . create_function ( :'stdlib::end_with' ) do
8
+ # @param test_string the string to check
9
+ # @param suffix the suffix to check
10
+ #
11
+ # @return [Boolean] True or False
12
+ dispatch :end_with do
13
+ param 'String[1]' , :test_string
14
+ param 'String[1]' , :suffix
15
+ return_type 'Boolean'
16
+ end
17
+
18
+ def end_with ( test_string , suffix )
19
+ test_string . end_with? ( suffix )
20
+ end
21
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe 'stdlib::end_with' do
4
+ it { is_expected . to run . with_params ( 'foobar' , 'bar' ) . and_return ( true ) }
5
+ it { is_expected . to run . with_params ( 'foobar' , 'foo' ) . and_return ( false ) }
6
+ it do
7
+ is_expected . to run . with_params ( '' , 'foo' ) . and_raise_error (
8
+ ArgumentError , %r{'stdlib::end_with' parameter 'test_string' expects a String\[ 1\] }
9
+ )
10
+ end
11
+ it do
12
+ is_expected . to run . with_params ( 'foobar' , '' ) . and_raise_error (
13
+ ArgumentError , %r{'stdlib::end_with' parameter 'suffix' expects a String\[ 1\] }
14
+ )
15
+ end
16
+ end
You can’t perform that action at this time.
0 commit comments