summaryrefslogtreecommitdiff
path: root/spec/functions
diff options
context:
space:
mode:
Diffstat (limited to 'spec/functions')
-rwxr-xr-xspec/functions/any2array_spec.rb6
-rwxr-xr-xspec/functions/basename_spec.rb5
-rwxr-xr-xspec/functions/chomp_spec.rb5
-rwxr-xr-xspec/functions/chop_spec.rb5
-rwxr-xr-xspec/functions/concat_spec.rb4
-rwxr-xr-xspec/functions/count_spec.rb5
-rwxr-xr-xspec/functions/deep_merge_spec.rb6
-rwxr-xr-xspec/functions/defined_with_params_spec.rb33
-rwxr-xr-xspec/functions/delete_at_spec.rb2
-rwxr-xr-xspec/functions/delete_spec.rb8
-rwxr-xr-xspec/functions/delete_undef_values_spec.rb1
-rwxr-xr-xspec/functions/delete_values_spec.rb6
-rw-r--r--spec/functions/deprecation_spec.rb4
-rwxr-xr-xspec/functions/difference_spec.rb2
-rw-r--r--spec/functions/dig44_spec.rb26
-rwxr-xr-xspec/functions/dirname_spec.rb5
-rw-r--r--spec/functions/dos2unix_spec.rb17
-rwxr-xr-xspec/functions/ensure_packages_spec.rb27
-rwxr-xr-xspec/functions/ensure_resource_spec.rb44
-rw-r--r--spec/functions/ensure_resources_spec.rb25
-rwxr-xr-xspec/functions/flatten_spec.rb1
-rw-r--r--spec/functions/fqdn_rand_string_spec.rb1
-rwxr-xr-xspec/functions/fqdn_rotate_spec.rb1
-rw-r--r--spec/functions/fqdn_uuid_spec.rb1
-rwxr-xr-xspec/functions/getparam_spec.rb8
-rwxr-xr-xspec/functions/getvar_spec.rb15
-rwxr-xr-xspec/functions/glob_spec.rb11
-rwxr-xr-xspec/functions/grep_spec.rb1
-rwxr-xr-xspec/functions/has_ip_network_spec.rb1
-rwxr-xr-xspec/functions/has_key_spec.rb5
-rwxr-xr-xspec/functions/hash_spec.rb1
-rwxr-xr-xspec/functions/intersection_spec.rb1
-rw-r--r--spec/functions/is_a_spec.rb5
-rwxr-xr-xspec/functions/is_function_available_spec.rb (renamed from spec/functions/is_function_available.rb)0
-rwxr-xr-xspec/functions/is_integer_spec.rb3
-rwxr-xr-xspec/functions/is_mac_address_spec.rb6
-rwxr-xr-xspec/functions/join_keys_to_values_spec.rb7
-rwxr-xr-xspec/functions/join_spec.rb1
-rwxr-xr-xspec/functions/keys_spec.rb5
-rwxr-xr-xspec/functions/length_spec.rb31
-rwxr-xr-xspec/functions/load_module_metadata_spec.rb47
-rw-r--r--spec/functions/loadjson_spec.rb37
-rwxr-xr-xspec/functions/loadyaml_spec.rb4
-rwxr-xr-xspec/functions/lstrip_spec.rb1
-rwxr-xr-xspec/functions/member_spec.rb2
-rwxr-xr-xspec/functions/merge_spec.rb2
-rwxr-xr-xspec/functions/parsejson_spec.rb11
-rwxr-xr-xspec/functions/parseyaml_spec.rb11
-rwxr-xr-xspec/functions/pick_default_spec.rb2
-rwxr-xr-xspec/functions/pick_spec.rb5
-rwxr-xr-xspec/functions/prefix_spec.rb1
-rw-r--r--spec/functions/pw_hash_spec.rb8
-rwxr-xr-xspec/functions/range_spec.rb8
-rw-r--r--spec/functions/regexpescape_spec.rb5
-rwxr-xr-xspec/functions/reject_spec.rb1
-rwxr-xr-xspec/functions/reverse_spec.rb2
-rwxr-xr-xspec/functions/round_spec.rb14
-rwxr-xr-xspec/functions/rstrip_spec.rb1
-rw-r--r--spec/functions/seeded_rand_spec.rb5
-rw-r--r--spec/functions/shell_escape_spec.rb5
-rw-r--r--spec/functions/shell_join_spec.rb5
-rw-r--r--spec/functions/shell_split_spec.rb5
-rwxr-xr-xspec/functions/shuffle_spec.rb5
-rwxr-xr-xspec/functions/size_spec.rb3
-rwxr-xr-xspec/functions/squeeze_spec.rb6
-rwxr-xr-xspec/functions/strftime_spec.rb4
-rwxr-xr-xspec/functions/strip_spec.rb1
-rwxr-xr-xspec/functions/suffix_spec.rb2
-rwxr-xr-xspec/functions/to_json_pretty_spec.rb11
-rwxr-xr-xspec/functions/to_json_spec.rb19
-rwxr-xr-xspec/functions/to_yaml_spec.rb17
-rwxr-xr-xspec/functions/union_spec.rb1
-rwxr-xr-xspec/functions/unique_spec.rb44
-rwxr-xr-xspec/functions/validate_cmd_spec.rb2
-rw-r--r--spec/functions/validate_domain_name_spec.rb35
-rwxr-xr-xspec/functions/validate_ipv6_address_spec.rb10
-rw-r--r--spec/functions/validate_legacy_spec.rb2
-rwxr-xr-xspec/functions/values_at_spec.rb5
-rwxr-xr-xspec/functions/values_spec.rb5
-rwxr-xr-xspec/functions/zip_spec.rb6
80 files changed, 634 insertions, 67 deletions
diff --git a/spec/functions/any2array_spec.rb b/spec/functions/any2array_spec.rb
index 70121f1..631657f 100755
--- a/spec/functions/any2array_spec.rb
+++ b/spec/functions/any2array_spec.rb
@@ -12,4 +12,10 @@ describe "any2array" do
it { is_expected.to run.with_params({}).and_return([]) }
it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key', 'value']) }
it { is_expected.to run.with_params({ 'key' => 'value' }).and_return(['key', 'value']) }
+
+ it { is_expected.to run.with_params('‰').and_return(['‰']) }
+ it { is_expected.to run.with_params('竹').and_return(['竹']) }
+ it { is_expected.to run.with_params('Ü').and_return(['Ü']) }
+ it { is_expected.to run.with_params('∇').and_return(['∇']) }
+ it { is_expected.to run.with_params('€', '万', 'Ö', '♥', '割').and_return(['€', '万', 'Ö', '♥', '割']) }
end
diff --git a/spec/functions/basename_spec.rb b/spec/functions/basename_spec.rb
index c84e192..3e02b01 100755
--- a/spec/functions/basename_spec.rb
+++ b/spec/functions/basename_spec.rb
@@ -11,4 +11,9 @@ describe 'basename' do
it { is_expected.to run.with_params('/path/to/a/file.ext', '.ext').and_return('file') }
it { is_expected.to run.with_params('relative_path/to/a/file.ext', '.ext').and_return('file') }
it { is_expected.to run.with_params('scheme:///path/to/a/file.ext').and_return('file.ext') }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('scheme:///√ạĺűē/竹.ext').and_return('竹.ext') }
+ it { is_expected.to run.with_params('ҝẽγ:/√ạĺűē/竹.ㄘ', '.ㄘ').and_return('竹') }
+ end
end
diff --git a/spec/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb
index 6878742..56bd9b1 100755
--- a/spec/functions/chomp_spec.rb
+++ b/spec/functions/chomp_spec.rb
@@ -17,4 +17,9 @@ describe 'chomp' do
it { is_expected.to run.with_params(AlsoString.new("one\n")).and_return("one") }
it { is_expected.to run.with_params(AlsoString.new("one\n\n")).and_return("one\n") }
it { is_expected.to run.with_params([AlsoString.new("one\n"), AlsoString.new("two"), "three\n"]).and_return(["one", "two", "three"]) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params("ůťƒ8\n\n").and_return("ůťƒ8\n") }
+ it { is_expected.to run.with_params("ネット\n\n").and_return("ネット\n") }
+ end
end
diff --git a/spec/functions/chop_spec.rb b/spec/functions/chop_spec.rb
index db7d18b..b70fc37 100755
--- a/spec/functions/chop_spec.rb
+++ b/spec/functions/chop_spec.rb
@@ -17,4 +17,9 @@ describe 'chop' do
it { is_expected.to run.with_params(AlsoString.new("one\n")).and_return("one") }
it { is_expected.to run.with_params(AlsoString.new("one\n\n")).and_return("one\n") }
it { is_expected.to run.with_params([AlsoString.new("one\n"), AlsoString.new("two"), "three\n"]).and_return(["one", "tw", "three"]) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params("ůťƒ8\n\n").and_return("ůťƒ8\n") }
+ it { is_expected.to run.with_params("ネット\n\n").and_return("ネット\n") }
+ end
end
diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb
index eb76233..6ab1b6e 100755
--- a/spec/functions/concat_spec.rb
+++ b/spec/functions/concat_spec.rb
@@ -11,7 +11,11 @@ describe 'concat' do
it { is_expected.to run.with_params(['1','2','3'],[['4','5'],'6']).and_return(['1','2','3',['4','5'],'6']) }
it { is_expected.to run.with_params(['1','2'],['3','4'],['5','6']).and_return(['1','2','3','4','5','6']) }
it { is_expected.to run.with_params(['1','2'],'3','4',['5','6']).and_return(['1','2','3','4','5','6']) }
+
+context 'should run with UTF8 and double byte characters' do
it { is_expected.to run.with_params([{"a" => "b"}], {"c" => "d", "e" => "f"}).and_return([{"a" => "b"}, {"c" => "d", "e" => "f"}]) }
+ it { is_expected.to run.with_params(['ấ','β','©'],['đ','ể','文字列']).and_return(['ấ','β','©','đ','ể','文字列']) }
+end
it "should leave the original array intact" do
argument1 = ['1','2','3']
diff --git a/spec/functions/count_spec.rb b/spec/functions/count_spec.rb
index c8d1960..3854cb8 100755
--- a/spec/functions/count_spec.rb
+++ b/spec/functions/count_spec.rb
@@ -15,4 +15,9 @@ describe 'count' do
it { is_expected.to run.with_params(["one", nil, "two"]).and_return(2) }
it { is_expected.to run.with_params(["one", "", "two"]).and_return(2) }
it { is_expected.to run.with_params(["one", :undef, "two"]).and_return(2) }
+
+ it { is_expected.to run.with_params(["ổņ℮", "ŧщộ", "three"]).and_return(3) }
+ it { is_expected.to run.with_params(["ổņ℮", "ŧщộ", "ŧщộ"], "ŧщộ").and_return(2) }
+ it { is_expected.to run.with_params(["ổņ℮", nil, "ŧщộ"]).and_return(2) }
+ it { is_expected.to run.with_params(["ổņ℮", :undef, "ŧщộ"]).and_return(2) }
end
diff --git a/spec/functions/deep_merge_spec.rb b/spec/functions/deep_merge_spec.rb
index 397e048..819e025 100755
--- a/spec/functions/deep_merge_spec.rb
+++ b/spec/functions/deep_merge_spec.rb
@@ -4,7 +4,7 @@ describe 'deep_merge' do
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it { is_expected.to run.with_params({ 'key' => 'value' }).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it { is_expected.to run.with_params({}, '2').and_raise_error(Puppet::ParseError, /unexpected argument type String/) }
- it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) }
+ it { is_expected.to run.with_params({}, 2).and_raise_error(Puppet::ParseError, /unexpected argument/) }
it { is_expected.to run.with_params({}, '').and_return({}) }
it { is_expected.to run.with_params({}, {}).and_return({}) }
it { is_expected.to run.with_params({}, {}, {}).and_return({}) }
@@ -52,4 +52,8 @@ describe 'deep_merge' do
expect(argument1).to eq(original1)
expect(argument2).to eq(original2)
end
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params({'ĸέỹ1' => 'ϋǻļủë1'}, {'この文字列' => '万' }).and_return({'ĸέỹ1' => 'ϋǻļủë1', 'この文字列' => '万'}) }
+ end
end
diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb
index e2f3abe..491a03b 100755
--- a/spec/functions/defined_with_params_spec.rb
+++ b/spec/functions/defined_with_params_spec.rb
@@ -11,6 +11,11 @@ describe 'defined_with_params' do
it { is_expected.to run.with_params('User[dan]', {}).and_return(true) }
it { is_expected.to run.with_params('User[bob]', {}).and_return(false) }
it { is_expected.to run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('User[ĵĭмოү]', {}).and_return(false) }
+ it { is_expected.to run.with_params('User[ポーラ]', {}).and_return(false) }
+ end
end
describe 'when compared against a resource with attributes' do
@@ -32,4 +37,32 @@ describe 'defined_with_params' do
it { is_expected.to run.with_params('File[/tmp/a]', {}).and_return(true) }
it { is_expected.to run.with_params('File[/tmp/a]', { 'ensure' => 'present', 'owner' => :undef }).and_return(true) }
end
+
+ describe 'when the reference is a' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+ context 'reference' do
+ it { is_expected.to run.with_params(Puppet::Resource.new('User[dan]'), {}).and_return(true) }
+ end
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
+ context 'array' do
+ it 'fails' do
+ expect {
+ subject.call([['User[dan]'], {}])
+ }.to raise_error ArgumentError, /not understood: 'Array'/
+ end
+ end
+ end
+ end
+
+ describe 'when passed a defined type' do
+ let :pre_condition do
+ 'test::deftype { "foo": }'
+ end
+ it { is_expected.to run.with_params('Test::Deftype[foo]', {}).and_return(true) }
+ it { is_expected.to run.with_params('Test::Deftype[bar]', {}).and_return(false) }
+ it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[foo]'), {}).and_return(true) }
+ it { is_expected.to run.with_params(Puppet::Resource.new('Test::Deftype[bar]'), {}).and_return(false) }
+ end
end
diff --git a/spec/functions/delete_at_spec.rb b/spec/functions/delete_at_spec.rb
index 0e19472..0471039 100755
--- a/spec/functions/delete_at_spec.rb
+++ b/spec/functions/delete_at_spec.rb
@@ -18,6 +18,8 @@ describe 'delete_at' do
it { is_expected.to run.with_params([0, 1, 2], 1).and_return([0, 2]) }
it { is_expected.to run.with_params([0, 1, 2], -1).and_return([0, 1]) }
it { is_expected.to run.with_params([0, 1, 2], -4).and_return([0, 1, 2]) }
+ it { is_expected.to run.with_params(["ƒờở", "βāř", "ьầż"], 1).and_return(["ƒờở", "ьầż"]) }
+
it "should leave the original array intact" do
argument = [1, 2, 3]
diff --git a/spec/functions/delete_spec.rb b/spec/functions/delete_spec.rb
index b44accf..4e37865 100755
--- a/spec/functions/delete_spec.rb
+++ b/spec/functions/delete_spec.rb
@@ -19,6 +19,7 @@ describe 'delete' do
it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
it { is_expected.to run.with_params(['two', 'one', 'two', 'three', 'two'], 'two').and_return(['one', 'three']) }
it { is_expected.to run.with_params(['one', 'two', 'three', 'two'], ['one', 'two']).and_return(['three']) }
+ it { is_expected.to run.with_params(['ồאּẻ', 'ŧẅơ', 'ŧңŗё℮', 'ŧẅơ'], ['ồאּẻ', 'ŧẅơ']).and_return(['ŧңŗё℮']) }
end
describe 'deleting from a string' do
@@ -30,7 +31,8 @@ describe 'delete' do
it { is_expected.to run.with_params('barfoobar', 'bar').and_return('foo') }
it { is_expected.to run.with_params('foobarbabarz', 'bar').and_return('foobaz') }
it { is_expected.to run.with_params('foobarbabarz', ['foo', 'bar']).and_return('baz') }
- # this is so sick
+ it { is_expected.to run.with_params('ƒōōβậяβậβậяź', ['ƒōō', 'βậя']).and_return('βậź') }
+
it { is_expected.to run.with_params('barfoobar', ['barbar', 'foo']).and_return('barbar') }
it { is_expected.to run.with_params('barfoobar', ['foo', 'barbar']).and_return('') }
end
@@ -47,6 +49,10 @@ describe 'delete' do
.with_params({'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'}, ['key1', 'key2']) \
.and_return( {'key3' => 'value3'})
}
+ it { is_expected.to run \
+ .with_params({'ĸəұ1' => 'νãŀủĕ1', 'ĸəұ2' => 'νãŀủĕ2', 'ĸəұ3' => 'νãŀủĕ3'}, ['ĸəұ1', 'ĸəұ2']) \
+ .and_return( {'ĸəұ3' => 'νãŀủĕ3'})
+ }
end
it "should leave the original array intact" do
diff --git a/spec/functions/delete_undef_values_spec.rb b/spec/functions/delete_undef_values_spec.rb
index ec9fb9c..c20cee2 100755
--- a/spec/functions/delete_undef_values_spec.rb
+++ b/spec/functions/delete_undef_values_spec.rb
@@ -16,6 +16,7 @@ describe 'delete_undef_values' do
end
it { is_expected.to run.with_params([undef_value]).and_return([]) }
it { is_expected.to run.with_params(['one',undef_value,'two','three']).and_return(['one','two','three']) }
+ it { is_expected.to run.with_params(['ớņέ',undef_value,'ŧשּׁō','ŧħґëə']).and_return(['ớņέ','ŧשּׁō','ŧħґëə']) }
end
it "should leave the original argument intact" do
diff --git a/spec/functions/delete_values_spec.rb b/spec/functions/delete_values_spec.rb
index 12907d4..329fa0b 100755
--- a/spec/functions/delete_values_spec.rb
+++ b/spec/functions/delete_values_spec.rb
@@ -19,7 +19,11 @@ describe 'delete_values' do
.and_return({'key1' => 'value1'})
}
it { is_expected.to run \
- .with_params({'key1' => 'value1', 'key2' => 'value to delete'}, 'value to delete') \
+ .with_params({'ҝếỵ1 ' => 'νâĺūẹ1', 'ҝếỵ2' => 'value to delete'}, 'value to delete') \
+ .and_return({'ҝếỵ1 ' => 'νâĺūẹ1'})
+ }
+ it { is_expected.to run \
+ .with_params({'key1' => 'value1', 'key2' => 'νǎŀữ℮ ťớ đêłểťė'}, 'νǎŀữ℮ ťớ đêłểťė') \
.and_return({'key1' => 'value1'})
}
it { is_expected.to run \
diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb
index cee4f1c..bde4e89 100644
--- a/spec/functions/deprecation_spec.rb
+++ b/spec/functions/deprecation_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-if Puppet.version.to_f >= 4.0
+if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
describe 'deprecation' do
before(:each) {
# this is to reset the strict variable to default
@@ -40,7 +40,7 @@ if Puppet.version.to_f >= 4.0
Puppet.settings[:strict] = :warning
}
end
-else
+elsif Puppet.version.to_f < 4.0
# Puppet version < 4 will use these tests.
describe 'deprecation' do
after(:all) do
diff --git a/spec/functions/difference_spec.rb b/spec/functions/difference_spec.rb
index d5e983d..0ae3689 100755
--- a/spec/functions/difference_spec.rb
+++ b/spec/functions/difference_spec.rb
@@ -12,8 +12,10 @@ describe 'difference' do
it { is_expected.to run.with_params([], []).and_return([]) }
it { is_expected.to run.with_params([], ['one']).and_return([]) }
it { is_expected.to run.with_params(['one'], ['one']).and_return([]) }
+ it { is_expected.to run.with_params(['ớņέ'], ['']).and_return(['ớņέ']) }
it { is_expected.to run.with_params(['one'], []).and_return(['one']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three']).and_return(['one']) }
+ it { is_expected.to run.with_params(['ớņέ', 'ŧשּׁō', 'ŧħґëə', 2], ['ŧשּׁō', 'ŧħґëə']).and_return(['ớņέ', 2]) }
it { is_expected.to run.with_params(['one', 'two', 'two', 'three'], ['two', 'three']).and_return(['one']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['one']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three', 'four']).and_return(['one']) }
diff --git a/spec/functions/dig44_spec.rb b/spec/functions/dig44_spec.rb
index 4f7408d..a7b8a3d 100644
--- a/spec/functions/dig44_spec.rb
+++ b/spec/functions/dig44_spec.rb
@@ -25,6 +25,18 @@ describe 'dig44' do
}
end
+ let(:utf8_data) do
+ {
+ 'ẵ' => {
+ 'в' => [
+ '©',
+ 'ĝ',
+ 'に',
+ ]
+ }
+ }
+ end
+
context 'single values' do
it 'should exist' do
is_expected.not_to be_nil
@@ -100,6 +112,20 @@ describe 'dig44' do
it 'should return "nil" if value is not found and no default value is provided' do
is_expected.to run.with_params(data, %w(a 1)).and_return(nil)
end
+ end
+
+ context 'Internationalization (i18N) values' do
+
+ it 'should be able to return a unicode character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 0]).and_return('©')
+ end
+ it 'should be able to return a utf8 character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 1]).and_return('ĝ')
+ end
+
+ it 'should be able to return a double byte character' do
+ is_expected.to run.with_params(utf8_data, ['ẵ', 'в', 2]).and_return('に')
+ end
end
end
diff --git a/spec/functions/dirname_spec.rb b/spec/functions/dirname_spec.rb
index 46c4c35..c494915 100755
--- a/spec/functions/dirname_spec.rb
+++ b/spec/functions/dirname_spec.rb
@@ -10,4 +10,9 @@ describe 'dirname' do
it { is_expected.to run.with_params('/path/to/a/file.ext', []).and_raise_error(Puppet::ParseError) }
it { is_expected.to run.with_params('/path/to/a/file.ext').and_return('/path/to/a') }
it { is_expected.to run.with_params('relative_path/to/a/file.ext').and_return('relative_path/to/a') }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('scheme:///√ạĺűē/竹.ext').and_return('scheme:///√ạĺűē') }
+ it { is_expected.to run.with_params('ҝẽγ:/√ạĺűē/竹.ㄘ').and_return('ҝẽγ:/√ạĺűē') }
+ end
end
diff --git a/spec/functions/dos2unix_spec.rb b/spec/functions/dos2unix_spec.rb
index 9c84703..97abae7 100644
--- a/spec/functions/dos2unix_spec.rb
+++ b/spec/functions/dos2unix_spec.rb
@@ -29,12 +29,19 @@ describe 'dos2unix' do
end
end
- context 'Converting from unix to unix format' do
- sample_text = "Hello\nWorld\n"
- desired_output = "Hello\nWorld\n"
+ context 'Internationalization (i18N) values' do
+ sample_text_utf8 = "Ħ℮ļłǿ\r\nשׁөŕłđ\r\n"
+ desired_output_utf8 = "Ħ℮ļłǿ\nשׁөŕłđ\n"
- it 'should output unix format' do
- should run.with_params(sample_text).and_return(desired_output)
+ sample_text_doublebyte = "こんにちは\r\n世界\r\n"
+ desired_output_doublebyte = "こんにちは\n世界\n"
+
+ it 'should output uft8 string' do
+ should run.with_params(sample_text_utf8).and_return(desired_output_utf8)
+ end
+
+ it 'should output double byte string' do
+ should run.with_params(sample_text_doublebyte).and_return(desired_output_doublebyte)
end
end
end
diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb
index 5d97684..190e580 100755
--- a/spec/functions/ensure_packages_spec.rb
+++ b/spec/functions/ensure_packages_spec.rb
@@ -34,11 +34,38 @@ describe 'ensure_packages' do
end
end
+ context 'given an empty packages array' do
+ let(:pre_condition) { 'notify { "hi": } -> Package <| |>; $somearray = ["vim",""]; ensure_packages($somearray)' }
+
+ describe 'after running ensure_package(["vim", ""])' do
+ it { expect { catalogue }.to raise_error(Puppet::ParseError, /Empty String provided/) }
+ end
+ end
+
context 'given hash of packages' do
before { subject.call([{"foo" => { "provider" => "rpm" }, "bar" => { "provider" => "gem" }}, { "ensure" => "present"}]) }
+ before { subject.call([{"パッケージ" => { "ensure" => "absent"}}]) }
+ before { subject.call([{"ρǻ¢κầģẻ" => { "ensure" => "absent"}}]) }
# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(lambda { catalogue }).to contain_package('foo').with({'provider' => 'rpm', 'ensure' => 'present'}) }
it { expect(lambda { catalogue }).to contain_package('bar').with({'provider' => 'gem', 'ensure' => 'present'}) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { expect(lambda { catalogue }).to contain_package('パッケージ').with({'ensure' => 'absent'}) }
+ it { expect(lambda { catalogue }).to contain_package('ρǻ¢κầģẻ').with({'ensure' => 'absent'}) }
+ end
end
+
+ context 'given a catalog with "package { puppet: ensure => present }"' do
+ let(:pre_condition) { 'package { puppet: ensure => present }' }
+
+ describe 'after running ensure_package("puppet", { "ensure" => "installed" })' do
+ before { subject.call(['puppet', { "ensure" => "installed" }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_package('puppet').with_ensure('present') }
+ end
+ end
+
end
diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb
index d552f4e..c847bf7 100755
--- a/spec/functions/ensure_resource_spec.rb
+++ b/spec/functions/ensure_resource_spec.rb
@@ -4,7 +4,7 @@ describe 'ensure_resource' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a type/) }
it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /Must specify a title/) }
- if Puppet.version.to_f >= 4.6
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.6.0') >= 0
it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(ArgumentError) }
else
it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) }
@@ -39,6 +39,37 @@ describe 'ensure_resource' do
it { expect(lambda { catalogue }).to contain_user('username1').without_gid }
end
+ describe 'after running ensure_resource("test::deftype", "foo", {})' do
+ before { subject.call(['test::deftype', 'foo', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure }
+ end
+ end
+
+ context 'given a catalog with UTF8 chars' do
+ describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", {})' do
+ before { subject.call(['User', 'Şắოрŀễ Ţëם', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
+ end
+
+ describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { gid => undef })' do
+ before { subject.call(['User', 'Şắოрŀễ Ţëם', { 'gid' => :undef }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_ensure }
+ it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
+ end
+
+ describe 'after running ensure_resource("user", "Şắოрŀễ Ţëם", { ensure => present, gid => undef })' do
+ before { subject.call(['User', 'Şắოрŀễ Ţëם', { 'ensure' => 'present', 'gid' => :undef }]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').with_ensure('present') }
+ it { expect(lambda { catalogue }).to contain_user('Şắოрŀễ Ţëם').without_gid }
+ end
end
context 'given a catalog with "user { username1: ensure => present }"' do
@@ -90,4 +121,15 @@ describe 'ensure_resource' do
}
end
end
+
+ context 'given a catalog with "test::deftype { foo: }"' do
+ let(:pre_condition) { 'test::deftype { "foo": }' }
+
+ describe 'after running ensure_resource("test::deftype", "foo", {})' do
+ before { subject.call(['test::deftype', 'foo', {}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_test__deftype('foo').without_ensure }
+ end
+ end
end
diff --git a/spec/functions/ensure_resources_spec.rb b/spec/functions/ensure_resources_spec.rb
new file mode 100644
index 0000000..7cca671
--- /dev/null
+++ b/spec/functions/ensure_resources_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'ensure_resources' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a type/) }
+ it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /Must specify a title/) }
+
+ describe 'given a title hash of multiple resources' do
+ before { subject.call(['user', {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }, 'alex' => { 'gid' => 'mygroup', 'uid' => '700'}}, {'ensure' => 'present'}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_user('dan').with_ensure('present') }
+ it { expect(lambda { catalogue }).to contain_user('alex').with_ensure('present') }
+ it { expect(lambda { catalogue }).to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600'}) }
+ it { expect(lambda { catalogue }).to contain_user('alex').with({ 'gid' => 'mygroup', 'uid' => '700'}) }
+ end
+
+ describe 'given a title hash of a single resource' do
+ before { subject.call(['user', {'dan' => { 'gid' => 'mygroup', 'uid' => '600' }}, {'ensure' => 'present'}]) }
+
+ # this lambda is required due to strangeness within rspec-puppet's expectation handling
+ it { expect(lambda { catalogue }).to contain_user('dan').with_ensure('present') }
+ it { expect(lambda { catalogue }).to contain_user('dan').with({ 'gid' => 'mygroup', 'uid' => '600'}) }
+ end
+end
diff --git a/spec/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb
index a4338be..b80f3c5 100755
--- a/spec/functions/flatten_spec.rb
+++ b/spec/functions/flatten_spec.rb
@@ -11,4 +11,5 @@ describe 'flatten' do
it { is_expected.to run.with_params([['one']]).and_return(['one']) }
it { is_expected.to run.with_params(["a","b","c","d","e","f","g"]).and_return(["a","b","c","d","e","f","g"]) }
it { is_expected.to run.with_params([["a","b",["c",["d","e"],"f","g"]]]).and_return(["a","b","c","d","e","f","g"]) }
+ it { is_expected.to run.with_params(["ã","β",["ĉ",["đ","ẽ","ƒ","ġ"]]]).and_return(["ã","β","ĉ","đ","ẽ","ƒ","ġ"]) }
end
diff --git a/spec/functions/fqdn_rand_string_spec.rb b/spec/functions/fqdn_rand_string_spec.rb
index e407084..861a59e 100644
--- a/spec/functions/fqdn_rand_string_spec.rb
+++ b/spec/functions/fqdn_rand_string_spec.rb
@@ -20,6 +20,7 @@ describe 'fqdn_rand_string' do
it { is_expected.to run.with_params(100, '').and_return(default_charset) }
it { is_expected.to run.with_params(100, 'a').and_return(/\Aa{100}\z/) }
it { is_expected.to run.with_params(100, 'ab').and_return(/\A[ab]{100}\z/) }
+ it { is_expected.to run.with_params(100, 'ãβ').and_return(/\A[ãβ]{100}\z/) }
it "provides the same 'random' value on subsequent calls for the same host" do
expect(fqdn_rand_string(10)).to eql(fqdn_rand_string(10))
diff --git a/spec/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb
index db7a717..7c1038a 100755
--- a/spec/functions/fqdn_rotate_spec.rb
+++ b/spec/functions/fqdn_rotate_spec.rb
@@ -7,6 +7,7 @@ describe 'fqdn_rotate' do
it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work with/) }
it { is_expected.to run.with_params('').and_return('') }
it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('ã').and_return('ã') }
it { is_expected.to run.with_params([]).and_return([]) }
it { is_expected.to run.with_params(['a']).and_return(['a']) }
diff --git a/spec/functions/fqdn_uuid_spec.rb b/spec/functions/fqdn_uuid_spec.rb
index a2d1618..d0c30d6 100644
--- a/spec/functions/fqdn_uuid_spec.rb
+++ b/spec/functions/fqdn_uuid_spec.rb
@@ -10,5 +10,4 @@ describe 'fqdn_uuid' do
it { should run.with_params('puppetlabs.com').and_return('9c70320f-6815-5fc5-ab0f-debe68bf764c') }
it { should run.with_params('google.com').and_return('64ee70a4-8cc1-5d25-abf2-dea6c79a09c8') }
end
-
end
diff --git a/spec/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb
index e4ef9e6..522ed3b 100755
--- a/spec/functions/getparam_spec.rb
+++ b/spec/functions/getparam_spec.rb
@@ -24,4 +24,12 @@ describe 'getparam' do
it { is_expected.to run.with_params('User[one]', 'shell').and_return('/bin/sh') }
it { is_expected.to run.with_params('User[one]', 'managehome').and_return(false) }
end
+
+ describe 'when compared against a user resource with UTF8 and double byte params' do
+ let(:pre_condition) { 'user { ["三", "ƒốưř"]: ensure => present }' }
+
+ it { is_expected.to run.with_params('User[三]', 'ensure').and_return('present') }
+ it { is_expected.to run.with_params('User[ƒốưř]', 'ensure').and_return('present') }
+
+ end
end
diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb
index 54f1842..55789d8 100755
--- a/spec/functions/getvar_spec.rb
+++ b/spec/functions/getvar_spec.rb
@@ -20,4 +20,19 @@ describe 'getvar' do
it { is_expected.to run.with_params('::site::data::foo').and_return('baz') }
it { is_expected.to run.with_params('::site::data::bar').and_return(nil) }
end
+
+ context 'given variables in namespaces' do
+ let(:pre_condition) {
+ <<-'ENDofPUPPETcode'
+ class site::info { $lock = 'ŧҺîš íš ắ śţřĭŋĝ' }
+ class site::new { $item = '万Ü€‰' }
+ include site::info
+ include site::new
+ ENDofPUPPETcode
+ }
+
+ it { is_expected.to run.with_params('site::info::lock').and_return('ŧҺîš íš ắ śţřĭŋĝ') }
+ it { is_expected.to run.with_params('::site::new::item').and_return('万Ü€‰') }
+ end
end
+
diff --git a/spec/functions/glob_spec.rb b/spec/functions/glob_spec.rb
new file mode 100755
index 0000000..06439da
--- /dev/null
+++ b/spec/functions/glob_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe 'glob' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError) }
+ it { is_expected.to run.with_params('').and_return([]) }
+ it { is_expected.to run.with_params(['']).and_return([]) }
+ it { is_expected.to run.with_params(['', '']).and_return([]) }
+ it { is_expected.to run.with_params(['/etc/xyzxyzxyz', '/etcxyzxyzxyz']).and_return([]) }
+end
diff --git a/spec/functions/grep_spec.rb b/spec/functions/grep_spec.rb
index 6e0bd6e..d2152b1 100755
--- a/spec/functions/grep_spec.rb
+++ b/spec/functions/grep_spec.rb
@@ -16,4 +16,5 @@ describe 'grep' do
it { is_expected.to run.with_params([], 'two').and_return([]) }
it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['two']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], 't(wo|hree)').and_return(['two', 'three']) }
+ it { is_expected.to run.with_params(['ờאּê', 'ţשּׂỡ', 'ţһŗəè'], 'ţ(שּׂỡ|һŗəè)').and_return(['ţשּׂỡ', 'ţһŗəè']) }
end
diff --git a/spec/functions/has_ip_network_spec.rb b/spec/functions/has_ip_network_spec.rb
index 7b5fe66..57cf613 100755
--- a/spec/functions/has_ip_network_spec.rb
+++ b/spec/functions/has_ip_network_spec.rb
@@ -9,7 +9,6 @@ describe 'has_ip_network' do
let(:facts) do
{
:interfaces => 'eth0,lo',
- :network => :undefined,
:network_lo => '127.0.0.0',
:network_eth0 => '10.0.0.0',
}
diff --git a/spec/functions/has_key_spec.rb b/spec/functions/has_key_spec.rb
index 965d5a6..0e0e1cc 100755
--- a/spec/functions/has_key_spec.rb
+++ b/spec/functions/has_key_spec.rb
@@ -12,4 +12,9 @@ describe 'has_key' do
it { is_expected.to run.with_params({ 'key' => 'value' }, "key").and_return(true) }
it { is_expected.to run.with_params({}, "key").and_return(false) }
it { is_expected.to run.with_params({ 'key' => 'value'}, "not a key").and_return(false) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params({ 'κéỳ ' => '٧ậļųể' }, "κéỳ ").and_return(true) }
+ it { is_expected.to run.with_params({ 'キー' => '٧ậļųể' }, "キー").and_return(true) }
+ end
end
diff --git a/spec/functions/hash_spec.rb b/spec/functions/hash_spec.rb
index 4fe99ce..092474b 100755
--- a/spec/functions/hash_spec.rb
+++ b/spec/functions/hash_spec.rb
@@ -10,5 +10,6 @@ describe 'hash' do
it { is_expected.to run.with_params(['one']).and_raise_error(Puppet::ParseError, /Unable to compute/) }
it { is_expected.to run.with_params([]).and_return({}) }
it { is_expected.to run.with_params(['key1', 'value1']).and_return({ 'key1' => 'value1' }) }
+ it { is_expected.to run.with_params(['κ℮ұ1', '√āĺűẻ1']).and_return({ 'κ℮ұ1' => '√āĺűẻ1' }) }
it { is_expected.to run.with_params(['key1', 'value1', 'key2', 'value2']).and_return({ 'key1' => 'value1', 'key2' => 'value2' }) }
end
diff --git a/spec/functions/intersection_spec.rb b/spec/functions/intersection_spec.rb
index c0f6086..ec368a5 100755
--- a/spec/functions/intersection_spec.rb
+++ b/spec/functions/intersection_spec.rb
@@ -14,6 +14,7 @@ describe 'intersection' do
it { is_expected.to run.with_params(['one'], []).and_return([]) }
it { is_expected.to run.with_params(['one'], ['one']).and_return(['one']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three']).and_return(['two', 'three']) }
+ it { is_expected.to run.with_params(['ōŋể', 'ŧשợ', 'ţђŕẽё'], ['ŧשợ', 'ţђŕẽё']).and_return(['ŧשợ', 'ţђŕẽё']) }
it { is_expected.to run.with_params(['one', 'two', 'two', 'three'], ['two', 'three']).and_return(['two', 'three']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['two', 'three']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'three', 'four']).and_return(['two', 'three']) }
diff --git a/spec/functions/is_a_spec.rb b/spec/functions/is_a_spec.rb
index 8dec13f..2d6cb46 100644
--- a/spec/functions/is_a_spec.rb
+++ b/spec/functions/is_a_spec.rb
@@ -21,5 +21,10 @@ if Puppet.version.to_f >= 4.0
it 'fails when comparing an integer and a string' do
is_expected.to run.with_params(5, String).and_return(false)
end
+
+ it 'suceeds when comparing an UTF8 and double byte characters' do
+ is_expected.to run.with_params('このテキスト', String).and_return(true)
+ is_expected.to run.with_params('ŧћịś ŧêχŧ', String).and_return(true)
+ end
end
end
diff --git a/spec/functions/is_function_available.rb b/spec/functions/is_function_available_spec.rb
index 44f08c0..44f08c0 100755
--- a/spec/functions/is_function_available.rb
+++ b/spec/functions/is_function_available_spec.rb
diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb
index b296830..8118ef4 100755
--- a/spec/functions/is_integer_spec.rb
+++ b/spec/functions/is_integer_spec.rb
@@ -11,6 +11,8 @@ describe 'is_integer' do
it { is_expected.to run.with_params('3').and_return(true) }
it { is_expected.to run.with_params(-3).and_return(true) }
it { is_expected.to run.with_params('-3').and_return(true) }
+ it { is_expected.to run.with_params("123\nfoo").and_return(true) }
+ it { is_expected.to run.with_params("foo\n123").and_return(true) }
it { is_expected.to run.with_params(3.7).and_return(false) }
it { is_expected.to run.with_params('3.7').and_return(false) }
@@ -24,6 +26,7 @@ describe 'is_integer' do
it { is_expected.to run.with_params(true).and_return(false) }
it { is_expected.to run.with_params(false).and_return(false) }
it { is_expected.to run.with_params('0001234').and_return(false) }
+ it { is_expected.to run.with_params("foo\nbar").and_return(false) }
context 'Checking for deprecation warning' do
after(:all) do
diff --git a/spec/functions/is_mac_address_spec.rb b/spec/functions/is_mac_address_spec.rb
index 5f76a91..c1e33b8 100755
--- a/spec/functions/is_mac_address_spec.rb
+++ b/spec/functions/is_mac_address_spec.rb
@@ -9,6 +9,12 @@ describe 'is_mac_address' do
it { is_expected.to run.with_params('00:00:00:00:00:0g').and_return(false) }
it { is_expected.to run.with_params('').and_return(false) }
it { is_expected.to run.with_params('one').and_return(false) }
+
+ context 'function can handle UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('ƒốưř').and_return(false) }
+ it { is_expected.to run.with_params('三+').and_return(false) }
+ end
+
it {
pending "should properly typecheck its arguments"
is_expected.to run.with_params(1).and_return(false)
diff --git a/spec/functions/join_keys_to_values_spec.rb b/spec/functions/join_keys_to_values_spec.rb
index c2bae5b..0a2a50c 100755
--- a/spec/functions/join_keys_to_values_spec.rb
+++ b/spec/functions/join_keys_to_values_spec.rb
@@ -11,6 +11,12 @@ describe 'join_keys_to_values' do
it { is_expected.to run.with_params({}, ':').and_return([]) }
it { is_expected.to run.with_params({ 'key' => 'value' }, '').and_return(['keyvalue']) }
it { is_expected.to run.with_params({ 'key' => 'value' }, ':').and_return(['key:value']) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params({ 'ҝẽγ' => '√ạĺűē' }, ':').and_return(['ҝẽγ:√ạĺűē']) }
+ it { is_expected.to run.with_params({ 'ҝẽγ' => '√ạĺűē' }, '万').and_return(['ҝẽγ万√ạĺűē']) }
+ end
+
it { is_expected.to run.with_params({ 'key' => nil }, ':').and_return(['key:']) }
it 'should run join_keys_to_values(<hash with multiple keys>, ":") and return the proper array' do
result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }, ':'])
@@ -21,3 +27,4 @@ describe 'join_keys_to_values' do
expect(result.sort).to eq(['key1 value1', 'key2 value2', 'key2 value3'].sort)
end
end
+
diff --git a/spec/functions/join_spec.rb b/spec/functions/join_spec.rb
index a300571..98852d5 100755
--- a/spec/functions/join_spec.rb
+++ b/spec/functions/join_spec.rb
@@ -16,4 +16,5 @@ describe 'join' do
it { is_expected.to run.with_params(['one'], ':').and_return('one') }
it { is_expected.to run.with_params(['one', 'two', 'three']).and_return('onetwothree') }
it { is_expected.to run.with_params(['one', 'two', 'three'], ':').and_return('one:two:three') }
+ it { is_expected.to run.with_params(['ōŋể', 'ŧשợ', 'ţђŕẽё'], ':').and_return('ōŋể:ŧשợ:ţђŕẽё') }
end
diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb
index 2e009dc..fc7d6d8 100755
--- a/spec/functions/keys_spec.rb
+++ b/spec/functions/keys_spec.rb
@@ -16,4 +16,9 @@ describe 'keys' do
result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }])
expect(result).to match_array(['key1', 'key2'])
end
+
+ it 'should run with UTF8 and double byte characters' do
+ result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }])
+ expect(result).to match_array(['ҝểү', 'キー'])
+ end
end
diff --git a/spec/functions/length_spec.rb b/spec/functions/length_spec.rb
new file mode 100755
index 0000000..487cf21
--- /dev/null
+++ b/spec/functions/length_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'length' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(ArgumentError, /'length' expects 1 argument, got none/) }
+ it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, /'length' expects 1 argument, got 2/) }
+ it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Integer/) }
+ it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, /expects a value of type String, Array, or Hash, got Boolean/) }
+ it { is_expected.to run.with_params('1').and_return(1) }
+ it { is_expected.to run.with_params('1.0').and_return(3) }
+ it { is_expected.to run.with_params([]).and_return(0) }
+ it { is_expected.to run.with_params(['a']).and_return(1) }
+ it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) }
+ it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) }
+
+ it { is_expected.to run.with_params({}).and_return(0) }
+ it { is_expected.to run.with_params({'1' => '2'}).and_return(1) }
+ it { is_expected.to run.with_params({'1' => '2', '4' => '4'}).and_return(2) }
+ it { is_expected.to run.with_params({'€' => '@', '竹' => 'ǿňè'}).and_return(2) }
+
+ it { is_expected.to run.with_params('').and_return(0) }
+ it { is_expected.to run.with_params('a').and_return(1) }
+ it { is_expected.to run.with_params('abc').and_return(3) }
+ it { is_expected.to run.with_params('abcd').and_return(4) }
+ it { is_expected.to run.with_params('万').and_return(1) }
+ it { is_expected.to run.with_params('āβćđ').and_return(4) }
+
+ context 'when using a class extending String' do
+ it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return(9) }
+ end
+end
diff --git a/spec/functions/load_module_metadata_spec.rb b/spec/functions/load_module_metadata_spec.rb
index 1a61e2c..9496fcb 100755
--- a/spec/functions/load_module_metadata_spec.rb
+++ b/spec/functions/load_module_metadata_spec.rb
@@ -7,32 +7,55 @@ describe 'load_module_metadata' do
describe "when calling with valid arguments" do
before :each do
- if RSpec.configuration.puppet_future
- allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
- else
- allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
- end
+ allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
+ allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
end
+
+ context "when calling with valid utf8 and double byte character arguments" do
+ before :each do
+ allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
+この文字"}')
+ allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš -
+この文字"}')
+ end
+
it "should json parse the file" do
- allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
- allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(true)
- allow(File).to receive(:read).with('/path/to/module/metadata.json').and_return('{"name": "spencer-science"}')
+ if Puppet::Util::Platform.windows?
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
+ allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(true)
+ allow(File).to receive(:read).with('C:/path/to/module/metadata.json').and_return('{"name": "spencer-science"}')
+ else
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
+ allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(true)
+ allow(File).to receive(:read).with('/path/to/module/metadata.json').and_return('{"name": "spencer-science"}')
+ end
result = subject.call(['science'])
expect(result['name']).to eq('spencer-science')
end
it "should fail by default if there is no metadata.json" do
- allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
- allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
+ if Puppet::Util::Platform.windows?
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
+ allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(false)
+ else
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
+ allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
+ end
expect {subject.call(['science'])}.to raise_error(Puppet::ParseError)
end
it "should return nil if user allows empty metadata.json" do
- allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
- allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
+ if Puppet::Util::Platform.windows?
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return('C:/path/to/module/')
+ allow(File).to receive(:exists?).with('C:/path/to/module/metadata.json').and_return(false)
+ else
+ allow(scope).to receive(:function_get_module_path).with(['science']).and_return('/path/to/module/')
+ allow(File).to receive(:exists?).with('/path/to/module/metadata.json').and_return(false)
+ end
result = subject.call(['science', true])
expect(result).to eq({})
end
+ end
end
end
diff --git a/spec/functions/loadjson_spec.rb b/spec/functions/loadjson_spec.rb
index a00dff9..dbef805 100644
--- a/spec/functions/loadjson_spec.rb
+++ b/spec/functions/loadjson_spec.rb
@@ -6,26 +6,37 @@ describe 'loadjson' do
describe "when calling with valid arguments" do
before :each do
- if RSpec.configuration.puppet_future
- allow(File).to receive(:read).with(/\/stdlib\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
- else
- allow(File).to receive(:read).with(/\/stdlib\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
- end
+ allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/, {:encoding=>"utf-8"}).and_return('{"name": "puppetlabs-stdlib"}')
+ allow(File).to receive(:read).with(/\/(stdlib|test)\/metadata.json/).and_return('{"name": "puppetlabs-stdlib"}')
end
context 'when a non-existing file is specified' do
- let(:filename) { '/tmp/doesnotexist' }
+ let(:filename) {
+ if Puppet::Util::Platform.windows?
+ 'C:/tmp/doesnotexist'
+ else
+ '/tmp/doesnotexist'
+ end
+ }
before {
allow(File).to receive(:exists?).with(filename).and_return(false).once
allow(PSON).to receive(:load).never
}
it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
+ it { is_expected.to run.with_params(filename, {'đẽƒằưļŧ' => '٧ẵłựέ'}).and_return({'đẽƒằưļŧ' => '٧ẵłựέ'}) }
+ it { is_expected.to run.with_params(filename, {'デフォルト' => '値'}).and_return({'デフォルト' => '値'}) }
end
context 'when an existing file is specified' do
- let(:filename) { '/tmp/doesexist' }
- let(:data) { { 'key' => 'value' } }
- let(:json) { '{"key":"value"}' }
+ let(:filename) {
+ if Puppet::Util::Platform.windows?
+ 'C:/tmp/doesexist'
+ else
+ '/tmp/doesexist'
+ end
+ }
+ let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'} }
+ let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' }
before {
allow(File).to receive(:exists?).with(filename).and_return(true).once
allow(File).to receive(:read).with(filename).and_return(json).once
@@ -36,7 +47,13 @@ describe 'loadjson' do
end
context 'when the file could not be parsed' do
- let(:filename) { '/tmp/doesexist' }
+ let(:filename) {
+ if Puppet::Util::Platform.windows?
+ 'C:/tmp/doesexist'
+ else
+ '/tmp/doesexist'
+ end
+ }
let(:json) { '{"key":"value"}' }
before {
allow(File).to receive(:exists?).with(filename).and_return(true).once
diff --git a/spec/functions/loadyaml_spec.rb b/spec/functions/loadyaml_spec.rb
index 9f16a1a..e9428e3 100755
--- a/spec/functions/loadyaml_spec.rb
+++ b/spec/functions/loadyaml_spec.rb
@@ -11,11 +11,13 @@ describe 'loadyaml' do
YAML.expects(:load_file).never
}
it { is_expected.to run.with_params(filename, {'default' => 'value'}).and_return({'default' => 'value'}) }
+ it { is_expected.to run.with_params(filename, {'đẽƒằưļŧ' => '٧ẵłựέ'}).and_return({'đẽƒằưļŧ' => '٧ẵłựέ'}) }
+ it { is_expected.to run.with_params(filename, {'デフォルト' => '値'}).and_return({'デフォルト' => '値'}) }
end
context 'when an existing file is specified' do
let(:filename) { '/tmp/doesexist' }
- let(:data) { { 'key' => 'value' } }
+ let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値'} }
before {
File.expects(:exists?).with(filename).returns(true).once
YAML.expects(:load_file).with(filename).returns(data).once
diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb
index 981794e..a5a09ed 100755
--- a/spec/functions/lstrip_spec.rb
+++ b/spec/functions/lstrip_spec.rb
@@ -22,6 +22,7 @@ describe 'lstrip' do
it { is_expected.to run.with_params('one ').and_return('one ') }
it { is_expected.to run.with_params(' one ').and_return('one ') }
it { is_expected.to run.with_params(' one ').and_return('one ') }
+ it { is_expected.to run.with_params(' ǿňè ').and_return('ǿňè ') }
it { is_expected.to run.with_params("\tone ").and_return('one ') }
it { is_expected.to run.with_params("\t one ").and_return('one ') }
it { is_expected.to run.with_params("one \t").and_return("one \t") }
diff --git a/spec/functions/member_spec.rb b/spec/functions/member_spec.rb
index 527f887..8988632 100755
--- a/spec/functions/member_spec.rb
+++ b/spec/functions/member_spec.rb
@@ -17,5 +17,7 @@ describe 'member' do
it { is_expected.to run.with_params(['one'], 'one').and_return(true) }
it { is_expected.to run.with_params(['one'], ['one']).and_return(true) }
it { is_expected.to run.with_params(['one', 'two', 'three', 'four'], ['four', 'two']).and_return(true) }
+ it { is_expected.to run.with_params(['ọאּẹ', 'ŧẅồ', 'ţҺŗęē', 'ƒơџŕ'], ['ƒơџŕ', 'ŧẅồ']).and_return(true) }
it { is_expected.to run.with_params(['one', 'two', 'three', 'four'], ['four', 'five']).and_return(false) }
+ it { is_expected.to run.with_params(['ọאּẹ', 'ŧẅồ', 'ţҺŗęē', 'ƒơџŕ'], ['ƒơџŕ', 'ƒί√ə']).and_return(false) }
end
diff --git a/spec/functions/merge_spec.rb b/spec/functions/merge_spec.rb
index 7b53363..3b2e3ef 100755
--- a/spec/functions/merge_spec.rb
+++ b/spec/functions/merge_spec.rb
@@ -4,7 +4,7 @@ describe 'merge' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it { is_expected.to run.with_params({}, 'two').and_raise_error(Puppet::ParseError, /unexpected argument type String/) }
- it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) }
+ it { is_expected.to run.with_params({}, 1).and_raise_error(Puppet::ParseError, /unexpected argument type (Fixnum|Integer)/) }
it {
pending 'should not special case this'
is_expected.to run.with_params({}).and_return({})
diff --git a/spec/functions/parsejson_spec.rb b/spec/functions/parsejson_spec.rb
index a01f1f6..7b07e49 100755
--- a/spec/functions/parsejson_spec.rb
+++ b/spec/functions/parsejson_spec.rb
@@ -12,12 +12,12 @@ describe 'parsejson' do
context 'with correct JSON data' do
- it 'should be able to parse a JSON data with a Hash' do
+ it 'should be able to parse JSON data with a Hash' do
is_expected.to run.with_params('{"a":"1","b":"2"}').
and_return({'a'=>'1', 'b'=>'2'})
end
- it 'should be able to parse a JSON data with an Array' do
+ it 'should be able to parse JSON data with an Array' do
is_expected.to run.with_params('["a","b","c"]').
and_return(['a', 'b', 'c'])
end
@@ -29,11 +29,16 @@ describe 'parsejson' do
and_return({})
end
- it 'should be able to parse a JSON data with a mixed structure' do
+ it 'should be able to parse JSON data with a mixed structure' do
is_expected.to run.with_params('{"a":"1","b":2,"c":{"d":[true,false]}}').
and_return({'a' =>'1', 'b' => 2, 'c' => { 'd' => [true, false] } })
end
+ it 'should be able to parse JSON data with a UTF8 and double byte characters' do
+ is_expected.to run.with_params('{"×":"これ","ý":"記号","です":{"©":["Á","ß"]}}').
+ and_return({'×' =>'これ', 'ý' => '記号', 'です' => { '©' => ['Á', 'ß'] } })
+ end
+
it 'should not return the default value if the data was parsed correctly' do
is_expected.to run.with_params('{"a":"1"}', 'default_value').
and_return({'a' => '1'})
diff --git a/spec/functions/parseyaml_spec.rb b/spec/functions/parseyaml_spec.rb
index fa947ca..c2a138c 100755
--- a/spec/functions/parseyaml_spec.rb
+++ b/spec/functions/parseyaml_spec.rb
@@ -18,21 +18,26 @@ describe 'parseyaml' do
and_return('just a string')
end
- it 'should be able to parse a YAML data with a Hash' do
+ it 'should be able to parse YAML data with a Hash' do
is_expected.to run.with_params("---\na: '1'\nb: '2'\n").
and_return({'a' => '1', 'b' => '2'})
end
- it 'should be able to parse a YAML data with an Array' do
+ it 'should be able to parse YAML data with an Array' do
is_expected.to run.with_params("---\n- a\n- b\n- c\n").
and_return(['a', 'b', 'c'])
end
- it 'should be able to parse a YAML data with a mixed structure' do
+ it 'should be able to parse YAML data with a mixed structure' do
is_expected.to run.with_params("---\na: '1'\nb: 2\nc:\n d:\n - :a\n - true\n - false\n").
and_return({'a' => '1', 'b' => 2, 'c' => {'d' => [:a, true, false]}})
end
+ it 'should be able to parse YAML data with a UTF8 and double byte characters' do
+ is_expected.to run.with_params("---\na: ×\nこれ: 記号\nです:\n ©:\n - Á\n - ß\n").
+ and_return({"a"=>"×", "これ"=>"記号", "です"=>{"©"=>["Á", "ß"]} })
+ end
+
it 'should not return the default value if the data was parsed correctly' do
is_expected.to run.with_params("---\na: '1'\n", 'default_value').
and_return({'a' => '1'})
diff --git a/spec/functions/pick_default_spec.rb b/spec/functions/pick_default_spec.rb
index e2fc64a..a7ffc86 100755
--- a/spec/functions/pick_default_spec.rb
+++ b/spec/functions/pick_default_spec.rb
@@ -5,6 +5,7 @@ describe 'pick_default' do
it { is_expected.to run.with_params().and_raise_error(Puppet::Error, /Must receive at least one argument/) }
it { is_expected.to run.with_params('one', 'two').and_return('one') }
+ it { is_expected.to run.with_params('ớņệ', 'ťωơ').and_return('ớņệ') }
it { is_expected.to run.with_params('', 'two').and_return('two') }
it { is_expected.to run.with_params(:undef, 'two').and_return('two') }
it { is_expected.to run.with_params(:undefined, 'two').and_return('two') }
@@ -13,6 +14,7 @@ describe 'pick_default' do
[ '', :undef, :undefined, nil, {}, [], 1, 'default' ].each do |value|
describe "when providing #{value.inspect} as default" do
it { is_expected.to run.with_params('one', value).and_return('one') }
+ it { is_expected.to run.with_params('ớņệ', value).and_return('ớņệ') }
it { is_expected.to run.with_params([], value).and_return([]) }
it { is_expected.to run.with_params({}, value).and_return({}) }
it { is_expected.to run.with_params(value, value).and_return(value) }
diff --git a/spec/functions/pick_spec.rb b/spec/functions/pick_spec.rb
index 2c7caa8..438553b 100755
--- a/spec/functions/pick_spec.rb
+++ b/spec/functions/pick_spec.rb
@@ -9,4 +9,9 @@ describe 'pick' do
it { is_expected.to run.with_params(:undef, 'two').and_return('two') }
it { is_expected.to run.with_params(:undefined, 'two').and_return('two') }
it { is_expected.to run.with_params(nil, 'two').and_return('two') }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(nil, 'このテキスト').and_return('このテキスト') }
+ it { is_expected.to run.with_params('', 'ŝẳмрłề џţƒ8 ţẽם', 'このテキスト').and_return('ŝẳмрłề џţƒ8 ţẽם') }
+ end
end
diff --git a/spec/functions/prefix_spec.rb b/spec/functions/prefix_spec.rb
index 3761022..5510c58 100755
--- a/spec/functions/prefix_spec.rb
+++ b/spec/functions/prefix_spec.rb
@@ -11,6 +11,7 @@ describe 'prefix' do
it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, /expected second argument to be a String/) }
it { is_expected.to run.with_params([]).and_return([]) }
it { is_expected.to run.with_params(['one', 2]).and_return(['one', '2']) }
+ it { is_expected.to run.with_params(['ớņệ', 2]).and_return(['ớņệ', '2']) }
it { is_expected.to run.with_params([], '').and_return([]) }
it { is_expected.to run.with_params([''], '').and_return(['']) }
it { is_expected.to run.with_params(['one'], 'pre').and_return(['preone']) }
diff --git a/spec/functions/pw_hash_spec.rb b/spec/functions/pw_hash_spec.rb
index df5348c..9e03464 100644
--- a/spec/functions/pw_hash_spec.rb
+++ b/spec/functions/pw_hash_spec.rb
@@ -65,5 +65,13 @@ describe 'pw_hash' do
it { is_expected.to run.with_params('password', 'sha-256', 'salt').and_return('$5$salt$Gcm6FsVtF/Qa77ZKD.iwsJlCVPY0XSMgLJL0Hnww/c1') }
it { is_expected.to run.with_params('password', 'sha-512', 'salt').and_return('$6$salt$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy.g.') }
end
+
+ if Puppet::Util::Package.versioncmp(Puppet.version, '4.7.0') >= 0
+ describe 'when arguments are sensitive' do
+ it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', 'salt').and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
+ it { is_expected.to run.with_params(Puppet::Pops::Types::PSensitiveType::Sensitive.new('password'), 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
+ it { is_expected.to run.with_params('password', 'md5', Puppet::Pops::Types::PSensitiveType::Sensitive.new('salt')).and_return('$1$salt$qJH7.N4xYta3aEG/dfqo/0') }
+ end
+ end
end
end
diff --git a/spec/functions/range_spec.rb b/spec/functions/range_spec.rb
index 492cad4..ca569d5 100755
--- a/spec/functions/range_spec.rb
+++ b/spec/functions/range_spec.rb
@@ -79,6 +79,14 @@ describe 'range' do
it { is_expected.to run.with_params('01', '04').and_return([1, 2, 3, 4]) }
end
+ context 'with prefixed numbers as utf8 strings as bounds' do
+ it { is_expected.to run.with_params('ħөŝŧ01', 'ħөŝŧ04').and_return(['ħөŝŧ01', 'ħөŝŧ02', 'ħөŝŧ03', 'ħөŝŧ04']) }
+ end
+
+ context 'with prefixed numbers as double byte character strings as bounds' do
+ it { is_expected.to run.with_params('ホスト01', 'ホスト04').and_return(['ホスト01', 'ホスト02', 'ホスト03', 'ホスト04']) }
+ end
+
context 'with dash-range syntax' do
it { is_expected.to run.with_params('4-1').and_return([]) }
it { is_expected.to run.with_params('1-1').and_return([1]) }
diff --git a/spec/functions/regexpescape_spec.rb b/spec/functions/regexpescape_spec.rb
index 6efa847..36dbe70 100644
--- a/spec/functions/regexpescape_spec.rb
+++ b/spec/functions/regexpescape_spec.rb
@@ -32,5 +32,10 @@ describe 'regexpescape' do
it { is_expected.to run.with_params([]).and_return([]) }
it { is_expected.to run.with_params(['one*', "two"]).and_return(['one\*', "two"]) }
it { is_expected.to run.with_params(['one*', 1, true, {}, "two"]).and_return(['one\*', 1, true, {}, "two"]) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(['ŏʼnε*']).and_return(['ŏʼnε\*']) }
+ it { is_expected.to run.with_params(['インターネット*']).and_return(['インターネット\*']) }
+ end
end
end
diff --git a/spec/functions/reject_spec.rb b/spec/functions/reject_spec.rb
index 4863050..86db7c7 100755
--- a/spec/functions/reject_spec.rb
+++ b/spec/functions/reject_spec.rb
@@ -16,4 +16,5 @@ describe 'reject' do
it { is_expected.to run.with_params([], 'two').and_return([]) }
it { is_expected.to run.with_params(['one', 'two', 'three'], 'two').and_return(['one', 'three']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], 't(wo|hree)').and_return(['one']) }
+ it { is_expected.to run.with_params(['όʼnệ', 'ţщồ', 'ţңяέέ'], 'ţ(щồ|ңяέέ)').and_return(['όʼnệ']) }
end
diff --git a/spec/functions/reverse_spec.rb b/spec/functions/reverse_spec.rb
index e00dee9..79bc0ad 100755
--- a/spec/functions/reverse_spec.rb
+++ b/spec/functions/reverse_spec.rb
@@ -15,11 +15,13 @@ describe 'reverse' do
it { is_expected.to run.with_params(['one']).and_return(['one']) }
it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(['three', 'two', 'one']) }
it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(['four', 'three', 'two', 'one']) }
+ it { is_expected.to run.with_params(['ổňë', 'ťŵọ', 'ŧңяəė', 'ƒŏůŗ']).and_return(['ƒŏůŗ', 'ŧңяəė', 'ťŵọ', 'ổňë']) }
it { is_expected.to run.with_params('').and_return('') }
it { is_expected.to run.with_params('a').and_return('a') }
it { is_expected.to run.with_params('abc').and_return('cba') }
it { is_expected.to run.with_params('abcd').and_return('dcba') }
+ it { is_expected.to run.with_params('āβćđ').and_return('đćβā') }
context 'when using a class extending String' do
it 'should call its reverse method' do
diff --git a/spec/functions/round_spec.rb b/spec/functions/round_spec.rb
new file mode 100755
index 0000000..8b13478
--- /dev/null
+++ b/spec/functions/round_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe 'round' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params(34.3).and_return(34) }
+ it { is_expected.to run.with_params(-34.3).and_return(-34) }
+ it { is_expected.to run.with_params(34.5).and_return(35) }
+ it { is_expected.to run.with_params(-34.5).and_return(-35) }
+ it { is_expected.to run.with_params(34.7).and_return(35) }
+ it { is_expected.to run.with_params(-34.7).and_return(-35) }
+ it { is_expected.to run.with_params("test").and_raise_error Puppet::ParseError }
+ it { is_expected.to run.with_params("test", "best").and_raise_error Puppet::ParseError }
+ it { is_expected.to run.with_params(3, 4).and_raise_error Puppet::ParseError }
+end
diff --git a/spec/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb
index d2efac8..a7663e2 100755
--- a/spec/functions/rstrip_spec.rb
+++ b/spec/functions/rstrip_spec.rb
@@ -22,6 +22,7 @@ describe 'rstrip' do
it { is_expected.to run.with_params('one ').and_return('one') }
it { is_expected.to run.with_params(' one ').and_return(' one') }
it { is_expected.to run.with_params(' one ').and_return(' one') }
+ it { is_expected.to run.with_params(' ǿňè ').and_return(' ǿňè') }
it { is_expected.to run.with_params("\tone ").and_return("\tone") }
it { is_expected.to run.with_params("\t one ").and_return("\t one") }
it { is_expected.to run.with_params("one\t").and_return('one') }
diff --git a/spec/functions/seeded_rand_spec.rb b/spec/functions/seeded_rand_spec.rb
index 38e134e..ac108f4 100644
--- a/spec/functions/seeded_rand_spec.rb
+++ b/spec/functions/seeded_rand_spec.rb
@@ -50,4 +50,9 @@ describe 'seeded_rand' do
scope.function_seeded_rand([max, seed])
end
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(1000, 'ǿňè')}
+ it { is_expected.to run.with_params(1000, '文字列')}
+ end
end
diff --git a/spec/functions/shell_escape_spec.rb b/spec/functions/shell_escape_spec.rb
index 3061dec..77917dd 100644
--- a/spec/functions/shell_escape_spec.rb
+++ b/spec/functions/shell_escape_spec.rb
@@ -19,4 +19,9 @@ describe 'shell_escape' do
it { is_expected.to run.with_params('~`!@#$%^&*()_+-=[]\{}|;\':",./<>?')
.and_return('\~\`\!@\#\$\%\^\&\*\(\)_\+-\=\[\]\\\\\{\}\|\;\\\':\",./\<\>\?') }
end
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('スペー スを含むテ キスト').and_return('\\ス\\ペ\\ー\\ \\ス\\を\\含\\む\\テ\\ \\ \\キ\\ス\\ト') }
+ it { is_expected.to run.with_params('μťƒ 8 ŧĕχť').and_return('\\μ\\ť\\ƒ\\ 8\\ \\ \\ŧ\\ĕ\\χ\\ť') }
+ end
end
diff --git a/spec/functions/shell_join_spec.rb b/spec/functions/shell_join_spec.rb
index 6815f7c..46305bf 100644
--- a/spec/functions/shell_join_spec.rb
+++ b/spec/functions/shell_join_spec.rb
@@ -15,6 +15,11 @@ describe 'shell_join' do
it { is_expected.to run.with_params(['foo', 'bar baz']).and_return('foo bar\ baz') }
it { is_expected.to run.with_params(['~`!@#$', '%^&*()_+-=', '[]\{}|;\':"', ',./<>?'])
.and_return('\~\`\!@\#\$ \%\^\&\*\(\)_\+-\= \[\]\\\\\{\}\|\;\\\':\" ,./\<\>\?') }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(['μťƒ', '8', 'ŧĕχť']).and_return('\\μ\\ť\\ƒ 8 \\ŧ\\ĕ\\χ\\ť') }
+ it { is_expected.to run.with_params(['スペー', 'スを含むテ', ' キスト']).and_return('\\ス\\ペ\\ー \\ス\\を\\含\\む\\テ \\ \\キ\\ス\\ト') }
+ end
end
describe 'stringification' do
diff --git a/spec/functions/shell_split_spec.rb b/spec/functions/shell_split_spec.rb
index beeb977..f8f9c90 100644
--- a/spec/functions/shell_split_spec.rb
+++ b/spec/functions/shell_split_spec.rb
@@ -20,5 +20,10 @@ describe 'shell_split' do
.and_return(['~`!@#$%^&*()_+-=[]\{}|;\':",./<>?']) }
it { is_expected.to run.with_params('\~\`\!@\#\$ \%\^\&\*\(\)_\+-\= \[\]\\\\\{\}\|\;\\\':\" ,./\<\>\?')
.and_return(['~`!@#$', '%^&*()_+-=', '[]\{}|;\':"', ',./<>?']) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('\\μ\\ť\\ƒ 8 \\ŧ\\ĕ\\χ\\ť').and_return(['μťƒ', '8', 'ŧĕχť']) }
+ it { is_expected.to run.with_params('\\ス\\ペ\\ー \\ス\\を\\含\\む\\テ \\ \\キ\\ス\\ト').and_return(['スペー', 'スを含むテ', ' キスト']) }
+ end
end
end
diff --git a/spec/functions/shuffle_spec.rb b/spec/functions/shuffle_spec.rb
index ebc3a73..4673daa 100755
--- a/spec/functions/shuffle_spec.rb
+++ b/spec/functions/shuffle_spec.rb
@@ -26,6 +26,11 @@ describe 'shuffle' do
it { is_expected.to run.with_params('abc').and_return('bac') }
it { is_expected.to run.with_params('abcd').and_return('dcba') }
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('ůţƒ8 ŧέχŧ şŧґíńģ').and_return('ģńş ůχţέƒŧí8ґŧŧ ') }
+ it { is_expected.to run.with_params('日本語の文字列').and_return('字本日語文列の') }
+ end
+
context 'when using a class extending String' do
it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return('lkhdsfajg') }
end
diff --git a/spec/functions/size_spec.rb b/spec/functions/size_spec.rb
index c0047ee..2047423 100755
--- a/spec/functions/size_spec.rb
+++ b/spec/functions/size_spec.rb
@@ -19,11 +19,14 @@ describe 'size' do
it { is_expected.to run.with_params({}).and_return(0) }
it { is_expected.to run.with_params({'1' => '2'}).and_return(1) }
it { is_expected.to run.with_params({'1' => '2', '4' => '4'}).and_return(2) }
+ it { is_expected.to run.with_params({'€' => '@', '竹' => 'ǿňè'}).and_return(2) }
it { is_expected.to run.with_params('').and_return(0) }
it { is_expected.to run.with_params('a').and_return(1) }
it { is_expected.to run.with_params('abc').and_return(3) }
it { is_expected.to run.with_params('abcd').and_return(4) }
+ it { is_expected.to run.with_params('万').and_return(1) }
+ it { is_expected.to run.with_params('āβćđ').and_return(4) }
context 'when using a class extending String' do
it 'should call its size method' do
diff --git a/spec/functions/squeeze_spec.rb b/spec/functions/squeeze_spec.rb
index 7f09c30..b267d9a 100755
--- a/spec/functions/squeeze_spec.rb
+++ b/spec/functions/squeeze_spec.rb
@@ -16,6 +16,12 @@ describe 'squeeze' do
it { is_expected.to run.with_params('aaaaaaaaabbbbbbbbbbcccccccccc', 'b-c').and_return('aaaaaaaaabc') }
end
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậậậậ').and_return('ậ') }
+ it { is_expected.to run.with_params('語語語語語語語', '語').and_return('語') }
+ it { is_expected.to run.with_params('ậậậậậậậậậậậậậậậậậ語語語語©©©©©', '©').and_return('ậậậậậậậậậậậậậậậậậ語語語語©') }
+ end
+
context 'when squeezing values in an array' do
it {
is_expected.to run \
diff --git a/spec/functions/strftime_spec.rb b/spec/functions/strftime_spec.rb
index e76774a..41cda6a 100755
--- a/spec/functions/strftime_spec.rb
+++ b/spec/functions/strftime_spec.rb
@@ -14,9 +14,9 @@ describe 'strftime' do
expect(result.to_i).to(be > 1311953157)
end
- it "using %s should be lower then 1.5 trillion" do
+ it "using %s should be greater than 1.5 trillion" do
result = scope.function_strftime(["%s"])
- expect(result.to_i).to(be < 1500000000)
+ expect(result.to_i).to(be > 1500000000)
end
it "should return a date when given %Y-%m-%d" do
diff --git a/spec/functions/strip_spec.rb b/spec/functions/strip_spec.rb
index 689b6dd..18e943d 100755
--- a/spec/functions/strip_spec.rb
+++ b/spec/functions/strip_spec.rb
@@ -30,5 +30,6 @@ describe 'strip' do
it { is_expected.to run.with_params("\tone \t").and_return('one') }
it { is_expected.to run.with_params("\t one \t").and_return('one') }
it { is_expected.to run.with_params(' o n e ').and_return('o n e') }
+ it { is_expected.to run.with_params(' ỏŋέ ').and_return('ỏŋέ') }
it { is_expected.to run.with_params(AlsoString.new(' one ')).and_return('one') }
end
diff --git a/spec/functions/suffix_spec.rb b/spec/functions/suffix_spec.rb
index efba4ab..e0eafb1 100755
--- a/spec/functions/suffix_spec.rb
+++ b/spec/functions/suffix_spec.rb
@@ -15,6 +15,8 @@ describe 'suffix' do
it { is_expected.to run.with_params([''], '').and_return(['']) }
it { is_expected.to run.with_params(['one'], 'post').and_return(['onepost']) }
it { is_expected.to run.with_params(['one', 'two', 'three'], 'post').and_return(['onepost', 'twopost', 'threepost']) }
+ it { is_expected.to run.with_params(['ỗńέ', 'ťשׂǿ', 'ŧҺř℮ə'], 'рổŝţ').and_return(['ỗńέрổŝţ', 'ťשׂǿрổŝţ', 'ŧҺř℮əрổŝţ']) }
+
it {
is_expected.to run.with_params({}).and_return({})
}
diff --git a/spec/functions/to_json_pretty_spec.rb b/spec/functions/to_json_pretty_spec.rb
new file mode 100755
index 0000000..abbcc2c
--- /dev/null
+++ b/spec/functions/to_json_pretty_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe 'to_json_pretty' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params([]).and_return("[\n\n]") }
+ it { is_expected.to run.with_params(['one']).and_return("[\n \"one\"\n]") }
+ it { is_expected.to run.with_params(['one', 'two']).and_return("[\n \"one\",\n \"two\"\n]") }
+ it { is_expected.to run.with_params({}).and_return("{\n}") }
+ it { is_expected.to run.with_params({ 'key' => 'value' }).and_return("{\n \"key\": \"value\"\n}") }
+ it { is_expected.to run.with_params({"one" => {"oneA" => "A","oneB" => {"oneB1" => "1","oneB2" => "2"}},"two" => ["twoA","twoB"]}).and_return("{\n \"one\": {\n \"oneA\": \"A\",\n \"oneB\": {\n \"oneB1\": \"1\",\n \"oneB2\": \"2\"\n }\n },\n \"two\": [\n \"twoA\",\n \"twoB\"\n ]\n}") }
+end
diff --git a/spec/functions/to_json_spec.rb b/spec/functions/to_json_spec.rb
new file mode 100755
index 0000000..925523c
--- /dev/null
+++ b/spec/functions/to_json_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe 'to_json' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params('').and_return("\"\"") }
+ it { is_expected.to run.with_params(true).and_return("true") }
+ it { is_expected.to run.with_params('one').and_return("\"one\"") }
+ it { is_expected.to run.with_params([]).and_return("[]") }
+ it { is_expected.to run.with_params(['one']).and_return("[\"one\"]") }
+ it { is_expected.to run.with_params(['one', 'two']).and_return("[\"one\",\"two\"]") }
+ it { is_expected.to run.with_params({}).and_return("{}") }
+ it { is_expected.to run.with_params({ 'key' => 'value' }).and_return("{\"key\":\"value\"}") }
+ it { is_expected.to run.with_params({"one" => {"oneA" => "A","oneB" => {"oneB1" => "1","oneB2" => "2"}},"two" => ["twoA","twoB"]}).and_return("{\"one\":{\"oneA\":\"A\",\"oneB\":{\"oneB1\":\"1\",\"oneB2\":\"2\"}},\"two\":[\"twoA\",\"twoB\"]}") }
+
+ it { is_expected.to run.with_params('‰').and_return('"‰"') }
+ it { is_expected.to run.with_params('竹').and_return('"竹"') }
+ it { is_expected.to run.with_params('Ü').and_return('"Ü"') }
+ it { is_expected.to run.with_params('∇').and_return('"∇"') }
+end
diff --git a/spec/functions/to_yaml_spec.rb b/spec/functions/to_yaml_spec.rb
new file mode 100755
index 0000000..3f69a70
--- /dev/null
+++ b/spec/functions/to_yaml_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+describe 'to_yaml' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params('').and_return("--- ''\n") }
+ it { is_expected.to run.with_params(true).and_return("--- true\n...\n") }
+ it { is_expected.to run.with_params('one').and_return("--- one\n...\n") }
+ it { is_expected.to run.with_params([]).and_return("--- []\n") }
+ it { is_expected.to run.with_params(['one']).and_return("---\n- one\n") }
+ it { is_expected.to run.with_params(['one', 'two']).and_return("---\n- one\n- two\n") }
+ it { is_expected.to run.with_params({}).and_return("--- {}\n") }
+ it { is_expected.to run.with_params({ 'key' => 'value' }).and_return("---\nkey: value\n") }
+ it { is_expected.to run.with_params({"one" => {"oneA" => "A","oneB" => {"oneB1" => "1","oneB2" => "2"}},"two" => ["twoA","twoB"]}).and_return("---\none:\n oneA: A\n oneB:\n oneB1: '1'\n oneB2: '2'\ntwo:\n- twoA\n- twoB\n") }
+
+ it { is_expected.to run.with_params('‰').and_return("--- \"‰\"\n") }
+ it { is_expected.to run.with_params('∇').and_return("--- \"∇\"\n") }
+end
diff --git a/spec/functions/union_spec.rb b/spec/functions/union_spec.rb
index cfd38b6..3f36f24 100755
--- a/spec/functions/union_spec.rb
+++ b/spec/functions/union_spec.rb
@@ -20,5 +20,6 @@ describe 'union' do
it { is_expected.to run.with_params(['one', 'two', 'three'], ['two', 'two', 'three']).and_return(['one', 'two', 'three']) }
it { is_expected.to run.with_params(['one', 'two'], ['two', 'three'], ['one', 'three']).and_return(['one', 'two', 'three']) }
it { is_expected.to run.with_params(['one', 'two'], ['three', 'four'], ['one', 'two', 'three'], ['four']).and_return(['one', 'two', 'three', 'four']) }
+ it { is_expected.to run.with_params(['ốńə', 'ţשׂợ'], ['ŧĥяếệ', 'ƒởųŗ'], ['ốńə', 'ţשׂợ', 'ŧĥяếệ'], ['ƒởųŗ']).and_return(['ốńə', 'ţשׂợ', 'ŧĥяếệ', 'ƒởųŗ']) }
it 'should not confuse types' do is_expected.to run.with_params(['1', '2', '3'], [1, 2]).and_return(['1', '2', '3', 1, 2]) end
end
diff --git a/spec/functions/unique_spec.rb b/spec/functions/unique_spec.rb
index 24257a0..76932ec 100755
--- a/spec/functions/unique_spec.rb
+++ b/spec/functions/unique_spec.rb
@@ -1,27 +1,31 @@
require 'spec_helper'
describe 'unique' do
- describe 'signature validation' do
- it { is_expected.not_to eq(nil) }
- it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
- it {
- pending("Current implementation ignores parameters after the first.")
- is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
- }
- it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
- it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
- it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
- end
+ if Puppet.version.to_f < 5.0
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it {
+ pending("Current implementation ignores parameters after the first.")
+ is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
+ }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Requires either array or string to work/) }
+ end
- context 'when called with an array' do
- it { is_expected.to run.with_params([]).and_return([]) }
- it { is_expected.to run.with_params(['a']).and_return(['a']) }
- it { is_expected.to run.with_params(['a', 'b', 'a']).and_return(['a', 'b']) }
- end
+ context 'when called with an array' do
+ it { is_expected.to run.with_params([]).and_return([]) }
+ it { is_expected.to run.with_params(['a']).and_return(['a']) }
+ it { is_expected.to run.with_params(['a', 'b', 'a']).and_return(['a', 'b']) }
+ it { is_expected.to run.with_params(['ã', 'ъ', 'ã']).and_return(['ã', 'ъ']) }
+ end
- context 'when called with a string' do
- it { is_expected.to run.with_params('').and_return('') }
- it { is_expected.to run.with_params('a').and_return('a') }
- it { is_expected.to run.with_params('aaba').and_return('ab') }
+ context 'when called with a string' do
+ it { is_expected.to run.with_params('').and_return('') }
+ it { is_expected.to run.with_params('a').and_return('a') }
+ it { is_expected.to run.with_params('aaba').and_return('ab') }
+ it { is_expected.to run.with_params('ããъã').and_return('ãъ') }
+ end
end
end
diff --git a/spec/functions/validate_cmd_spec.rb b/spec/functions/validate_cmd_spec.rb
index ab0cbc9..c6559e8 100755
--- a/spec/functions/validate_cmd_spec.rb
+++ b/spec/functions/validate_cmd_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'validate_cmd' do
+describe 'validate_cmd', :unless => Puppet::Util::Platform.windows? do
let(:touch) { File.exists?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' }
describe 'signature validation' do
diff --git a/spec/functions/validate_domain_name_spec.rb b/spec/functions/validate_domain_name_spec.rb
new file mode 100644
index 0000000..69fcae4
--- /dev/null
+++ b/spec/functions/validate_domain_name_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+describe 'validate_domain_name' do
+ describe 'signature validation' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ end
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params('com', 'com.') }
+ it { is_expected.to run.with_params('x.com', 'x.com.') }
+ it { is_expected.to run.with_params('foo.example.com', 'foo.example.com.') }
+ it { is_expected.to run.with_params('2foo.example.com', '2foo.example.com.') }
+ it { is_expected.to run.with_params('www.2foo.example.com', 'www.2foo.example.com.') }
+ it { is_expected.to run.with_params('domain.tld', 'puppet.com') }
+ end
+
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) }
+
+ it { is_expected.to run.with_params('foo.example.com', []).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params('foo.example.com', {}).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params('foo.example.com', 1).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params('foo.example.com', true).and_raise_error(Puppet::ParseError, /is not a string/) }
+
+ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) }
+ it { is_expected.to run.with_params('invalid domain').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) }
+ it { is_expected.to run.with_params('-foo.example.com').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) }
+ it { is_expected.to run.with_params('www.example.2com').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) }
+ it { is_expected.to run.with_params('192.168.1.1').and_raise_error(Puppet::ParseError, /is not a syntactically correct domain name/) }
+ end
+end
diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb
index 78810d4..137db36 100755
--- a/spec/functions/validate_ipv6_address_spec.rb
+++ b/spec/functions/validate_ipv6_address_spec.rb
@@ -29,6 +29,13 @@ describe 'validate_ipv6_address' do
it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
it { is_expected.to run.with_params('::1/64') }
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ it { is_expected.to run.with_params('fe80:0000:0000:0000:0204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80:0:0:0:204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80::204:61ff:fe9d:f156') }
+ it { is_expected.to run.with_params('fe80:0:0:0:0204:61ff:254.157.241.86') }
+ it { is_expected.to run.with_params('::1') }
+ it { is_expected.to run.with_params('fe80::') }
+ it { is_expected.to run.with_params('2001::') }
end
describe 'invalid inputs' do
@@ -38,6 +45,9 @@ describe 'validate_ipv6_address' do
it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('::ffff:2.3.4').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('::ffff:257.1.2.3').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('::ffff:12345678901234567890.1.26').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) }
it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) }
diff --git a/spec/functions/validate_legacy_spec.rb b/spec/functions/validate_legacy_spec.rb
index 50cb317..7b48f12 100644
--- a/spec/functions/validate_legacy_spec.rb
+++ b/spec/functions/validate_legacy_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-if Puppet.version.to_f >= 4.0
+if Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0
describe 'validate_legacy' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
diff --git a/spec/functions/values_at_spec.rb b/spec/functions/values_at_spec.rb
index a8348f3..681c101 100755
--- a/spec/functions/values_at_spec.rb
+++ b/spec/functions/values_at_spec.rb
@@ -30,6 +30,11 @@ describe 'values_at' do
it { is_expected.to run.with_params([0, 1, 2], 3).and_raise_error(Puppet::ParseError, /index exceeds array size/) }
end
+ context 'when requesting a single item using UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(['ẩ', 'β', 'с', 'ď'], 0).and_return(['ẩ']) }
+ it { is_expected.to run.with_params(['文', '字', 'の', '値'], 2).and_return(['の']) }
+ end
+
context 'when requesting multiple items' do
it { is_expected.to run.with_params([0, 1, 2], [1, -1]).and_raise_error(Puppet::ParseError, /Unknown format of given index/) }
it { is_expected.to run.with_params([0, 1, 2], [0, 2]).and_return([0, 2]) }
diff --git a/spec/functions/values_spec.rb b/spec/functions/values_spec.rb
index 4abf0bd..26c6dfb 100755
--- a/spec/functions/values_spec.rb
+++ b/spec/functions/values_spec.rb
@@ -16,4 +16,9 @@ describe 'values' do
result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }])
expect(result).to match_array(['value1', 'value2', 'value2'])
end
+
+ it 'should run with UTF8 and double byte characters' do
+ result = subject.call([{ 'かぎ' => '使用', 'ҝĕұ' => '√ẩŀứệ', 'ҝĕұďŭрļǐçằťè' => '√ẩŀứệ' }])
+ expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ'])
+ end
end
diff --git a/spec/functions/zip_spec.rb b/spec/functions/zip_spec.rb
index abca7ee..e1ae8ee 100755
--- a/spec/functions/zip_spec.rb
+++ b/spec/functions/zip_spec.rb
@@ -12,4 +12,10 @@ describe 'zip' do
it { is_expected.to run.with_params([1,2,3], [4,5,6]).and_return([[1,4], [2,5], [3,6]]) }
it { is_expected.to run.with_params([1,2,3], [4,5,6], false).and_return([[1,4], [2,5], [3,6]]) }
it { is_expected.to run.with_params([1,2,3], [4,5,6], true).and_return([1, 4, 2, 5, 3, 6]) }
+
+ context 'should run with UTF8 and double byte characters' do
+ it { is_expected.to run.with_params(['ầ', 'ь', 'ć'], ['đ', 'ề', 'ƒ']).and_return([['ầ','đ'], ['ь','ề'], ['ć', 'ƒ']]) }
+ it { is_expected.to run.with_params(['ペ', '含', '値'], ['ッ', '文', 'イ']).and_return([['ペ','ッ'], ['含','文'], ['値', 'イ']]) }
+ end
end
+