puppet 4.7.1-x64-mingw32 → 4.8.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/Gemfile +0 -3
- data/MAINTAINERS +76 -0
- data/README.md +0 -6
- data/Rakefile +2 -2
- data/lib/puppet/agent.rb +3 -3
- data/lib/puppet/application/apply.rb +1 -1
- data/lib/puppet/configurer.rb +2 -2
- data/lib/puppet/data_providers.rb +1 -0
- data/lib/puppet/data_providers/data_adapter.rb +1 -0
- data/lib/puppet/data_providers/data_function_support.rb +1 -0
- data/lib/puppet/data_providers/function_env_data_provider.rb +1 -0
- data/lib/puppet/data_providers/function_module_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_config.rb +1 -0
- data/lib/puppet/data_providers/hiera_env_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_interpolate.rb +1 -0
- data/lib/puppet/data_providers/hiera_module_data_provider.rb +1 -0
- data/lib/puppet/data_providers/hiera_support.rb +1 -2
- data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -0
- data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -0
- data/lib/puppet/defaults.rb +20 -1
- data/lib/puppet/environments.rb +5 -2
- data/lib/puppet/face/catalog.rb +1 -1
- data/lib/puppet/face/epp.rb +57 -11
- data/lib/puppet/face/module/install.rb +6 -6
- data/lib/puppet/functions.rb +23 -24
- data/lib/puppet/functions/alert.rb +14 -0
- data/lib/puppet/functions/binary_file.rb +25 -0
- data/lib/puppet/functions/break.rb +22 -0
- data/lib/puppet/functions/contain.rb +33 -0
- data/lib/puppet/functions/crit.rb +14 -0
- data/lib/puppet/functions/debug.rb +14 -0
- data/lib/puppet/functions/emerg.rb +14 -0
- data/lib/puppet/functions/epp.rb +1 -1
- data/lib/puppet/functions/err.rb +14 -0
- data/lib/puppet/functions/find_file.rb +31 -0
- data/lib/puppet/functions/include.rb +21 -0
- data/lib/puppet/functions/info.rb +14 -0
- data/lib/puppet/functions/new.rb +1 -1
- data/lib/puppet/functions/next.rb +23 -0
- data/lib/puppet/functions/notice.rb +14 -0
- data/lib/puppet/functions/regsubst.rb +12 -16
- data/lib/puppet/functions/require.rb +37 -0
- data/lib/puppet/functions/return.rb +22 -0
- data/lib/puppet/functions/strftime.rb +35 -0
- data/lib/puppet/functions/warning.rb +14 -0
- data/lib/puppet/generate/models/type/type.rb +4 -0
- data/lib/puppet/generate/templates/type/pcore.erb +2 -1
- data/lib/puppet/indirector/face.rb +6 -1
- data/lib/puppet/network/http/error.rb +2 -2
- data/lib/puppet/network/http/handler.rb +2 -2
- data/lib/puppet/node/environment.rb +11 -0
- data/lib/puppet/parser/ast.rb +5 -0
- data/lib/puppet/parser/ast/pops_bridge.rb +17 -4
- data/lib/puppet/parser/compiler.rb +29 -1
- data/lib/puppet/parser/functions.rb +6 -0
- data/lib/puppet/parser/functions/assert_type.rb +1 -1
- data/lib/puppet/parser/functions/binary_file.rb +24 -0
- data/lib/puppet/parser/functions/break.rb +39 -0
- data/lib/puppet/parser/functions/contain.rb +7 -15
- data/lib/puppet/parser/functions/defined.rb +2 -2
- data/lib/puppet/parser/functions/dig.rb +1 -1
- data/lib/puppet/parser/functions/each.rb +1 -1
- data/lib/puppet/parser/functions/epp.rb +2 -2
- data/lib/puppet/parser/functions/filter.rb +1 -1
- data/lib/puppet/parser/functions/find_file.rb +28 -0
- data/lib/puppet/parser/functions/hiera.rb +4 -4
- data/lib/puppet/parser/functions/hiera_array.rb +1 -1
- data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
- data/lib/puppet/parser/functions/hiera_include.rb +1 -1
- data/lib/puppet/parser/functions/include.rb +4 -8
- data/lib/puppet/parser/functions/inline_epp.rb +1 -1
- data/lib/puppet/parser/functions/lest.rb +1 -1
- data/lib/puppet/parser/functions/lookup.rb +4 -2
- data/lib/puppet/parser/functions/map.rb +1 -1
- data/lib/puppet/parser/functions/match.rb +1 -1
- data/lib/puppet/parser/functions/new.rb +414 -18
- data/lib/puppet/parser/functions/next.rb +38 -0
- data/lib/puppet/parser/functions/reduce.rb +1 -1
- data/lib/puppet/parser/functions/regsubst.rb +4 -2
- data/lib/puppet/parser/functions/require.rb +4 -27
- data/lib/puppet/parser/functions/return.rb +71 -0
- data/lib/puppet/parser/functions/reverse_each.rb +1 -1
- data/lib/puppet/parser/functions/scanf.rb +13 -8
- data/lib/puppet/parser/functions/slice.rb +1 -1
- data/lib/puppet/parser/functions/split.rb +1 -1
- data/lib/puppet/parser/functions/step.rb +1 -1
- data/lib/puppet/parser/functions/strftime.rb +185 -0
- data/lib/puppet/parser/functions/then.rb +1 -1
- data/lib/puppet/parser/functions/type.rb +1 -1
- data/lib/puppet/parser/functions/with.rb +3 -3
- data/lib/puppet/parser/resource.rb +8 -5
- data/lib/puppet/parser/scope.rb +1 -1
- data/lib/puppet/plugins/configuration.rb +8 -0
- data/lib/puppet/plugins/data_providers.rb +1 -0
- data/lib/puppet/plugins/data_providers/data_provider.rb +7 -28
- data/lib/puppet/plugins/data_providers/registry.rb +1 -0
- data/lib/puppet/pops.rb +4 -0
- data/lib/puppet/pops/evaluator/access_operator.rb +36 -5
- data/lib/puppet/pops/evaluator/closure.rb +81 -12
- data/lib/puppet/pops/evaluator/compare_operator.rb +24 -1
- data/lib/puppet/pops/evaluator/evaluator_impl.rb +29 -5
- data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +1 -1
- data/lib/puppet/pops/evaluator/runtime3_converter.rb +53 -62
- data/lib/puppet/pops/evaluator/runtime3_support.rb +15 -6
- data/lib/puppet/pops/functions/dispatch.rb +9 -2
- data/lib/puppet/pops/functions/dispatcher.rb +3 -1
- data/lib/puppet/pops/functions/function.rb +19 -2
- data/lib/puppet/pops/issues.rb +9 -0
- data/lib/puppet/pops/label_provider.rb +2 -2
- data/lib/puppet/pops/loader/loader.rb +17 -0
- data/lib/puppet/pops/loader/static_loader.rb +0 -41
- data/lib/puppet/pops/lookup.rb +12 -0
- data/lib/puppet/pops/lookup/context.rb +86 -0
- data/lib/puppet/pops/lookup/explainer.rb +46 -6
- data/lib/puppet/pops/lookup/invocation.rb +19 -0
- data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
- data/lib/puppet/pops/model/factory.rb +20 -8
- data/lib/puppet/pops/model/model_label_provider.rb +3 -0
- data/lib/puppet/pops/model/model_meta.rb +2 -0
- data/lib/puppet/pops/model/model_tree_dumper.rb +14 -0
- data/lib/puppet/pops/parser/egrammar.ra +11 -6
- data/lib/puppet/pops/parser/eparser.rb +1112 -1086
- data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
- data/lib/puppet/pops/pcore.rb +1 -0
- data/lib/puppet/pops/puppet_stack.rb +3 -3
- data/lib/puppet/pops/resource/param.rb +5 -1
- data/lib/puppet/pops/resource/resource_type_impl.rb +8 -4
- data/lib/puppet/pops/resource/resource_type_set.pcore +1 -0
- data/lib/puppet/pops/serialization/abstract_reader.rb +19 -2
- data/lib/puppet/pops/serialization/abstract_writer.rb +16 -3
- data/lib/puppet/pops/serialization/deserializer.rb +5 -1
- data/lib/puppet/pops/serialization/extension.rb +2 -0
- data/lib/puppet/pops/serialization/json.rb +76 -26
- data/lib/puppet/pops/serialization/serializer.rb +5 -1
- data/lib/puppet/pops/serialization/time_factory.rb +2 -1
- data/lib/puppet/pops/time/timespan.rb +718 -0
- data/lib/puppet/pops/time/timestamp.rb +148 -0
- data/lib/puppet/pops/types/p_binary_type.rb +220 -0
- data/lib/puppet/pops/types/p_object_type.rb +12 -6
- data/lib/puppet/pops/types/p_sensitive_type.rb +5 -1
- data/lib/puppet/pops/types/p_timespan_type.rb +141 -0
- data/lib/puppet/pops/types/p_timestamp_type.rb +69 -0
- data/lib/puppet/pops/types/string_converter.rb +62 -0
- data/lib/puppet/pops/types/type_asserter.rb +1 -1
- data/lib/puppet/pops/types/type_calculator.rb +17 -3
- data/lib/puppet/pops/types/type_factory.rb +35 -1
- data/lib/puppet/pops/types/type_formatter.rb +64 -11
- data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -61
- data/lib/puppet/pops/types/type_parser.rb +18 -4
- data/lib/puppet/pops/types/types.rb +98 -63
- data/lib/puppet/pops/validation.rb +9 -1
- data/lib/puppet/pops/validation/checker4_0.rb +7 -0
- data/lib/puppet/property.rb +1 -1
- data/lib/puppet/provider.rb +3 -6
- data/lib/puppet/provider/mcx/mcxcontent.rb +1 -1
- data/lib/puppet/provider/mount/parsed.rb +18 -4
- data/lib/puppet/provider/nameservice/directoryservice.rb +15 -7
- data/lib/puppet/provider/package/gem.rb +6 -1
- data/lib/puppet/provider/package/pip.rb +0 -1
- data/lib/puppet/provider/package/pkg.rb +5 -1
- data/lib/puppet/provider/package/pkgng.rb +1 -1
- data/lib/puppet/provider/package/yum.rb +10 -0
- data/lib/puppet/provider/service/launchd.rb +1 -0
- data/lib/puppet/provider/user/directoryservice.rb +6 -6
- data/lib/puppet/provider/yumrepo/inifile.rb +1 -1
- data/lib/puppet/provider/zpool/zpool.rb +1 -1
- data/lib/puppet/resource.rb +54 -12
- data/lib/puppet/resource/capability_finder.rb +15 -9
- data/lib/puppet/resource/catalog.rb +25 -6
- data/lib/puppet/resource/type.rb +3 -1
- data/lib/puppet/settings.rb +1 -1
- data/lib/puppet/settings/environment_conf.rb +12 -4
- data/lib/puppet/syntax_checkers/base64.rb +41 -0
- data/lib/puppet/syntax_checkers/json.rb +0 -2
- data/lib/puppet/transaction.rb +6 -0
- data/lib/puppet/transaction/additional_resource_generator.rb +5 -0
- data/lib/puppet/transaction/report.rb +7 -2
- data/lib/puppet/type.rb +2 -1
- data/lib/puppet/type/file/checksum.rb +1 -0
- data/lib/puppet/type/file/content.rb +4 -4
- data/lib/puppet/type/mount.rb +44 -0
- data/lib/puppet/type/ssh_authorized_key.rb +1 -1
- data/lib/puppet/type/tidy.rb +3 -0
- data/lib/puppet/type/user.rb +12 -6
- data/lib/puppet/util/log.rb +25 -0
- data/lib/puppet/util/plist.rb +8 -3
- data/lib/puppet/version.rb +1 -1
- data/lib/puppet_x.rb +7 -1
- data/spec/integration/application/apply_spec.rb +118 -0
- data/spec/integration/parser/compiler_spec.rb +28 -0
- data/spec/integration/parser/pcore_resource_spec.rb +40 -3
- data/spec/integration/provider/mount_spec.rb +2 -1
- data/spec/integration/util/windows/principal_spec.rb +2 -2
- data/spec/integration/util/windows/registry_spec.rb +4 -4
- data/spec/lib/puppet_spec/compiler.rb +5 -1
- data/spec/lib/puppet_spec/unindent.rb +5 -0
- data/spec/shared_contexts/types_setup.rb +6 -0
- data/spec/shared_examples/rhel_package_provider.rb +16 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/agent_spec.rb +11 -0
- data/spec/unit/application/lookup_spec.rb +94 -3
- data/spec/unit/capability_spec.rb +22 -0
- data/spec/unit/configurer_spec.rb +8 -0
- data/spec/unit/face/epp_face_spec.rb +22 -3
- data/spec/unit/functions/assert_type_spec.rb +3 -3
- data/spec/unit/functions/binary_file_spec.rb +46 -0
- data/spec/unit/functions/break_spec.rb +89 -0
- data/spec/unit/{parser/functions → functions}/contain_spec.rb +68 -3
- data/spec/unit/functions/find_file_spec.rb +69 -0
- data/spec/unit/functions/include_spec.rb +175 -0
- data/spec/unit/functions/logging_spec.rb +54 -0
- data/spec/unit/functions/lookup_spec.rb +3 -3
- data/spec/unit/functions/new_spec.rb +105 -5
- data/spec/unit/functions/next_spec.rb +93 -0
- data/spec/unit/functions/require_spec.rb +83 -0
- data/spec/unit/functions/return_spec.rb +105 -0
- data/spec/unit/{parser/functions → functions}/shared.rb +14 -11
- data/spec/unit/functions/strftime_spec.rb +152 -0
- data/spec/unit/functions4_spec.rb +22 -0
- data/spec/unit/indirector/face_spec.rb +10 -2
- data/spec/unit/network/http/error_spec.rb +1 -2
- data/spec/unit/network/http/handler_spec.rb +6 -5
- data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
- data/spec/unit/parser/functions/hiera_spec.rb +1 -1
- data/spec/unit/parser/functions/lookup_spec.rb +1 -1
- data/spec/unit/parser/functions/regsubst_spec.rb +1 -1
- data/spec/unit/parser/functions/split_spec.rb +1 -1
- data/spec/unit/pops/evaluator/access_ops_spec.rb +81 -1
- data/spec/unit/pops/evaluator/arithmetic_ops_spec.rb +170 -0
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +29 -4
- data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +112 -4
- data/spec/unit/pops/loaders/dependency_loader_spec.rb +12 -0
- data/spec/unit/pops/loaders/static_loader_spec.rb +0 -26
- data/spec/unit/pops/lookup/context_spec.rb +149 -0
- data/spec/unit/pops/parser/parse_functions_spec.rb +19 -0
- data/spec/unit/pops/parser/parse_lambda_spec.rb +19 -0
- data/spec/unit/pops/puppet_stack_spec.rb +1 -1
- data/spec/unit/pops/resource/resource_type_impl_spec.rb +74 -0
- data/spec/unit/pops/serialization/packer_spec.rb +34 -14
- data/spec/unit/pops/serialization/serialization_spec.rb +67 -5
- data/spec/unit/pops/time/timespan_spec.rb +121 -0
- data/spec/unit/pops/types/p_binary_type_spec.rb +243 -0
- data/spec/unit/pops/types/p_object_type_spec.rb +7 -7
- data/spec/unit/pops/types/p_sensitive_type_spec.rb +1 -1
- data/spec/unit/pops/types/p_timespan_type_spec.rb +273 -0
- data/spec/unit/pops/types/p_timestamp_type_spec.rb +311 -0
- data/spec/unit/pops/types/p_type_set_type_spec.rb +13 -13
- data/spec/unit/pops/types/ruby_generator_spec.rb +12 -12
- data/spec/unit/pops/types/string_converter_spec.rb +89 -0
- data/spec/unit/pops/types/type_asserter_spec.rb +3 -3
- data/spec/unit/pops/types/type_calculator_spec.rb +113 -5
- data/spec/unit/pops/types/type_formatter_spec.rb +40 -0
- data/spec/unit/pops/types/type_mismatch_describer_spec.rb +49 -38
- data/spec/unit/pops/types/type_parser_spec.rb +87 -4
- data/spec/unit/pops/types/types_spec.rb +1 -1
- data/spec/unit/pops/validator/validator_spec.rb +23 -0
- data/spec/unit/provider/mount/parsed_spec.rb +47 -29
- data/spec/unit/provider/package/pkg_spec.rb +109 -99
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -0
- data/spec/unit/provider/user/aix_spec.rb +1 -1
- data/spec/unit/provider/user/directoryservice_spec.rb +101 -30
- data/spec/unit/resource/capability_finder_spec.rb +29 -7
- data/spec/unit/resource/catalog_spec.rb +127 -0
- data/spec/unit/ssl/certificate_request_spec.rb +1 -1
- data/spec/unit/transaction/additional_resource_generator_spec.rb +30 -0
- data/spec/unit/transaction/persistence_spec.rb +1 -6
- data/spec/unit/transaction/report_spec.rb +23 -0
- data/spec/unit/transaction_spec.rb +38 -0
- data/spec/unit/type/mount_spec.rb +5 -0
- data/spec/unit/util/plist_spec.rb +14 -2
- metadata +71 -12
- data/spec/integration/parser/functions/require_spec.rb +0 -43
- data/spec/unit/parser/functions/include_spec.rb +0 -55
- data/spec/unit/parser/functions/require_spec.rb +0 -68
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'puppet/pops'
|
3
|
+
require_relative 'parser_rspec_helper'
|
4
|
+
|
5
|
+
describe 'egrammar parsing function definitions' do
|
6
|
+
include ParserRspecHelper
|
7
|
+
|
8
|
+
context 'without return type' do
|
9
|
+
it 'function foo() { 1 }' do
|
10
|
+
expect(dump(parse('function foo() { 1 }'))).to eq("(function foo (block\n 1\n))")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with return type' do
|
15
|
+
it 'function foo() >> Integer { 1 }' do
|
16
|
+
expect(dump(parse('function foo() >> Integer { 1 }'))).to eq("(function foo (return_type integer) (block\n 1\n))")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'puppet/pops'
|
3
|
+
require_relative 'parser_rspec_helper'
|
4
|
+
|
5
|
+
describe 'egrammar parsing lambda definitions' do
|
6
|
+
include ParserRspecHelper
|
7
|
+
|
8
|
+
context 'without return type' do
|
9
|
+
it 'f() |$x| { 1 }' do
|
10
|
+
expect(dump(parse('f() |$x| { 1 }'))).to eq("(invoke f (lambda (parameters x) (block\n 1\n)))")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with return type' do
|
15
|
+
it 'f() |$x| >> Integer { 1 }' do
|
16
|
+
expect(dump(parse('f() |$x| >> Integer { 1 }'))).to eq("(invoke f (lambda (parameters x) (return_type integer) (block\n 1\n)))")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -50,7 +50,7 @@ describe 'Puppet::Pops::PuppetStack' do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'returns an array from stacktrace with information about each level with oldest frame last' do
|
53
|
-
expect(StackTraceTest.new.two_levels).to eql([['
|
53
|
+
expect(StackTraceTest.new.two_levels).to eql([['level2.pp', 1240], ['two_levels.pp', 1237]])
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'accepts file to be nil' do
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'puppet/pops'
|
4
|
+
require 'puppet_spec/files'
|
4
5
|
require 'puppet_spec/compiler'
|
5
6
|
|
6
7
|
module Puppet::Pops
|
@@ -32,6 +33,79 @@ describe "Puppet::Pops::Resource" do
|
|
32
33
|
expect(rt.valid_parameter?(:loglevel)).to be_truthy
|
33
34
|
end
|
34
35
|
end
|
36
|
+
|
37
|
+
|
38
|
+
context 'when used with capability resource with producers/consumers' do
|
39
|
+
include PuppetSpec::Files
|
40
|
+
|
41
|
+
let!(:env_name) { 'spec' }
|
42
|
+
let!(:env_dir) { tmpdir('environments') }
|
43
|
+
let!(:populated_env_dir) do
|
44
|
+
dir_contained_in(env_dir, env_name => {
|
45
|
+
'.resource_types' => {
|
46
|
+
'capability.pp' => <<-PUPPET
|
47
|
+
Puppet::Resource::ResourceType3.new(
|
48
|
+
'capability',
|
49
|
+
[],
|
50
|
+
[Puppet::Resource::Param(Any, 'name', true)],
|
51
|
+
{ /(.*)/ => ['name'] },
|
52
|
+
true,
|
53
|
+
true)
|
54
|
+
PUPPET
|
55
|
+
},
|
56
|
+
'modules' => {
|
57
|
+
'test' => {
|
58
|
+
'lib' => {
|
59
|
+
'puppet' => {
|
60
|
+
'type' => { 'capability.rb' => <<-RUBY
|
61
|
+
Puppet::Type.newtype(:capability, :is_capability => true) do
|
62
|
+
newparam :name, :namevar => true
|
63
|
+
raise Puppet::Error, 'Ruby resource was loaded'
|
64
|
+
end
|
65
|
+
RUBY
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
})
|
72
|
+
end
|
73
|
+
|
74
|
+
let!(:code) { <<-PUPPET }
|
75
|
+
define producer() {
|
76
|
+
notify { "producer":}
|
77
|
+
}
|
78
|
+
|
79
|
+
define consumer() {
|
80
|
+
notify { $title:}
|
81
|
+
}
|
82
|
+
|
83
|
+
Producer produces Capability {}
|
84
|
+
|
85
|
+
Consumer consumes Capability {}
|
86
|
+
|
87
|
+
producer {x: export => Capability[cap]}
|
88
|
+
consumer {x: consume => Capability[cap]}
|
89
|
+
consumer {y: require => Capability[cap]}
|
90
|
+
PUPPET
|
91
|
+
|
92
|
+
let(:environments) { Puppet::Environments::Directories.new(populated_env_dir, []) }
|
93
|
+
let(:env) { Puppet::Node::Environment.create(:'spec', [File.join(env_dir, 'spec', 'modules')]) }
|
94
|
+
let(:node) { Puppet::Node.new('test', :environment => env) }
|
95
|
+
around(:each) do |example|
|
96
|
+
Puppet[:app_management] = true
|
97
|
+
Puppet[:environment] = env_name
|
98
|
+
Puppet.override(:environments => environments, :current_environment => env) do
|
99
|
+
example.run
|
100
|
+
end
|
101
|
+
Puppet::Type.rmtype(:capability)
|
102
|
+
Puppet[:app_management] = false
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'does not load the Ruby resource' do
|
106
|
+
expect { compile_to_catalog(code, node) }.not_to raise_error
|
107
|
+
end
|
108
|
+
end
|
35
109
|
end
|
36
110
|
end
|
37
111
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'puppet/pops/serialization'
|
3
3
|
|
4
|
-
module Puppet::Pops
|
4
|
+
module Puppet::Pops
|
5
|
+
module Serialization
|
5
6
|
[JSON].each do |packer_module|
|
6
7
|
describe "the Puppet::Pops::Serialization when using #{packer_module.name}" do
|
7
8
|
let(:io) { StringIO.new }
|
@@ -21,7 +22,7 @@ describe "the Puppet::Pops::Serialization when using #{packer_module.name}" do
|
|
21
22
|
count.nil? ? @deserializer.read : Array.new(count) { @deserializer.read }
|
22
23
|
end
|
23
24
|
|
24
|
-
context 'can write and read a
|
25
|
+
context 'can write and read a' do
|
25
26
|
it 'String' do
|
26
27
|
val = 'the value'
|
27
28
|
write(val)
|
@@ -86,11 +87,28 @@ describe "the Puppet::Pops::Serialization when using #{packer_module.name}" do
|
|
86
87
|
expect(val2).to eql(val)
|
87
88
|
end
|
88
89
|
|
89
|
-
it '
|
90
|
-
|
90
|
+
it 'Sensitive' do
|
91
|
+
sval = 'the sensitive value'
|
92
|
+
val = Types::PSensitiveType::Sensitive.new(sval)
|
91
93
|
write(val)
|
92
94
|
val2 = read
|
93
|
-
expect(val2).to be_a(
|
95
|
+
expect(val2).to be_a(Types::PSensitiveType::Sensitive)
|
96
|
+
expect(val2.unwrap).to eql(sval)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'Timespan' do
|
100
|
+
val = Time::Timespan.from_fields(false, 3, 12, 40, 31, 123)
|
101
|
+
write(val)
|
102
|
+
val2 = read
|
103
|
+
expect(val2).to be_a(Time::Timespan)
|
104
|
+
expect(val2).to eql(val)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'Timestamp' do
|
108
|
+
val = Time::Timestamp.now
|
109
|
+
write(val)
|
110
|
+
val2 = read
|
111
|
+
expect(val2).to be_a(Time::Timestamp)
|
94
112
|
expect(val2).to eql(val)
|
95
113
|
end
|
96
114
|
|
@@ -110,21 +128,22 @@ describe "the Puppet::Pops::Serialization when using #{packer_module.name}" do
|
|
110
128
|
expect(val2).to eql(val)
|
111
129
|
end
|
112
130
|
|
113
|
-
it '
|
114
|
-
val =
|
115
|
-
val = TimeFactory.at(val.tv_sec, val.tv_nsec / 1000 + 0.123)
|
131
|
+
it 'Binary' do
|
132
|
+
val = Types::PBinaryType::Binary.from_base64('w5ZzdGVuIG1lZCByw7ZzdGVuCg==')
|
116
133
|
write(val)
|
117
134
|
val2 = read
|
118
|
-
expect(
|
135
|
+
expect(val2).to be_a(Types::PBinaryType::Binary)
|
136
|
+
expect(val2).to eql(val)
|
119
137
|
end
|
120
138
|
|
121
|
-
|
122
|
-
|
123
|
-
val =
|
124
|
-
val = Time.at(val.tv_sec, val.tv_nsec / 1000 + 0.123)
|
139
|
+
it 'Sensitive with rich data' do
|
140
|
+
sval = Time::Timestamp.now
|
141
|
+
val = Types::PSensitiveType::Sensitive.new(sval)
|
125
142
|
write(val)
|
126
143
|
val2 = read
|
127
|
-
expect(
|
144
|
+
expect(val2).to be_a(Types::PSensitiveType::Sensitive)
|
145
|
+
expect(val2.unwrap).to be_a(Time::Timestamp)
|
146
|
+
expect(val2.unwrap).to eql(sval)
|
128
147
|
end
|
129
148
|
end
|
130
149
|
|
@@ -151,3 +170,4 @@ describe "the Puppet::Pops::Serialization when using #{packer_module.name}" do
|
|
151
170
|
end
|
152
171
|
end
|
153
172
|
end
|
173
|
+
end
|
@@ -37,7 +37,7 @@ module Serialization
|
|
37
37
|
parser.parse_string(string, '/home/tester/experiments/manifests/init.pp').current
|
38
38
|
end
|
39
39
|
|
40
|
-
context 'can write and read a
|
40
|
+
context 'can write and read a' do
|
41
41
|
it 'String' do
|
42
42
|
val = 'the value'
|
43
43
|
write(val)
|
@@ -94,12 +94,28 @@ module Serialization
|
|
94
94
|
expect(val2).to eql(val)
|
95
95
|
end
|
96
96
|
|
97
|
-
it '
|
98
|
-
|
99
|
-
val =
|
97
|
+
it 'Sensitive' do
|
98
|
+
sval = 'the sensitive value'
|
99
|
+
val = Types::PSensitiveType::Sensitive.new(sval)
|
100
|
+
write(val)
|
101
|
+
val2 = read
|
102
|
+
expect(val2).to be_a(Types::PSensitiveType::Sensitive)
|
103
|
+
expect(val2.unwrap).to eql(sval)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'Timespan' do
|
107
|
+
val = Time::Timespan.from_fields(false, 3, 12, 40, 31, 123)
|
100
108
|
write(val)
|
101
109
|
val2 = read
|
102
|
-
expect(val2).to be_a(Time)
|
110
|
+
expect(val2).to be_a(Time::Timespan)
|
111
|
+
expect(val2).to eql(val)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'Timestamp' do
|
115
|
+
val = Time::Timestamp.now
|
116
|
+
write(val)
|
117
|
+
val2 = read
|
118
|
+
expect(val2).to be_a(Time::Timestamp)
|
103
119
|
expect(val2).to eql(val)
|
104
120
|
end
|
105
121
|
|
@@ -120,6 +136,24 @@ module Serialization
|
|
120
136
|
expect(val2).to be_a(Semantic::VersionRange)
|
121
137
|
expect(val2).to eql(val)
|
122
138
|
end
|
139
|
+
|
140
|
+
it 'Binary' do
|
141
|
+
val = Types::PBinaryType::Binary.from_base64('w5ZzdGVuIG1lZCByw7ZzdGVuCg==')
|
142
|
+
write(val)
|
143
|
+
val2 = read
|
144
|
+
expect(val2).to be_a(Types::PBinaryType::Binary)
|
145
|
+
expect(val2).to eql(val)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'Sensitive with rich data' do
|
149
|
+
sval = Time::Timestamp.now
|
150
|
+
val = Types::PSensitiveType::Sensitive.new(sval)
|
151
|
+
write(val)
|
152
|
+
val2 = read
|
153
|
+
expect(val2).to be_a(Types::PSensitiveType::Sensitive)
|
154
|
+
expect(val2.unwrap).to be_a(Time::Timestamp)
|
155
|
+
expect(val2.unwrap).to eql(sval)
|
156
|
+
end
|
123
157
|
end
|
124
158
|
|
125
159
|
context 'can write and read' do
|
@@ -169,6 +203,34 @@ module Serialization
|
|
169
203
|
end
|
170
204
|
end
|
171
205
|
|
206
|
+
it 'Array of rich data' do
|
207
|
+
# Sensitive omitted because it doesn't respond to ==
|
208
|
+
val = [
|
209
|
+
Time::Timespan.from_fields(false, 3, 12, 40, 31, 123),
|
210
|
+
Time::Timestamp.now,
|
211
|
+
Semantic::Version.parse('1.2.3-alpha2'),
|
212
|
+
Semantic::VersionRange.parse('>=1.2.3-alpha2 <1.2.4'),
|
213
|
+
Types::PBinaryType::Binary.from_base64('w5ZzdGVuIG1lZCByw7ZzdGVuCg==')
|
214
|
+
]
|
215
|
+
write(val)
|
216
|
+
val2 = read
|
217
|
+
expect(val2).to eql(val)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'Hash of rich data' do
|
221
|
+
# Sensitive omitted because it doesn't respond to ==
|
222
|
+
val = {
|
223
|
+
'duration' => Time::Timespan.from_fields(false, 3, 12, 40, 31, 123),
|
224
|
+
'time' => Time::Timestamp.now,
|
225
|
+
'version' => Semantic::Version.parse('1.2.3-alpha2'),
|
226
|
+
'range' => Semantic::VersionRange.parse('>=1.2.3-alpha2 <1.2.4'),
|
227
|
+
'binary' => Types::PBinaryType::Binary.from_base64('w5ZzdGVuIG1lZCByw7ZzdGVuCg==')
|
228
|
+
}
|
229
|
+
write(val)
|
230
|
+
val2 = read
|
231
|
+
expect(val2).to eql(val)
|
232
|
+
end
|
233
|
+
|
172
234
|
context 'an AST model' do
|
173
235
|
it "Locator" do
|
174
236
|
val = Parser::Locator::Locator19.new('here is some text', '/tmp/foo', [5])
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'puppet/pops'
|
3
|
+
require 'puppet_spec/compiler'
|
4
|
+
|
5
|
+
module Puppet::Pops
|
6
|
+
module Time
|
7
|
+
describe 'Timespan' do
|
8
|
+
include PuppetSpec::Compiler
|
9
|
+
|
10
|
+
let! (:simple) { Timespan.from_fields(false, 1, 3, 10, 11) }
|
11
|
+
let! (:all_fields_hash) { {'days' => 1, 'hours' => 7, 'minutes' => 10, 'seconds' => 11, 'milliseconds' => 123, 'microseconds' => 456, 'nanoseconds' => 789} }
|
12
|
+
let! (:complex) { Timespan.from_fields_hash(all_fields_hash) }
|
13
|
+
|
14
|
+
context 'can be created from a String' do
|
15
|
+
it 'using default format' do
|
16
|
+
expect(Timespan.parse('1-03:10:11')).to eql(simple)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'using explicit format' do
|
20
|
+
expect(Timespan.parse('1-7:10:11.123456789', '%D-%H:%M:%S.%N')).to eql(complex)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'using leading minus and explicit format' do
|
24
|
+
expect(Timespan.parse('-1-7:10:11.123456789', '%D-%H:%M:%S.%N')).to eql(-complex)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'using %H as the biggest quantity' do
|
28
|
+
expect(Timespan.parse('27:10:11', '%H:%M:%S')).to eql(simple)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'using %M as the biggest quantity' do
|
32
|
+
expect(Timespan.parse('1630:11', '%M:%S')).to eql(simple)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'using %S as the biggest quantity' do
|
36
|
+
expect(Timespan.parse('97811', '%S')).to eql(simple)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'where biggest quantity is not frist' do
|
40
|
+
expect(Timespan.parse('11:1630', '%S:%M')).to eql(simple)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raises an error when using %L as the biggest quantity' do
|
44
|
+
expect { Timespan.parse('123', '%L') }.to raise_error(ArgumentError, /denotes fractions and must be used together with a specifier of higher magnitude/)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'raises an error when using %N as the biggest quantity' do
|
48
|
+
expect { Timespan.parse('123', '%N') }.to raise_error(ArgumentError, /denotes fractions and must be used together with a specifier of higher magnitude/)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'where %L is treated as fractions of a second' do
|
52
|
+
expect(Timespan.parse('0.4', '%S.%L')).to eql(Timespan.from_fields(false, 0, 0, 0, 0, 400))
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'where %N is treated as fractions of a second' do
|
56
|
+
expect(Timespan.parse('0.4', '%S.%N')).to eql(Timespan.from_fields(false, 0, 0, 0, 0, 400))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when presented as a String' do
|
61
|
+
it 'uses default format for #to_s' do
|
62
|
+
expect(simple.to_s).to eql('1-03:10:11.0')
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'using a format' do
|
66
|
+
it 'produces a string containing all components' do
|
67
|
+
expect(complex.format('%D-%H:%M:%S.%N')).to eql('1-07:10:11.123456789')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'produces a literal % for %%' do
|
71
|
+
expect(complex.format('%D%%%H:%M:%S')).to eql('1%07:10:11')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'produces a leading dash for negative instance' do
|
75
|
+
expect((-complex).format('%D-%H:%M:%S')).to eql('-1-07:10:11')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'produces a string without trailing zeros for %-N' do
|
79
|
+
expect(Timespan.parse('2.345', '%S.%N').format('%-S.%-N')).to eql('2.345')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'produces a string with trailing zeros for %N' do
|
83
|
+
expect(Timespan.parse('2.345', '%S.%N').format('%-S.%N')).to eql('2.345000000')
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'produces a string with trailing zeros for %0N' do
|
87
|
+
expect(Timespan.parse('2.345', '%S.%N').format('%-S.%0N')).to eql('2.345000000')
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'produces a string with trailing spaces for %_N' do
|
91
|
+
expect(Timespan.parse('2.345', '%S.%N').format('%-S.%_N')).to eql('2.345 ')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when converted to a hash' do
|
97
|
+
it 'produces a hash with all numeric keys' do
|
98
|
+
hash = complex.to_hash
|
99
|
+
expect(hash).to eql(all_fields_hash)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'produces a compact hash with seconds and nanoseconds for #to_hash(true)' do
|
103
|
+
hash = complex.to_hash(true)
|
104
|
+
expect(hash).to eql({'seconds' => 112211, 'nanoseconds' => 123456789})
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'from a negative value' do
|
108
|
+
it 'produces a hash with all numeric keys and negative = true' do
|
109
|
+
hash = (-complex).to_hash
|
110
|
+
expect(hash).to eql(all_fields_hash.merge('negative' => true))
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'produces a compact hash with negative seconds and negative nanoseconds for #to_hash(true)' do
|
114
|
+
hash = (-complex).to_hash(true)
|
115
|
+
expect(hash).to eql({'seconds' => -112211, 'nanoseconds' => -123456789})
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,243 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'puppet/pops'
|
3
|
+
require 'puppet_spec/compiler'
|
4
|
+
|
5
|
+
module Puppet::Pops
|
6
|
+
module Types
|
7
|
+
describe 'Binary Type' do
|
8
|
+
include PuppetSpec::Compiler
|
9
|
+
|
10
|
+
context 'as a type' do
|
11
|
+
it 'can be created with the type factory' do
|
12
|
+
t = TypeFactory.binary()
|
13
|
+
expect(t).to be_a(PBinaryType)
|
14
|
+
expect(t).to eql(PBinaryType::DEFAULT)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'a Binary instance' do
|
19
|
+
it 'can be created from a raw String using %r, raw string mode' do
|
20
|
+
str = [0xF1].pack("C*")
|
21
|
+
code = <<-CODE
|
22
|
+
$x = Binary($testing, '%r')
|
23
|
+
notice(assert_type(Binary, $x))
|
24
|
+
CODE
|
25
|
+
expect(eval_and_collect_notices(code, Puppet::Node.new('foonode'), { 'testing' => str })).to eql(['8Q=='])
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'can be created from a String using %s, string mode' do
|
29
|
+
# the text 'binar' needs padding with '='
|
30
|
+
code = <<-CODE
|
31
|
+
$x = Binary('binary', '%s')
|
32
|
+
notice(assert_type(Binary, $x))
|
33
|
+
CODE
|
34
|
+
expect(eval_and_collect_notices(code)).to eql(['YmluYXJ5'])
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'format %s errors if encoding is bad in given string when using format %s and a broken UTF-8 string' do
|
38
|
+
str = [0xF1].pack("C*")
|
39
|
+
str.force_encoding('UTF-8')
|
40
|
+
code = <<-CODE
|
41
|
+
$x = Binary($testing, '%s')
|
42
|
+
notice(assert_type(Binary, $x))
|
43
|
+
CODE
|
44
|
+
expect {
|
45
|
+
eval_and_collect_notices(code, Puppet::Node.new('foonode'), { 'testing' => str })
|
46
|
+
}.to raise_error(/.*The given string in encoding 'UTF-8' is invalid\. Cannot create a Binary UTF-8 representation.*/)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'format %s errors if encoding is correct but string cannot be transcoded to UTF-8' do
|
50
|
+
str = [0xF1].pack("C*")
|
51
|
+
code = <<-CODE
|
52
|
+
$x = Binary($testing, '%s')
|
53
|
+
notice(assert_type(Binary, $x))
|
54
|
+
CODE
|
55
|
+
expect {
|
56
|
+
eval_and_collect_notices(code, Puppet::Node.new('foonode'), { 'testing' => str })
|
57
|
+
}.to raise_error(/.*"\\xF1" from ASCII-8BIT to UTF-8.*/)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'can be created from a strict Base64 encoded String using default format' do
|
61
|
+
code = <<-CODE
|
62
|
+
$x = Binary('YmluYXI=')
|
63
|
+
notice(assert_type(Binary, $x))
|
64
|
+
CODE
|
65
|
+
expect(eval_and_collect_notices(code)).to eql(['YmluYXI='])
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'will error creation in strict mode if padding is missing when using default format' do
|
69
|
+
# the text 'binar' needs padding with '=' (missing here to trigger error
|
70
|
+
code = <<-CODE
|
71
|
+
$x = Binary('YmluYXI')
|
72
|
+
notice(assert_type(Binary, $x))
|
73
|
+
CODE
|
74
|
+
expect{ eval_and_collect_notices(code) }.to raise_error(/invalid base64/)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'can be created from a Base64 encoded String using %B, strict mode' do
|
78
|
+
# the text 'binar' needs padding with '='
|
79
|
+
code = <<-CODE
|
80
|
+
$x = Binary('YmluYXI=', '%B')
|
81
|
+
notice(assert_type(Binary, $x))
|
82
|
+
CODE
|
83
|
+
expect(eval_and_collect_notices(code)).to eql(['YmluYXI='])
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'will error creation in strict mode if padding is missing' do
|
87
|
+
# the text 'binar' needs padding with '=' (missing here to trigger error
|
88
|
+
code = <<-CODE
|
89
|
+
$x = Binary('YmluYXI', '%B')
|
90
|
+
notice(assert_type(Binary, $x))
|
91
|
+
CODE
|
92
|
+
expect{ eval_and_collect_notices(code) }.to raise_error(/invalid base64/)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'will not error creation in base mode if padding is missing' do
|
96
|
+
# the text 'binar' needs padding with '=' (missing here to trigger possible error)
|
97
|
+
code = <<-CODE
|
98
|
+
$x = Binary('YmluYXI', '%b')
|
99
|
+
notice(assert_type(Binary, $x))
|
100
|
+
CODE
|
101
|
+
expect(eval_and_collect_notices(code)).to eql(['YmluYXI='])
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'will not error creation in base mode if padding is not required' do
|
105
|
+
# the text 'binary' does not need padding with '='
|
106
|
+
code = <<-CODE
|
107
|
+
$x = Binary('YmluYXJ5', '%b')
|
108
|
+
notice(assert_type(Binary, $x))
|
109
|
+
CODE
|
110
|
+
expect(eval_and_collect_notices(code)).to eql(['YmluYXJ5'])
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'can be compared to another instance for equality' do
|
114
|
+
code = <<-CODE
|
115
|
+
$x = Binary('YmluYXJ5')
|
116
|
+
$y = Binary('YmluYXJ5')
|
117
|
+
notice($x == $y)
|
118
|
+
notice($x != $y)
|
119
|
+
CODE
|
120
|
+
expect(eval_and_collect_notices(code)).to eql(['true', 'false'])
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'can be created from an array of byte values' do
|
124
|
+
# the text 'binar' needs padding with '='
|
125
|
+
code = <<-CODE
|
126
|
+
$x = Binary([251, 239, 255])
|
127
|
+
notice(assert_type(Binary, $x))
|
128
|
+
CODE
|
129
|
+
expect(eval_and_collect_notices(code)).to eql(['++//'])
|
130
|
+
end
|
131
|
+
|
132
|
+
it "can be created from an hash with value and format" do
|
133
|
+
# the text 'binar' needs padding with '='
|
134
|
+
code = <<-CODE
|
135
|
+
$x = Binary({value => '--__', format => '%u'})
|
136
|
+
notice(assert_type(Binary, $x))
|
137
|
+
CODE
|
138
|
+
expect(eval_and_collect_notices(code)).to eql(['++//'])
|
139
|
+
end
|
140
|
+
|
141
|
+
it "can be created from an hash with value and default format" do
|
142
|
+
code = <<-CODE
|
143
|
+
$x = Binary({value => 'YmluYXI='})
|
144
|
+
notice(assert_type(Binary, $x))
|
145
|
+
CODE
|
146
|
+
expect(eval_and_collect_notices(code)).to eql(['YmluYXI='])
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'can be created from a hash with value being an array' do
|
150
|
+
# the text 'binar' needs padding with '='
|
151
|
+
code = <<-CODE
|
152
|
+
$x = Binary({value => [251, 239, 255]})
|
153
|
+
notice(assert_type(Binary, $x))
|
154
|
+
CODE
|
155
|
+
expect(eval_and_collect_notices(code)).to eql(['++//'])
|
156
|
+
end
|
157
|
+
|
158
|
+
it "can be created from an Base64 using URL safe encoding by specifying '%u' format'" do
|
159
|
+
# the text 'binar' needs padding with '='
|
160
|
+
code = <<-CODE
|
161
|
+
$x = Binary('--__', '%u')
|
162
|
+
notice(assert_type(Binary, $x))
|
163
|
+
CODE
|
164
|
+
expect(eval_and_collect_notices(code)).to eql(['++//'])
|
165
|
+
end
|
166
|
+
|
167
|
+
it "when created with URL safe encoding chars in '%b' format, these are skipped" do
|
168
|
+
code = <<-CODE
|
169
|
+
$x = Binary('--__YmluYXJ5', '%b')
|
170
|
+
notice(assert_type(Binary, $x))
|
171
|
+
CODE
|
172
|
+
expect(eval_and_collect_notices(code)).to eql(['YmluYXJ5'])
|
173
|
+
end
|
174
|
+
|
175
|
+
it "will error in strict format if string contains URL safe encoded chars" do
|
176
|
+
code = <<-CODE
|
177
|
+
$x = Binary('--__YmluYXJ5', '%B')
|
178
|
+
notice(assert_type(Binary, $x))
|
179
|
+
CODE
|
180
|
+
expect { eval_and_collect_notices(code) }.to raise_error(/invalid base64/)
|
181
|
+
end
|
182
|
+
|
183
|
+
[ '<',
|
184
|
+
'<=',
|
185
|
+
'>',
|
186
|
+
'>='
|
187
|
+
].each do |op|
|
188
|
+
it "cannot be compared to another instance for magnitude using #{op}" do
|
189
|
+
code = <<-"CODE"
|
190
|
+
$x = Binary('YmluYXJ5')
|
191
|
+
$y = Binary('YmluYXJ5')
|
192
|
+
$x #{op} $y
|
193
|
+
CODE
|
194
|
+
expect { eval_and_collect_notices(code)}.to raise_error(/Comparison of: Binary #{op} Binary, is not possible/)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'can be matched against a Binary in case expression' do
|
199
|
+
code = <<-CODE
|
200
|
+
case Binary('YmluYXJ5') {
|
201
|
+
Binary('YWxpZW4='): {
|
202
|
+
notice('nope')
|
203
|
+
}
|
204
|
+
Binary('YmluYXJ5'): {
|
205
|
+
notice('yay')
|
206
|
+
}
|
207
|
+
default: {
|
208
|
+
notice('nope')
|
209
|
+
}
|
210
|
+
}
|
211
|
+
CODE
|
212
|
+
expect(eval_and_collect_notices(code)).to eql(['yay'])
|
213
|
+
end
|
214
|
+
|
215
|
+
it "can be matched against a Binary subsequence using 'in' expression" do
|
216
|
+
# finding 'one' in 'one two three'
|
217
|
+
code = <<-CODE
|
218
|
+
notice(Binary("b25l") in Binary("b25lIHR3byB0aHJlZQ=="))
|
219
|
+
notice(Binary("c25l") in Binary("b25lIHR3byB0aHJlZQ=="))
|
220
|
+
CODE
|
221
|
+
expect(eval_and_collect_notices(code)).to eql(['true', 'false'])
|
222
|
+
end
|
223
|
+
|
224
|
+
it "can be matched against a byte value using 'in' expression" do
|
225
|
+
# finding 'e' (ascii 101) in 'one two three'
|
226
|
+
code = <<-CODE
|
227
|
+
notice(101 in Binary("b25lIHR3byB0aHJlZQ=="))
|
228
|
+
notice(101.0 in Binary("b25lIHR3byB0aHJlZQ=="))
|
229
|
+
notice(102 in Binary("b25lIHR3byB0aHJlZQ=="))
|
230
|
+
CODE
|
231
|
+
expect(eval_and_collect_notices(code)).to eql(['true', 'true', 'false'])
|
232
|
+
end
|
233
|
+
|
234
|
+
it "has a length method in ruby returning the length measured in bytes" do
|
235
|
+
# \u{1f452} is "woman's hat emoji - 4 bytes in UTF-8"
|
236
|
+
a_binary = PBinaryType::Binary.new("\u{1f452}")
|
237
|
+
expect(a_binary.length).to be(4)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|