puppet 4.4.2-x64-mingw32 → 4.5.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/CONTRIBUTING.md +5 -5
- data/Gemfile +2 -2
- data/LICENSE +2 -2
- data/README.md +5 -0
- data/ext/project_data.yaml +2 -0
- data/lib/hiera_puppet.rb +6 -14
- data/lib/puppet/application/agent.rb +2 -3
- data/lib/puppet/data_providers/hiera_config.rb +2 -4
- data/lib/puppet/data_providers/hiera_interpolate.rb +12 -154
- data/lib/puppet/data_providers/json_data_provider_factory.rb +0 -7
- data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -8
- data/lib/puppet/defaults.rb +70 -7
- data/lib/puppet/functions.rb +69 -0
- data/lib/puppet/functions/dig.rb +39 -0
- data/lib/puppet/functions/lest.rb +53 -0
- data/lib/puppet/functions/lookup.rb +40 -27
- data/lib/puppet/functions/new.rb +502 -0
- data/lib/puppet/functions/regsubst.rb +11 -10
- data/lib/puppet/functions/then.rb +74 -0
- data/lib/puppet/functions/type.rb +4 -4
- data/lib/puppet/functions/with.rb +1 -1
- data/lib/puppet/indirector/catalog/compiler.rb +2 -0
- data/lib/puppet/indirector/resource_type/parser.rb +5 -0
- data/lib/puppet/indirector/rest.rb +5 -1
- data/lib/puppet/loaders.rb +2 -0
- data/lib/puppet/metatype/manager.rb +19 -2
- data/lib/puppet/module_tool/applications/application.rb +1 -1
- data/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +6 -2
- data/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +19 -4
- data/lib/puppet/module_tool/skeleton/templates/generator/{tests → examples}/init.pp.erb +1 -1
- data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +0 -1
- data/lib/puppet/network/http/api/master/v3/environment.rb +6 -2
- data/lib/puppet/parser/ast/pops_bridge.rb +20 -3
- data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +24 -2
- data/lib/puppet/parser/e4_parser_adapter.rb +13 -12
- data/lib/puppet/parser/environment_compiler.rb +2 -2
- data/lib/puppet/parser/resource.rb +14 -5
- data/lib/puppet/parser/scope.rb +18 -15
- data/lib/puppet/plugins/data_providers/data_provider.rb +19 -8
- data/lib/puppet/pops.rb +6 -0
- data/lib/puppet/pops/adapters.rb +5 -1
- data/lib/puppet/pops/evaluator/access_operator.rb +52 -14
- data/lib/puppet/pops/evaluator/compare_operator.rb +34 -4
- data/lib/puppet/pops/evaluator/evaluator_impl.rb +75 -22
- data/lib/puppet/pops/evaluator/literal_evaluator.rb +7 -6
- data/lib/puppet/pops/evaluator/runtime3_converter.rb +13 -1
- data/lib/puppet/pops/evaluator/runtime3_support.rb +14 -4
- data/lib/puppet/pops/functions/dispatcher.rb +1 -1
- data/lib/puppet/pops/issues.rb +18 -2
- data/lib/puppet/pops/loader/base_loader.rb +48 -7
- data/lib/puppet/pops/loader/dependency_loader.rb +27 -2
- data/lib/puppet/pops/loader/loader.rb +12 -0
- data/lib/puppet/pops/loader/predefined_loader.rb +29 -0
- data/lib/puppet/pops/loader/runtime3_type_loader.rb +57 -0
- data/lib/puppet/pops/loader/static_loader.rb +92 -5
- data/lib/puppet/pops/loader/type_definition_instantiator.rb +25 -3
- data/lib/puppet/pops/loaders.rb +84 -14
- data/lib/puppet/pops/lookup/explainer.rb +38 -1
- data/lib/puppet/pops/lookup/interpolation.rb +115 -0
- data/lib/puppet/pops/lookup/sub_lookup.rb +86 -0
- data/lib/puppet/pops/model/ast_transformer.rb +8 -1
- data/lib/puppet/pops/model/factory.rb +31 -8
- data/lib/puppet/pops/model/model.rb +8 -0
- data/lib/puppet/pops/model/model_label_provider.rb +1 -0
- data/lib/puppet/pops/model/model_meta.rb +7 -1
- data/lib/puppet/pops/model/model_tree_dumper.rb +4 -0
- data/lib/puppet/pops/parser/egrammar.ra +24 -7
- data/lib/puppet/pops/parser/eparser.rb +863 -798
- data/lib/puppet/pops/parser/evaluating_parser.rb +4 -0
- data/lib/puppet/pops/parser/locator.rb +8 -4
- data/lib/puppet/pops/pcore.rb +30 -0
- data/lib/puppet/pops/types/class_loader.rb +2 -4
- data/lib/puppet/pops/types/implementation_registry.rb +146 -0
- data/lib/puppet/pops/types/iterable.rb +4 -4
- data/lib/puppet/pops/types/p_object_type.rb +846 -0
- data/lib/puppet/pops/types/p_runtime_type.rb +102 -0
- data/lib/puppet/pops/types/p_sem_ver_range_type.rb +164 -0
- data/lib/puppet/pops/types/p_sem_ver_type.rb +113 -0
- data/lib/puppet/pops/types/puppet_object.rb +21 -0
- data/lib/puppet/pops/types/ruby_generator.rb +258 -0
- data/lib/puppet/pops/types/string_converter.rb +922 -0
- data/lib/puppet/pops/types/type_calculator.rb +29 -5
- data/lib/puppet/pops/types/type_conversion_error.rb +15 -0
- data/lib/puppet/pops/types/type_factory.rb +49 -16
- data/lib/puppet/pops/types/type_formatter.rb +335 -112
- data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -29
- data/lib/puppet/pops/types/type_parser.rb +205 -197
- data/lib/puppet/pops/types/types.rb +481 -103
- data/lib/puppet/pops/validation.rb +1 -1
- data/lib/puppet/pops/validation/checker4_0.rb +66 -4
- data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
- data/lib/puppet/pops/visitor.rb +3 -1
- data/lib/puppet/property.rb +1 -1
- data/lib/puppet/provider/augeas/augeas.rb +1 -1
- data/lib/puppet/provider/package/pip.rb +64 -20
- data/lib/puppet/provider/package/rpm.rb +112 -0
- data/lib/puppet/provider/package/yum.rb +7 -68
- data/lib/puppet/provider/service/daemontools.rb +3 -3
- data/lib/puppet/provider/service/init.rb +4 -2
- data/lib/puppet/provider/service/runit.rb +3 -3
- data/lib/puppet/provider/service/smf.rb +6 -3
- data/lib/puppet/provider/service/systemd.rb +59 -73
- data/lib/puppet/reference/providers.rb +1 -2
- data/lib/puppet/resource.rb +54 -37
- data/lib/puppet/resource/catalog.rb +31 -29
- data/lib/puppet/resource/type_collection.rb +23 -8
- data/lib/puppet/settings.rb +4 -2
- data/lib/puppet/settings/base_setting.rb +9 -3
- data/lib/puppet/settings/symbolic_enum_setting.rb +17 -0
- data/lib/puppet/test/test_helper.rb +0 -1
- data/lib/puppet/type.rb +9 -3
- data/lib/puppet/type/exec.rb +17 -17
- data/lib/puppet/type/file.rb +12 -0
- data/lib/puppet/type/file/content.rb +6 -6
- data/lib/puppet/type/file/ensure.rb +4 -4
- data/lib/puppet/type/file/source.rb +4 -4
- data/lib/puppet/type/file/target.rb +2 -2
- data/lib/puppet/type/mount.rb +18 -1
- data/lib/puppet/type/package.rb +3 -3
- data/lib/puppet/type/schedule.rb +4 -4
- data/lib/puppet/type/service.rb +15 -0
- data/lib/puppet/type/sshkey.rb +5 -3
- data/lib/puppet/type/tidy.rb +3 -3
- data/lib/puppet/type/zone.rb +5 -5
- data/lib/puppet/util/feature.rb +1 -1
- data/lib/puppet/util/monkey_patches.rb +8 -0
- data/lib/puppet/util/network_device/cisco/device.rb +16 -6
- data/lib/puppet/util/network_device/cisco/interface.rb +5 -6
- data/lib/puppet/util/plist.rb +3 -3
- data/lib/puppet/version.rb +1 -1
- data/spec/fixtures/unit/application/environments/production/data/common.yaml +13 -0
- data/spec/fixtures/unit/data_providers/environments/production/modules/abc/lib/puppet/functions/abc/data.rb +2 -1
- data/spec/fixtures/unit/data_providers/environments/production/modules/abc/manifests/init.pp +2 -1
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/data/empty_key.json +1 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/hiera.yaml +5 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/manifests/init.pp +2 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/metadata.json +9 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/data/empty_key.yaml +1 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/hiera.yaml +5 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/manifests/init.pp +2 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/metadata.json +9 -0
- data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/data/empty.yaml +1 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/type/usee_type.rb +5 -0
- data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +6 -0
- data/spec/fixtures/unit/provider/service/smf/svcs.out +4 -3
- data/spec/integration/module_tool/tar/mini_spec.rb +27 -27
- data/spec/integration/parser/catalog_spec.rb +14 -2
- data/spec/integration/parser/compiler_spec.rb +94 -3
- data/spec/integration/parser/resource_expressions_spec.rb +1 -1
- data/spec/integration/resource/type_collection_spec.rb +8 -0
- data/spec/lib/puppet_spec/compiler.rb +11 -4
- data/spec/shared_contexts/types_setup.rb +4 -0
- data/spec/unit/application/lookup_spec.rb +91 -9
- data/spec/unit/appmgmt_spec.rb +44 -35
- data/spec/unit/capability_spec.rb +33 -53
- data/spec/unit/data_providers/function_data_provider_spec.rb +19 -1
- data/spec/unit/data_providers/hiera_data_provider_spec.rb +1 -1
- data/spec/unit/defaults_spec.rb +18 -0
- data/spec/unit/functions/assert_type_spec.rb +1 -1
- data/spec/unit/functions/dig_spec.rb +58 -0
- data/spec/unit/functions/lest_spec.rb +34 -0
- data/spec/unit/functions/lookup_spec.rb +108 -2
- data/spec/unit/functions/new_spec.rb +543 -0
- data/spec/unit/functions/regsubst_spec.rb +8 -0
- data/spec/unit/functions/then_spec.rb +40 -0
- data/spec/unit/functions4_spec.rb +78 -10
- data/spec/unit/hiera_puppet_spec.rb +49 -8
- data/spec/unit/indirector/resource_type/parser_spec.rb +5 -0
- data/spec/unit/indirector/rest_spec.rb +12 -0
- data/spec/unit/network/http/api/master/v3/environment_spec.rb +60 -0
- data/spec/unit/node/environment_spec.rb +10 -0
- data/spec/unit/parser/compiler_spec.rb +20 -1
- data/spec/unit/parser/functions/create_resources_spec.rb +2 -2
- data/spec/unit/parser/functions/shared.rb +1 -1
- data/spec/unit/parser/resource_spec.rb +8 -1
- data/spec/unit/parser/scope_spec.rb +45 -0
- data/spec/unit/pops/evaluator/access_ops_spec.rb +14 -0
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +13 -5
- data/spec/unit/pops/loaders/static_loader_spec.rb +92 -1
- data/spec/unit/{data_providers/hiera_interpolation_spec.rb → pops/lookup/interpolation_spec.rb} +7 -5
- data/spec/unit/pops/parser/lexer2_spec.rb +2 -9
- data/spec/unit/pops/parser/parse_application_spec.rb +3 -8
- data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +19 -0
- data/spec/unit/pops/parser/parse_capabilities_spec.rb +3 -10
- data/spec/unit/pops/parser/parse_site_spec.rb +19 -10
- data/spec/unit/pops/parser/parser_rspec_helper.rb +0 -4
- data/spec/unit/pops/types/enumeration_spec.rb +13 -12
- data/spec/unit/pops/types/iterable_spec.rb +2 -2
- data/spec/unit/pops/types/p_object_type_spec.rb +1060 -0
- data/spec/unit/pops/types/p_sem_ver_type_spec.rb +285 -0
- data/spec/unit/pops/types/recursion_guard_spec.rb +19 -17
- data/spec/unit/pops/types/ruby_generator_spec.rb +261 -0
- data/spec/unit/pops/types/string_converter_spec.rb +904 -0
- data/spec/unit/pops/types/type_calculator_spec.rb +430 -406
- data/spec/unit/pops/types/type_factory_spec.rb +119 -104
- data/spec/unit/pops/types/type_formatter_spec.rb +73 -6
- data/spec/unit/pops/types/type_mismatch_describer_spec.rb +2 -2
- data/spec/unit/pops/types/type_parser_spec.rb +54 -15
- data/spec/unit/pops/types/types_spec.rb +113 -8
- data/spec/unit/pops/validator/validator_spec.rb +84 -10
- data/spec/unit/provider/package/pip3_spec.rb +9 -270
- data/spec/unit/provider/package/pip_spec.rb +85 -30
- data/spec/unit/provider/package/rpm_spec.rb +160 -3
- data/spec/unit/provider/package/yum_spec.rb +23 -134
- data/spec/unit/provider/service/smf_spec.rb +14 -2
- data/spec/unit/provider/service/systemd_spec.rb +33 -41
- data/spec/unit/resource/capability_finder_spec.rb +10 -2
- data/spec/unit/settings/file_setting_spec.rb +6 -0
- data/spec/unit/transaction/additional_resource_generator_spec.rb +80 -65
- data/spec/unit/type/mount_spec.rb +51 -10
- data/spec/unit/type/service_spec.rb +16 -0
- data/spec/unit/type_spec.rb +14 -0
- data/spec/unit/util/feature_spec.rb +1 -1
- data/spec/unit/util/monkey_patches_spec.rb +60 -0
- data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
- metadata +63 -11
- data/lib/puppet/pops/types/types_meta.rb +0 -0
- data/spec/integration/provider/package_spec.rb +0 -35
@@ -1,307 +1,322 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'puppet/pops'
|
3
3
|
|
4
|
+
module Puppet::Pops
|
5
|
+
module Types
|
4
6
|
describe 'The type factory' do
|
5
7
|
context 'when creating' do
|
6
8
|
it 'integer() returns PIntegerType' do
|
7
|
-
expect(
|
9
|
+
expect(TypeFactory.integer().class()).to eq(PIntegerType)
|
8
10
|
end
|
9
11
|
|
10
12
|
it 'float() returns PFloatType' do
|
11
|
-
expect(
|
13
|
+
expect(TypeFactory.float().class()).to eq(PFloatType)
|
12
14
|
end
|
13
15
|
|
14
16
|
it 'string() returns PStringType' do
|
15
|
-
expect(
|
17
|
+
expect(TypeFactory.string().class()).to eq(PStringType)
|
16
18
|
end
|
17
19
|
|
18
20
|
it 'boolean() returns PBooleanType' do
|
19
|
-
expect(
|
21
|
+
expect(TypeFactory.boolean().class()).to eq(PBooleanType)
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'pattern() returns PPatternType' do
|
23
|
-
expect(
|
25
|
+
expect(TypeFactory.pattern().class()).to eq(PPatternType)
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'regexp() returns PRegexpType' do
|
27
|
-
expect(
|
29
|
+
expect(TypeFactory.regexp().class()).to eq(PRegexpType)
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'enum() returns PEnumType' do
|
31
|
-
expect(
|
33
|
+
expect(TypeFactory.enum().class()).to eq(PEnumType)
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'variant() returns PVariantType' do
|
35
|
-
expect(
|
37
|
+
expect(TypeFactory.variant().class()).to eq(PVariantType)
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'scalar() returns PScalarType' do
|
39
|
-
expect(
|
41
|
+
expect(TypeFactory.scalar().class()).to eq(PScalarType)
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'data() returns PDataType' do
|
43
|
-
expect(
|
45
|
+
expect(TypeFactory.data().class()).to eq(PDataType)
|
44
46
|
end
|
45
47
|
|
46
48
|
it 'optional() returns POptionalType' do
|
47
|
-
expect(
|
49
|
+
expect(TypeFactory.optional().class()).to eq(POptionalType)
|
48
50
|
end
|
49
51
|
|
50
52
|
it 'collection() returns PCollectionType' do
|
51
|
-
expect(
|
53
|
+
expect(TypeFactory.collection().class()).to eq(PCollectionType)
|
52
54
|
end
|
53
55
|
|
54
56
|
it 'catalog_entry() returns PCatalogEntryType' do
|
55
|
-
expect(
|
57
|
+
expect(TypeFactory.catalog_entry().class()).to eq(PCatalogEntryType)
|
56
58
|
end
|
57
59
|
|
58
60
|
it 'struct() returns PStructType' do
|
59
|
-
expect(
|
61
|
+
expect(TypeFactory.struct().class()).to eq(PStructType)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "object() returns PObjectType" do
|
65
|
+
expect(TypeFactory.object.class).to eq(PObjectType)
|
60
66
|
end
|
61
67
|
|
62
68
|
it 'tuple() returns PTupleType' do
|
63
|
-
expect(
|
69
|
+
expect(TypeFactory.tuple.class()).to eq(PTupleType)
|
64
70
|
end
|
65
71
|
|
66
72
|
it 'undef() returns PUndefType' do
|
67
|
-
expect(
|
73
|
+
expect(TypeFactory.undef().class()).to eq(PUndefType)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'type_alias() returns PTypeAliasType' do
|
77
|
+
expect(TypeFactory.type_alias().class()).to eq(PTypeAliasType)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'sem_ver() returns PSemVerType' do
|
81
|
+
expect(TypeFactory.sem_ver.class).to eq(PSemVerType)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'sem_ver(r1, r2) returns constrained PSemVerType' do
|
85
|
+
expect(TypeFactory.sem_ver('1.x', '3.x').ranges).to include(Semantic::VersionRange.parse('1.x'), Semantic::VersionRange.parse('3.x'))
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'sem_ver_range() returns PSemVerRangeType' do
|
89
|
+
expect(TypeFactory.sem_ver_range.class).to eq(PSemVerRangeType)
|
68
90
|
end
|
69
91
|
|
70
92
|
it 'default() returns PDefaultType' do
|
71
|
-
expect(
|
93
|
+
expect(TypeFactory.default().class()).to eq(PDefaultType)
|
72
94
|
end
|
73
95
|
|
74
96
|
it 'range(to, from) returns PIntegerType' do
|
75
|
-
t =
|
76
|
-
expect(t.class()).to eq(
|
97
|
+
t = TypeFactory.range(1,2)
|
98
|
+
expect(t.class()).to eq(PIntegerType)
|
77
99
|
expect(t.from).to eq(1)
|
78
100
|
expect(t.to).to eq(2)
|
79
101
|
end
|
80
102
|
|
81
103
|
it 'range(default, default) returns PIntegerType' do
|
82
|
-
t =
|
83
|
-
expect(t.class()).to eq(
|
104
|
+
t = TypeFactory.range(:default,:default)
|
105
|
+
expect(t.class()).to eq(PIntegerType)
|
84
106
|
expect(t.from).to eq(nil)
|
85
107
|
expect(t.to).to eq(nil)
|
86
108
|
end
|
87
109
|
|
88
110
|
it 'float_range(to, from) returns PFloatType' do
|
89
|
-
t =
|
90
|
-
expect(t.class()).to eq(
|
111
|
+
t = TypeFactory.float_range(1.0, 2.0)
|
112
|
+
expect(t.class()).to eq(PFloatType)
|
91
113
|
expect(t.from).to eq(1.0)
|
92
114
|
expect(t.to).to eq(2.0)
|
93
115
|
end
|
94
116
|
|
95
117
|
it 'float_range(default, default) returns PFloatType' do
|
96
|
-
t =
|
97
|
-
expect(t.class()).to eq(
|
118
|
+
t = TypeFactory.float_range(:default, :default)
|
119
|
+
expect(t.class()).to eq(PFloatType)
|
98
120
|
expect(t.from).to eq(nil)
|
99
121
|
expect(t.to).to eq(nil)
|
100
122
|
end
|
101
123
|
|
102
124
|
it 'resource() creates a generic PResourceType' do
|
103
|
-
pr =
|
104
|
-
expect(pr.class()).to eq(
|
125
|
+
pr = TypeFactory.resource()
|
126
|
+
expect(pr.class()).to eq(PResourceType)
|
105
127
|
expect(pr.type_name).to eq(nil)
|
106
128
|
end
|
107
129
|
|
108
130
|
it 'resource(x) creates a PResourceType[x]' do
|
109
|
-
pr =
|
110
|
-
expect(pr.class()).to eq(
|
111
|
-
expect(pr.type_name).to eq('
|
131
|
+
pr = TypeFactory.resource('x')
|
132
|
+
expect(pr.class()).to eq(PResourceType)
|
133
|
+
expect(pr.type_name).to eq('X')
|
112
134
|
end
|
113
135
|
|
114
136
|
it 'host_class() creates a generic PHostClassType' do
|
115
|
-
hc =
|
116
|
-
expect(hc.class()).to eq(
|
137
|
+
hc = TypeFactory.host_class()
|
138
|
+
expect(hc.class()).to eq(PHostClassType)
|
117
139
|
expect(hc.class_name).to eq(nil)
|
118
140
|
end
|
119
141
|
|
120
142
|
it 'host_class(x) creates a PHostClassType[x]' do
|
121
|
-
hc =
|
122
|
-
expect(hc.class()).to eq(
|
143
|
+
hc = TypeFactory.host_class('x')
|
144
|
+
expect(hc.class()).to eq(PHostClassType)
|
123
145
|
expect(hc.class_name).to eq('x')
|
124
146
|
end
|
125
147
|
|
126
148
|
it 'host_class(::x) creates a PHostClassType[x]' do
|
127
|
-
hc =
|
128
|
-
expect(hc.class()).to eq(
|
149
|
+
hc = TypeFactory.host_class('::x')
|
150
|
+
expect(hc.class()).to eq(PHostClassType)
|
129
151
|
expect(hc.class_name).to eq('x')
|
130
152
|
end
|
131
153
|
|
132
154
|
it 'array_of(fixnum) returns PArrayType[PIntegerType]' do
|
133
|
-
at =
|
134
|
-
expect(at.class()).to eq(
|
135
|
-
expect(at.element_type.class).to eq(
|
155
|
+
at = TypeFactory.array_of(1)
|
156
|
+
expect(at.class()).to eq(PArrayType)
|
157
|
+
expect(at.element_type.class).to eq(PIntegerType)
|
136
158
|
end
|
137
159
|
|
138
160
|
it 'array_of(PIntegerType) returns PArrayType[PIntegerType]' do
|
139
|
-
at =
|
140
|
-
expect(at.class()).to eq(
|
141
|
-
expect(at.element_type.class).to eq(
|
161
|
+
at = TypeFactory.array_of(PIntegerType::DEFAULT)
|
162
|
+
expect(at.class()).to eq(PArrayType)
|
163
|
+
expect(at.element_type.class).to eq(PIntegerType)
|
142
164
|
end
|
143
165
|
|
144
166
|
it 'array_of_data returns PArrayType[PDataType]' do
|
145
|
-
at =
|
146
|
-
expect(at.class()).to eq(
|
147
|
-
expect(at.element_type.class).to eq(
|
167
|
+
at = TypeFactory.array_of_data
|
168
|
+
expect(at.class()).to eq(PArrayType)
|
169
|
+
expect(at.element_type.class).to eq(PDataType)
|
148
170
|
end
|
149
171
|
|
150
172
|
it 'hash_of_data returns PHashType[PScalarType,PDataType]' do
|
151
|
-
ht =
|
152
|
-
expect(ht.class()).to eq(
|
153
|
-
expect(ht.key_type.class).to eq(
|
154
|
-
expect(ht.element_type.class).to eq(
|
173
|
+
ht = TypeFactory.hash_of_data
|
174
|
+
expect(ht.class()).to eq(PHashType)
|
175
|
+
expect(ht.key_type.class).to eq(PScalarType)
|
176
|
+
expect(ht.element_type.class).to eq(PDataType)
|
155
177
|
end
|
156
178
|
|
157
179
|
it 'ruby(1) returns PRuntimeType[ruby, \'Fixnum\']' do
|
158
|
-
ht =
|
159
|
-
expect(ht.class()).to eq(
|
180
|
+
ht = TypeFactory.ruby(1)
|
181
|
+
expect(ht.class()).to eq(PRuntimeType)
|
160
182
|
expect(ht.runtime).to eq(:ruby)
|
161
183
|
expect(ht.runtime_type_name).to eq('Fixnum')
|
162
184
|
end
|
163
185
|
|
164
186
|
it 'a size constrained collection can be created from array' do
|
165
|
-
t =
|
166
|
-
expect(t.size_type.class).to eq(
|
187
|
+
t = TypeFactory.array_of(TypeFactory.data, TypeFactory.range(1,2))
|
188
|
+
expect(t.size_type.class).to eq(PIntegerType)
|
167
189
|
expect(t.size_type.from).to eq(1)
|
168
190
|
expect(t.size_type.to).to eq(2)
|
169
191
|
end
|
170
192
|
|
171
193
|
it 'a size constrained collection can be created from hash' do
|
172
|
-
t =
|
173
|
-
expect(t.size_type.class).to eq(
|
194
|
+
t = TypeFactory.hash_of(TypeFactory.scalar, TypeFactory.data, TypeFactory.range(1,2))
|
195
|
+
expect(t.size_type.class).to eq(PIntegerType)
|
174
196
|
expect(t.size_type.from).to eq(1)
|
175
197
|
expect(t.size_type.to).to eq(2)
|
176
198
|
end
|
177
199
|
|
178
|
-
it '
|
179
|
-
|
180
|
-
Puppet::Pops::Types::TypeFactory.array_of(Puppet::Pops::Types::TypeFactory.data, Puppet::Pops::Types::TypeFactory.range(0,0))
|
181
|
-
}.to raise_error(/An empty collection may not specify an element type/)
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'it is legal to create an empty array of unit element type' do
|
185
|
-
t = Puppet::Pops::Types::TypeFactory.array_of(Puppet::Pops::Types::PUnitType::DEFAULT, Puppet::Pops::Types::TypeFactory.range(0,0))
|
200
|
+
it 'a typed empty array, the resulting array erases the type' do
|
201
|
+
t = Puppet::Pops::Types::TypeFactory.array_of(Puppet::Pops::Types::TypeFactory.data, Puppet::Pops::Types::TypeFactory.range(0,0))
|
186
202
|
expect(t.size_type.class).to eq(Puppet::Pops::Types::PIntegerType)
|
187
203
|
expect(t.size_type.from).to eq(0)
|
188
204
|
expect(t.size_type.to).to eq(0)
|
205
|
+
expect(t.element_type).to eq(Puppet::Pops::Types::PUnitType::DEFAULT)
|
189
206
|
end
|
190
207
|
|
191
|
-
it '
|
192
|
-
|
193
|
-
Puppet::Pops::Types::TypeFactory.hash_of(Puppet::Pops::Types::TypeFactory.scalar, Puppet::Pops::Types::TypeFactory.data, Puppet::Pops::Types::TypeFactory.range(0,0))
|
194
|
-
}.to raise_error(/An empty collection may not specify an element type/)
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'it is legal to create an empty hash where key and value types are of Unit type' do
|
198
|
-
t = Puppet::Pops::Types::TypeFactory.hash_of(Puppet::Pops::Types::PUnitType::DEFAULT, Puppet::Pops::Types::PUnitType::DEFAULT, Puppet::Pops::Types::TypeFactory.range(0,0))
|
208
|
+
it 'a typed empty hash, the resulting hash erases the key and value type' do
|
209
|
+
t = Puppet::Pops::Types::TypeFactory.hash_of(Puppet::Pops::Types::TypeFactory.scalar, Puppet::Pops::Types::TypeFactory.data, Puppet::Pops::Types::TypeFactory.range(0,0))
|
199
210
|
expect(t.size_type.class).to eq(Puppet::Pops::Types::PIntegerType)
|
200
211
|
expect(t.size_type.from).to eq(0)
|
201
212
|
expect(t.size_type.to).to eq(0)
|
213
|
+
expect(t.key_type).to eq(Puppet::Pops::Types::PUnitType::DEFAULT)
|
214
|
+
expect(t.element_type).to eq(Puppet::Pops::Types::PUnitType::DEFAULT)
|
202
215
|
end
|
203
216
|
|
204
217
|
context 'callable types' do
|
205
218
|
it 'the callable methods produces a Callable' do
|
206
|
-
t =
|
207
|
-
expect(t.class).to be(
|
208
|
-
expect(t.param_types.class).to be(
|
219
|
+
t = TypeFactory.callable()
|
220
|
+
expect(t.class).to be(PCallableType)
|
221
|
+
expect(t.param_types.class).to be(PTupleType)
|
209
222
|
expect(t.param_types.types).to be_empty
|
210
223
|
expect(t.block_type).to be_nil
|
211
224
|
end
|
212
225
|
|
213
226
|
it 'callable method with types produces the corresponding Tuple for parameters and generated names' do
|
214
|
-
tf =
|
227
|
+
tf = TypeFactory
|
215
228
|
t = tf.callable(tf.integer, tf.string)
|
216
|
-
expect(t.class).to be(
|
217
|
-
expect(t.param_types.class).to be(
|
229
|
+
expect(t.class).to be(PCallableType)
|
230
|
+
expect(t.param_types.class).to be(PTupleType)
|
218
231
|
expect(t.param_types.types).to eql([tf.integer, tf.string])
|
219
232
|
expect(t.block_type).to be_nil
|
220
233
|
end
|
221
234
|
|
222
235
|
it 'callable accepts min range to be given' do
|
223
|
-
tf =
|
236
|
+
tf = TypeFactory
|
224
237
|
t = tf.callable(tf.integer, tf.string, 1)
|
225
|
-
expect(t.class).to be(
|
226
|
-
expect(t.param_types.class).to be(
|
238
|
+
expect(t.class).to be(PCallableType)
|
239
|
+
expect(t.param_types.class).to be(PTupleType)
|
227
240
|
expect(t.param_types.size_type.from).to eql(1)
|
228
241
|
expect(t.param_types.size_type.to).to be_nil
|
229
242
|
end
|
230
243
|
|
231
244
|
it 'callable accepts max range to be given' do
|
232
|
-
tf =
|
245
|
+
tf = TypeFactory
|
233
246
|
t = tf.callable(tf.integer, tf.string, 1, 3)
|
234
|
-
expect(t.class).to be(
|
235
|
-
expect(t.param_types.class).to be(
|
247
|
+
expect(t.class).to be(PCallableType)
|
248
|
+
expect(t.param_types.class).to be(PTupleType)
|
236
249
|
expect(t.param_types.size_type.from).to eql(1)
|
237
250
|
expect(t.param_types.size_type.to).to eql(3)
|
238
251
|
end
|
239
252
|
|
240
253
|
it 'callable accepts max range to be given as :default' do
|
241
|
-
tf =
|
254
|
+
tf = TypeFactory
|
242
255
|
t = tf.callable(tf.integer, tf.string, 1, :default)
|
243
|
-
expect(t.class).to be(
|
244
|
-
expect(t.param_types.class).to be(
|
256
|
+
expect(t.class).to be(PCallableType)
|
257
|
+
expect(t.param_types.class).to be(PTupleType)
|
245
258
|
expect(t.param_types.size_type.from).to eql(1)
|
246
259
|
expect(t.param_types.size_type.to).to be_nil
|
247
260
|
end
|
248
261
|
|
249
262
|
it 'the all_callables method produces a Callable matching any Callable' do
|
250
|
-
t =
|
251
|
-
expect(t.class).to be(
|
263
|
+
t = TypeFactory.all_callables()
|
264
|
+
expect(t.class).to be(PCallableType)
|
252
265
|
expect(t.param_types).to be_nil
|
253
266
|
expect(t.block_type).to be_nil
|
254
267
|
end
|
255
268
|
|
256
269
|
it 'with block are created by placing a Callable last' do
|
257
|
-
block_t =
|
258
|
-
t =
|
270
|
+
block_t = TypeFactory.callable(String)
|
271
|
+
t = TypeFactory.callable(String, block_t)
|
259
272
|
expect(t.block_type).to be(block_t)
|
260
273
|
end
|
261
274
|
|
262
275
|
it 'min size constraint can be used with a block last' do
|
263
|
-
block_t =
|
264
|
-
t =
|
276
|
+
block_t = TypeFactory.callable(String)
|
277
|
+
t = TypeFactory.callable(String, 1, block_t)
|
265
278
|
expect(t.block_type).to be(block_t)
|
266
279
|
expect(t.param_types.size_type.from).to eql(1)
|
267
280
|
expect(t.param_types.size_type.to).to be_nil
|
268
281
|
end
|
269
282
|
|
270
283
|
it 'min, max size constraint can be used with a block last' do
|
271
|
-
block_t =
|
272
|
-
t =
|
284
|
+
block_t = TypeFactory.callable(String)
|
285
|
+
t = TypeFactory.callable(String, 1, 3, block_t)
|
273
286
|
expect(t.block_type).to be(block_t)
|
274
287
|
expect(t.param_types.size_type.from).to eql(1)
|
275
288
|
expect(t.param_types.size_type.to).to eql(3)
|
276
289
|
end
|
277
290
|
|
278
291
|
it 'the with_block methods decorates a Callable with a block_type' do
|
279
|
-
t =
|
280
|
-
t2 =
|
292
|
+
t = TypeFactory.callable
|
293
|
+
t2 = TypeFactory.callable(t)
|
281
294
|
block_t = t2.block_type
|
282
295
|
# given t is returned after mutation
|
283
296
|
expect(block_t).to be(t)
|
284
|
-
expect(block_t.class).to be(
|
285
|
-
expect(block_t.param_types.class).to be(
|
297
|
+
expect(block_t.class).to be(PCallableType)
|
298
|
+
expect(block_t.param_types.class).to be(PTupleType)
|
286
299
|
expect(block_t.param_types.types).to be_empty
|
287
300
|
expect(block_t.block_type).to be_nil
|
288
301
|
end
|
289
302
|
|
290
303
|
it 'the with_optional_block methods decorates a Callable with an optional block_type' do
|
291
|
-
b =
|
292
|
-
t =
|
293
|
-
t2 =
|
304
|
+
b = TypeFactory.callable
|
305
|
+
t = TypeFactory.optional(b)
|
306
|
+
t2 = TypeFactory.callable(t)
|
294
307
|
opt_t = t2.block_type
|
295
|
-
expect(opt_t.class).to be(
|
308
|
+
expect(opt_t.class).to be(POptionalType)
|
296
309
|
block_t = opt_t.optional_type
|
297
310
|
# given t is returned after mutation
|
298
311
|
expect(opt_t).to be(t)
|
299
312
|
expect(block_t).to be(b)
|
300
|
-
expect(block_t.class).to be(
|
301
|
-
expect(block_t.param_types.class).to be(
|
313
|
+
expect(block_t.class).to be(PCallableType)
|
314
|
+
expect(block_t.param_types.class).to be(PTupleType)
|
302
315
|
expect(block_t.param_types.types).to be_empty
|
303
316
|
expect(block_t.block_type).to be_nil
|
304
317
|
end
|
305
318
|
end
|
306
319
|
end
|
307
320
|
end
|
321
|
+
end
|
322
|
+
end
|
@@ -6,6 +6,68 @@ describe 'The type formatter' do
|
|
6
6
|
let(:s) { TypeFormatter.new }
|
7
7
|
let(:f) { TypeFactory }
|
8
8
|
|
9
|
+
def drop_indent(str)
|
10
|
+
ld = str.index("\n")
|
11
|
+
if ld.nil?
|
12
|
+
str
|
13
|
+
else
|
14
|
+
str.gsub(Regexp.compile("^ {#{ld - 1}}"), '')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when representing a literal as a string' do
|
19
|
+
{
|
20
|
+
'true' => true,
|
21
|
+
'false' => false,
|
22
|
+
'?' => nil,
|
23
|
+
'23.4' => 23.4,
|
24
|
+
'145' => 145,
|
25
|
+
"'string'" => 'string',
|
26
|
+
'/expr/' => /expr/,
|
27
|
+
'[1, 2, 3]' => [1, 2, 3],
|
28
|
+
"{'a' => 32, 'b' => [1, 2, 3]}" => {'a' => 32,'b' => [1, 2, 3]}
|
29
|
+
}.each_pair do |str, value|
|
30
|
+
it "should yield '#{str}' for a value of #{str}" do
|
31
|
+
expect(s.string(value)).to eq(str)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when using indent' do
|
37
|
+
it 'should put hash entries on new indented lines' do
|
38
|
+
expect(s.indented_string({'a' => 32,'b' => [1, 2, {'c' => 'd'}]})).to eq(<<-FORMATTED)
|
39
|
+
{
|
40
|
+
'a' => 32,
|
41
|
+
'b' => [1, 2, {
|
42
|
+
'c' => 'd'
|
43
|
+
}]
|
44
|
+
}
|
45
|
+
FORMATTED
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should start on given indent level' do
|
49
|
+
expect(s.indented_string({'a' => 32,'b' => [1, 2, {'c' => 'd'}]}, 3)).to eq(<<-FORMATTED)
|
50
|
+
{
|
51
|
+
'a' => 32,
|
52
|
+
'b' => [1, 2, {
|
53
|
+
'c' => 'd'
|
54
|
+
}]
|
55
|
+
}
|
56
|
+
FORMATTED
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should use given indent width' do
|
60
|
+
expect(s.indented_string({'a' => 32,'b' => [1, 2, {'c' => 'd'}]}, 2, 4)).to eq(<<-FORMATTED)
|
61
|
+
{
|
62
|
+
'a' => 32,
|
63
|
+
'b' => [1, 2, {
|
64
|
+
'c' => 'd'
|
65
|
+
}]
|
66
|
+
}
|
67
|
+
FORMATTED
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
9
71
|
context 'when representing the type as string' do
|
10
72
|
include_context 'types_setup'
|
11
73
|
|
@@ -252,12 +314,12 @@ describe 'The type formatter' do
|
|
252
314
|
|
253
315
|
it "should yield the name of an unparameterized type reference" do
|
254
316
|
t = f.type_reference('What')
|
255
|
-
expect(s.string(t)).to eq('What')
|
317
|
+
expect(s.string(t)).to eq("TypeReference['What']")
|
256
318
|
end
|
257
319
|
|
258
320
|
it "should yield the name and arguments of an parameterized type reference" do
|
259
|
-
t = f.type_reference('What
|
260
|
-
expect(s.string(t)).to eq('What[Undef, String]')
|
321
|
+
t = f.type_reference('What[Undef, String]')
|
322
|
+
expect(s.string(t)).to eq("TypeReference['What[Undef, String]']")
|
261
323
|
end
|
262
324
|
|
263
325
|
it "should yield the name of a type alias" do
|
@@ -266,19 +328,24 @@ describe 'The type formatter' do
|
|
266
328
|
end
|
267
329
|
|
268
330
|
it "should yield 'Type[Runtime[ruby, Puppet]]' for the Puppet module" do
|
269
|
-
expect(s.string(Puppet)).to eq(
|
331
|
+
expect(s.string(Puppet)).to eq("Runtime[ruby, 'Puppet']")
|
270
332
|
end
|
271
333
|
|
272
334
|
it "should yield 'Type[Runtime[ruby, Puppet::Pops]]' for the Puppet::Resource class" do
|
273
|
-
expect(s.string(Puppet::Resource)).to eq(
|
335
|
+
expect(s.string(Puppet::Resource)).to eq("Runtime[ruby, 'Puppet::Resource']")
|
336
|
+
end
|
337
|
+
|
338
|
+
it "should yield \"SemVer['1.x', '3.x']\" for the PSemVerType['1.x', '3.x']" do
|
339
|
+
expect(s.string(PSemVerType.new('1.x', '3.x'))).to eq("SemVer['1.x', '3.x']")
|
274
340
|
end
|
275
341
|
|
276
342
|
it 'should present a valid simple name' do
|
277
|
-
(all_types - [PType]).each do |t|
|
343
|
+
(all_types - [PType, PHostClassType]).each do |t|
|
278
344
|
name = t::DEFAULT.simple_name
|
279
345
|
expect(t.name).to match("^Puppet::Pops::Types::P#{name}Type$")
|
280
346
|
end
|
281
347
|
expect(PType::DEFAULT.simple_name).to eql('Type')
|
348
|
+
expect(PHostClassType::DEFAULT.simple_name).to eql('Class')
|
282
349
|
end
|
283
350
|
end
|
284
351
|
end
|