puppet 4.2.3-x86-mingw32 → 4.3.0-x86-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.

Files changed (337) hide show
  1. data/Gemfile +3 -0
  2. data/README.md +1 -1
  3. data/ext/debian/puppet.init +0 -1
  4. data/ext/debian/puppet.logrotate +14 -5
  5. data/ext/osx/puppet.plist +0 -2
  6. data/ext/redhat/client.init +13 -5
  7. data/ext/redhat/logrotate +15 -3
  8. data/ext/redhat/puppet.spec.erb +5 -1
  9. data/ext/redhat/server.init +1 -1
  10. data/ext/systemd/puppet.service +1 -0
  11. data/lib/puppet.rb +12 -0
  12. data/lib/puppet/agent.rb +4 -4
  13. data/lib/puppet/agent/locker.rb +11 -2
  14. data/lib/puppet/application/agent.rb +5 -1
  15. data/lib/puppet/application/apply.rb +4 -0
  16. data/lib/puppet/application/filebucket.rb +78 -4
  17. data/lib/puppet/application/lookup.rb +356 -0
  18. data/lib/puppet/application/master.rb +3 -0
  19. data/lib/puppet/configurer.rb +9 -5
  20. data/lib/puppet/context.rb +16 -1
  21. data/lib/puppet/context/trusted_information.rb +21 -1
  22. data/lib/puppet/daemon.rb +17 -13
  23. data/lib/puppet/data_binding.rb +4 -2
  24. data/lib/puppet/data_providers.rb +12 -13
  25. data/lib/puppet/data_providers/data_adapter.rb +7 -68
  26. data/lib/puppet/data_providers/data_function_support.rb +5 -26
  27. data/lib/puppet/data_providers/function_env_data_provider.rb +0 -10
  28. data/lib/puppet/data_providers/function_module_data_provider.rb +0 -22
  29. data/lib/puppet/data_providers/hiera_config.rb +106 -0
  30. data/lib/puppet/data_providers/hiera_env_data_provider.rb +18 -0
  31. data/lib/puppet/data_providers/hiera_interpolate.rb +97 -0
  32. data/lib/puppet/data_providers/hiera_module_data_provider.rb +23 -0
  33. data/lib/puppet/data_providers/hiera_support.rb +37 -0
  34. data/lib/puppet/data_providers/json_data_provider_factory.rb +31 -0
  35. data/lib/puppet/data_providers/lookup_adapter.rb +200 -0
  36. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +32 -0
  37. data/lib/puppet/defaults.rb +12 -2
  38. data/lib/puppet/error.rb +4 -0
  39. data/lib/puppet/face/module/changes.rb +2 -1
  40. data/lib/puppet/feature/cfacter.rb +1 -0
  41. data/lib/puppet/file_bucket/dipper.rb +58 -2
  42. data/lib/puppet/functions.rb +2 -4
  43. data/lib/puppet/functions/assert_type.rb +48 -12
  44. data/lib/puppet/functions/defined.rb +79 -48
  45. data/lib/puppet/functions/each.rb +85 -27
  46. data/lib/puppet/functions/filter.rb +58 -23
  47. data/lib/puppet/functions/hiera.rb +76 -3
  48. data/lib/puppet/functions/hiera_array.rb +65 -3
  49. data/lib/puppet/functions/hiera_hash.rb +74 -2
  50. data/lib/puppet/functions/hiera_include.rb +75 -2
  51. data/lib/puppet/functions/lookup.rb +19 -17
  52. data/lib/puppet/functions/map.rb +56 -21
  53. data/lib/puppet/functions/match.rb +29 -12
  54. data/lib/puppet/functions/reduce.rb +95 -58
  55. data/lib/puppet/functions/versioncmp.rb +36 -0
  56. data/lib/puppet/functions/with.rb +15 -7
  57. data/lib/puppet/indirector/catalog/compiler.rb +3 -3
  58. data/lib/puppet/indirector/catalog/static_compiler.rb +46 -30
  59. data/lib/puppet/indirector/data_binding/none.rb +4 -1
  60. data/lib/puppet/indirector/file_bucket_file/file.rb +58 -1
  61. data/lib/puppet/indirector/hiera.rb +4 -0
  62. data/lib/puppet/indirector/json.rb +1 -1
  63. data/lib/puppet/indirector/msgpack.rb +1 -1
  64. data/lib/puppet/indirector/request.rb +7 -8
  65. data/lib/puppet/indirector/resource_type/parser.rb +5 -3
  66. data/lib/puppet/info_service.rb +7 -0
  67. data/lib/puppet/info_service/class_information_service.rb +111 -0
  68. data/lib/puppet/module_tool/metadata.rb +32 -9
  69. data/lib/puppet/module_tool/skeleton/templates/generator/README.md.erb +42 -38
  70. data/lib/puppet/network/authconfig.rb +21 -1
  71. data/lib/puppet/network/authorization.rb +8 -1
  72. data/lib/puppet/network/http/api/master/v3.rb +7 -1
  73. data/lib/puppet/network/http/api/master/v3/environment.rb +59 -0
  74. data/lib/puppet/node/environment.rb +9 -2
  75. data/lib/puppet/parser.rb +3 -0
  76. data/lib/puppet/parser/ast/pops_bridge.rb +39 -1
  77. data/lib/puppet/parser/compiler.rb +302 -12
  78. data/lib/puppet/parser/compiler/catalog_validator.rb +33 -0
  79. data/lib/puppet/parser/compiler/catalog_validator/env_relationship_validator.rb +64 -0
  80. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +38 -0
  81. data/lib/puppet/parser/compiler/catalog_validator/site_validator.rb +20 -0
  82. data/lib/puppet/parser/environment_compiler.rb +165 -0
  83. data/lib/puppet/parser/functions/assert_type.rb +46 -16
  84. data/lib/puppet/parser/functions/defined.rb +105 -68
  85. data/lib/puppet/parser/functions/each.rb +85 -27
  86. data/lib/puppet/parser/functions/filter.rb +59 -23
  87. data/lib/puppet/parser/functions/hiera.rb +83 -27
  88. data/lib/puppet/parser/functions/hiera_array.rb +71 -28
  89. data/lib/puppet/parser/functions/hiera_hash.rb +81 -30
  90. data/lib/puppet/parser/functions/hiera_include.rb +81 -40
  91. data/lib/puppet/parser/functions/map.rb +55 -20
  92. data/lib/puppet/parser/functions/match.rb +27 -12
  93. data/lib/puppet/parser/functions/reduce.rb +97 -60
  94. data/lib/puppet/parser/functions/with.rb +16 -8
  95. data/lib/puppet/parser/resource.rb +98 -19
  96. data/lib/puppet/plugins/configuration.rb +3 -2
  97. data/lib/puppet/plugins/data_providers.rb +12 -60
  98. data/lib/puppet/plugins/data_providers/data_provider.rb +283 -0
  99. data/lib/puppet/plugins/data_providers/registry.rb +84 -0
  100. data/lib/puppet/pops.rb +19 -17
  101. data/lib/puppet/pops/adapters.rb +12 -0
  102. data/lib/puppet/pops/binder/binder.rb +2 -2
  103. data/lib/puppet/pops/binder/bindings_checker.rb +1 -1
  104. data/lib/puppet/pops/binder/bindings_label_provider.rb +3 -1
  105. data/lib/puppet/pops/binder/bindings_loader.rb +6 -2
  106. data/lib/puppet/pops/binder/bindings_model_meta.rb +2 -2
  107. data/lib/puppet/pops/binder/config/binder_config.rb +1 -1
  108. data/lib/puppet/pops/binder/injector.rb +4 -4
  109. data/lib/puppet/pops/binder/key_factory.rb +3 -9
  110. data/lib/puppet/pops/binder/scheme_handler/module_scheme.rb +68 -9
  111. data/lib/puppet/pops/evaluator/access_operator.rb +27 -60
  112. data/lib/puppet/pops/evaluator/closure.rb +8 -8
  113. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +1 -1
  114. data/lib/puppet/pops/evaluator/evaluator_impl.rb +5 -5
  115. data/lib/puppet/pops/evaluator/literal_evaluator.rb +87 -0
  116. data/lib/puppet/pops/evaluator/relationship_operator.rb +7 -1
  117. data/lib/puppet/pops/functions/dispatcher.rb +3 -3
  118. data/lib/puppet/pops/issues.rb +1 -1
  119. data/lib/puppet/pops/label_provider.rb +1 -1
  120. data/lib/puppet/pops/lookup.rb +25 -47
  121. data/lib/puppet/pops/lookup/explainer.rb +402 -0
  122. data/lib/puppet/pops/lookup/invocation.rb +117 -0
  123. data/lib/puppet/pops/merge_strategy.rb +73 -5
  124. data/lib/puppet/pops/model/factory.rb +34 -0
  125. data/lib/puppet/pops/model/model_label_provider.rb +10 -1
  126. data/lib/puppet/pops/model/model_meta.rb +15 -0
  127. data/lib/puppet/pops/model/model_tree_dumper.rb +18 -0
  128. data/lib/puppet/pops/parser/code_merger.rb +13 -1
  129. data/lib/puppet/pops/parser/egrammar.ra +56 -3
  130. data/lib/puppet/pops/parser/eparser.rb +1549 -1352
  131. data/lib/puppet/pops/parser/lexer2.rb +31 -6
  132. data/lib/puppet/pops/parser/locator.rb +1 -1
  133. data/lib/puppet/pops/parser/parser_support.rb +25 -13
  134. data/lib/puppet/pops/types/enumeration.rb +1 -2
  135. data/lib/puppet/pops/types/type_asserter.rb +16 -15
  136. data/lib/puppet/pops/types/type_assertion_error.rb +1 -0
  137. data/lib/puppet/pops/types/type_calculator.rb +171 -1020
  138. data/lib/puppet/pops/types/type_factory.rb +87 -148
  139. data/lib/puppet/pops/types/type_mismatch_describer.rb +743 -0
  140. data/lib/puppet/pops/types/type_parser.rb +116 -127
  141. data/lib/puppet/pops/types/types.rb +1394 -255
  142. data/lib/puppet/pops/types/types_meta.rb +0 -234
  143. data/lib/puppet/pops/validation.rb +7 -2
  144. data/lib/puppet/pops/validation/checker4_0.rb +28 -0
  145. data/lib/puppet/provider/augeas/augeas.rb +50 -0
  146. data/lib/puppet/provider/group/directoryservice.rb +10 -0
  147. data/lib/puppet/provider/package/dnf.rb +41 -0
  148. data/lib/puppet/provider/package/gem.rb +7 -2
  149. data/lib/puppet/provider/package/rpm.rb +1 -0
  150. data/lib/puppet/provider/package/windows/exe_package.rb +10 -8
  151. data/lib/puppet/provider/package/windows/msi_package.rb +4 -3
  152. data/lib/puppet/provider/package/windows/package.rb +9 -1
  153. data/lib/puppet/provider/package/yum.rb +14 -9
  154. data/lib/puppet/provider/service/bsd.rb +1 -1
  155. data/lib/puppet/provider/service/debian.rb +21 -0
  156. data/lib/puppet/provider/service/init.rb +6 -0
  157. data/lib/puppet/provider/service/rcng.rb +51 -0
  158. data/lib/puppet/provider/service/redhat.rb +2 -1
  159. data/lib/puppet/provider/service/smf.rb +43 -2
  160. data/lib/puppet/provider/service/src.rb +27 -0
  161. data/lib/puppet/provider/service/systemd.rb +15 -3
  162. data/lib/puppet/provider/sshkey/parsed.rb +19 -9
  163. data/lib/puppet/reference/report.rb +9 -12
  164. data/lib/puppet/reports.rb +5 -1
  165. data/lib/puppet/resource.rb +50 -73
  166. data/lib/puppet/resource/capability_finder.rb +95 -0
  167. data/lib/puppet/resource/catalog.rb +47 -7
  168. data/lib/puppet/resource/status.rb +0 -2
  169. data/lib/puppet/resource/type.rb +238 -44
  170. data/lib/puppet/resource/type_collection.rb +60 -2
  171. data/lib/puppet/settings.rb +2 -2
  172. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  173. data/lib/puppet/ssl/oids.rb +9 -1
  174. data/lib/puppet/transaction.rb +4 -1
  175. data/lib/puppet/transaction/additional_resource_generator.rb +71 -8
  176. data/lib/puppet/transaction/resource_harness.rb +9 -4
  177. data/lib/puppet/type.rb +74 -3
  178. data/lib/puppet/type/augeas.rb +8 -0
  179. data/lib/puppet/type/file/source.rb +14 -12
  180. data/lib/puppet/type/user.rb +4 -2
  181. data/lib/puppet/util/windows/security.rb +4 -1
  182. data/lib/puppet/util/windows/taskscheduler.rb +1 -1
  183. data/lib/puppet/version.rb +1 -1
  184. data/spec/fixtures/unit/application/environments/production/data/common.yaml +3 -0
  185. data/spec/fixtures/unit/application/environments/production/environment.conf +1 -0
  186. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/data/bad.json +3 -0
  187. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/environment.conf +2 -0
  188. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/hiera.yaml +5 -0
  189. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/manifests/site.pp +5 -0
  190. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/data/bad.yaml +3 -0
  191. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/environment.conf +2 -0
  192. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/hiera.yaml +5 -0
  193. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/manifests/site.pp +5 -0
  194. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/data/common.yaml +2 -0
  195. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/environment.conf +2 -0
  196. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/manifests/site.pp +1 -0
  197. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/data/common.yaml +2 -0
  198. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/manifests/init.pp +5 -0
  199. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/metadata.json +9 -0
  200. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/first.json +3 -0
  201. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/name.yaml +2 -0
  202. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/second.json +3 -0
  203. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/single.yaml +2 -0
  204. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data2/single.yaml +2 -0
  205. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/environment.conf +2 -0
  206. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/hiera.yaml +18 -0
  207. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/manifests/site.pp +5 -0
  208. data/spec/fixtures/unit/data_providers/environments/hiera_misc/data/common.yaml +46 -0
  209. data/spec/fixtures/unit/data_providers/environments/hiera_misc/environment.conf +2 -0
  210. data/spec/fixtures/unit/data_providers/environments/hiera_misc/manifests/site.pp +1 -0
  211. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/data/common.yaml +30 -0
  212. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/manifests/init.pp +13 -0
  213. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/metadata.json +9 -0
  214. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/environment.conf +2 -0
  215. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/manifests/site.pp +1 -0
  216. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/first.json +3 -0
  217. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/name.yaml +1 -0
  218. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/second.json +3 -0
  219. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/single.yaml +2 -0
  220. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data2/single.yaml +2 -0
  221. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/hiera.yaml +18 -0
  222. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/manifests/init.pp +5 -0
  223. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/metadata.json +9 -0
  224. data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/lib/puppet_x/helindbe/sample_env_data.rb +1 -0
  225. data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/lib/puppet_x/helindbe/sample_module_data.rb +1 -0
  226. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/data/first.json +3 -0
  227. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/hiera.yaml +8 -0
  228. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/manifests/init.pp +5 -0
  229. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/metadata.json +9 -0
  230. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/lib/puppet/functions/meta/data.rb +9 -0
  231. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/manifests/init.pp +3 -0
  232. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/metadata.json +9 -0
  233. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/lib/puppet/bindings/metawcp/default.rb +10 -0
  234. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/lib/puppet_x/thallgren/sample_module_data.rb +23 -0
  235. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/manifests/init.pp +3 -0
  236. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/metadata.json +9 -0
  237. data/spec/fixtures/unit/provider/package/yum/yum-check-update-security.txt +184 -0
  238. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_get/should_yield_to_the_block.yml +24 -0
  239. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_head/should_yield_to_the_block.yml +24 -0
  240. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_post/should_yield_to_the_block.yml +24 -0
  241. data/spec/integration/data_binding_spec.rb +229 -0
  242. data/spec/integration/file_bucket/file_spec.rb +2 -2
  243. data/spec/integration/parser/compiler_spec.rb +23 -19
  244. data/spec/integration/parser/resource_expressions_spec.rb +4 -4
  245. data/spec/integration/parser/undef_param_spec.rb +1 -1
  246. data/spec/integration/resource/catalog_spec.rb +1 -1
  247. data/spec/integration/type/package_spec.rb +2 -0
  248. data/spec/integration/util/windows/security_spec.rb +18 -0
  249. data/spec/lib/matchers/include_in_order.rb +2 -2
  250. data/spec/shared_behaviours/iterative_functions.rb +8 -8
  251. data/spec/spec_helper.rb +7 -0
  252. data/spec/unit/agent/locker_spec.rb +4 -4
  253. data/spec/unit/agent_spec.rb +0 -8
  254. data/spec/unit/application/agent_spec.rb +5 -0
  255. data/spec/unit/application/apply_spec.rb +8 -0
  256. data/spec/unit/application/filebucket_spec.rb +87 -1
  257. data/spec/unit/application/lookup_spec.rb +195 -0
  258. data/spec/unit/appmgmt_spec.rb +657 -0
  259. data/spec/unit/capability_spec.rb +414 -0
  260. data/spec/unit/configurer_spec.rb +7 -1
  261. data/spec/unit/context/trusted_information_spec.rb +24 -1
  262. data/spec/unit/daemon_spec.rb +18 -8
  263. data/spec/unit/data_providers/hiera_data_provider_spec.rb +201 -0
  264. data/spec/unit/file_bucket/dipper_spec.rb +210 -1
  265. data/spec/unit/functions/assert_type_spec.rb +5 -7
  266. data/spec/unit/functions/defined_spec.rb +2 -2
  267. data/spec/unit/functions/epp_spec.rb +2 -2
  268. data/spec/unit/functions/lookup_spec.rb +200 -9
  269. data/spec/unit/functions/regsubst_spec.rb +17 -8
  270. data/spec/unit/functions/scanf_spec.rb +1 -1
  271. data/spec/unit/functions/split_spec.rb +2 -2
  272. data/spec/unit/functions/versioncmp_spec.rb +36 -0
  273. data/spec/unit/functions4_spec.rb +58 -72
  274. data/spec/unit/indirector/catalog/compiler_spec.rb +28 -8
  275. data/spec/unit/indirector/catalog/static_compiler_spec.rb +38 -20
  276. data/spec/unit/indirector/data_binding/none_spec.rb +2 -2
  277. data/spec/unit/indirector/file_bucket_file/file_spec.rb +52 -1
  278. data/spec/unit/indirector/request_spec.rb +8 -8
  279. data/spec/unit/info_service_spec.rb +236 -0
  280. data/spec/unit/module_tool/metadata_spec.rb +31 -2
  281. data/spec/unit/network/authconfig_spec.rb +62 -32
  282. data/spec/unit/network/authorization_spec.rb +30 -2
  283. data/spec/unit/network/http/connection_spec.rb +14 -19
  284. data/spec/unit/parser/compiler_spec.rb +86 -2
  285. data/spec/unit/parser/functions/create_resources_spec.rb +1 -1
  286. data/spec/unit/parser/resource_spec.rb +2 -20
  287. data/spec/unit/pops/binder/config/binder_config_spec.rb +1 -1
  288. data/spec/unit/pops/binder/injector_spec.rb +3 -3
  289. data/spec/unit/pops/evaluator/access_ops_spec.rb +13 -11
  290. data/spec/unit/pops/evaluator/basic_expressions_spec.rb +1 -2
  291. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +19 -11
  292. data/spec/unit/pops/evaluator/literal_evaluator_spec.rb +43 -0
  293. data/spec/unit/pops/label_provider_spec.rb +5 -1
  294. data/spec/unit/pops/parser/lexer2_spec.rb +33 -7
  295. data/spec/unit/pops/parser/parse_application_spec.rb +40 -0
  296. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +4 -0
  297. data/spec/unit/pops/parser/parse_capabilities_spec.rb +47 -0
  298. data/spec/unit/pops/parser/parse_site_spec.rb +38 -0
  299. data/spec/unit/pops/parser/parser_rspec_helper.rb +5 -0
  300. data/spec/unit/pops/parser/parser_spec.rb +18 -0
  301. data/spec/unit/pops/types/type_calculator_spec.rb +427 -444
  302. data/spec/unit/pops/types/type_factory_spec.rb +12 -12
  303. data/spec/unit/pops/types/type_parser_spec.rb +7 -12
  304. data/spec/unit/pops/validator/validator_spec.rb +25 -0
  305. data/spec/unit/provider/augeas/augeas_spec.rb +50 -0
  306. data/spec/unit/provider/group/directoryservice_spec.rb +33 -0
  307. data/spec/unit/provider/group/windows_adsi_spec.rb +3 -0
  308. data/spec/unit/provider/package/dnf_spec.rb +92 -0
  309. data/spec/unit/provider/package/gem_spec.rb +7 -0
  310. data/spec/unit/provider/package/rpm_spec.rb +25 -2
  311. data/spec/unit/provider/package/windows/package_spec.rb +41 -0
  312. data/spec/unit/provider/package/yum_spec.rb +21 -13
  313. data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +10 -0
  314. data/spec/unit/provider/service/debian_spec.rb +27 -0
  315. data/spec/unit/provider/service/rcng_spec.rb +41 -0
  316. data/spec/unit/provider/service/redhat_spec.rb +8 -1
  317. data/spec/unit/provider/service/smf_spec.rb +30 -5
  318. data/spec/unit/provider/service/src_spec.rb +19 -4
  319. data/spec/unit/provider/service/systemd_spec.rb +78 -29
  320. data/spec/unit/provider/sshkey/parsed_spec.rb +23 -0
  321. data/spec/unit/reports_spec.rb +10 -0
  322. data/spec/unit/resource/capability_finder_spec.rb +56 -0
  323. data/spec/unit/resource/catalog_spec.rb +31 -8
  324. data/spec/unit/resource/type_collection_spec.rb +23 -2
  325. data/spec/unit/resource/type_spec.rb +1 -1
  326. data/spec/unit/resource_spec.rb +22 -4
  327. data/spec/unit/settings_spec.rb +90 -1
  328. data/spec/unit/ssl/certificate_authority/interface_spec.rb +4 -3
  329. data/spec/unit/ssl/oids_spec.rb +8 -0
  330. data/spec/unit/transaction/additional_resource_generator_spec.rb +78 -5
  331. data/spec/unit/transaction/report_spec.rb +24 -1
  332. data/spec/unit/type/package_spec.rb +1 -0
  333. data/spec/unit/type/user_spec.rb +14 -7
  334. data/spec/unit/type_spec.rb +1 -1
  335. metadata +169 -5
  336. data/lib/puppet/pops/evaluator/callable_mismatch_describer.rb +0 -175
  337. data/spec/integration/data_binding.rb +0 -104
@@ -2,7 +2,11 @@ require 'spec_helper'
2
2
  require 'puppet/pops'
3
3
 
4
4
  describe Puppet::Pops::LabelProvider do
5
- let(:labeler) { Puppet::Pops::LabelProvider.new }
5
+ class TestLabelProvider
6
+ include Puppet::Pops::LabelProvider
7
+ end
8
+
9
+ let(:labeler) { TestLabelProvider.new }
6
10
 
7
11
  it "prefixes words that start with a vowel with an 'an'" do
8
12
  expect(labeler.a_an('owl')).to eq('an owl')
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
  require 'matchers/match_tokens2'
3
3
  require 'puppet/pops'
4
4
  require 'puppet/pops/parser/lexer2'
5
+ require_relative './parser_rspec_helper'
5
6
 
6
7
  module EgrammarLexer2Spec
7
8
  def tokens_scanned_from(s)
@@ -19,6 +20,7 @@ end
19
20
 
20
21
  describe 'Lexer2' do
21
22
  include EgrammarLexer2Spec
23
+ include ParserRspecHelper
22
24
 
23
25
  {
24
26
  :LISTSTART => '[',
@@ -100,13 +102,37 @@ describe 'Lexer2' do
100
102
  end
101
103
  end
102
104
 
103
- {
104
- "application" => :APPLICATION_R,
105
- "consumes" => :CONSUMES_R,
106
- "produces" => :PRODUCES_R,
107
- }.each do |string, name|
108
- it "should lex a (future reserved) keyword from '#{string}'" do
109
- expect(tokens_scanned_from(string)).to match_tokens2(name)
105
+ context 'when app_management is off (by default)' do
106
+ {
107
+ "application" => :APPLICATION_R,
108
+ "consumes" => :CONSUMES_R,
109
+ "produces" => :PRODUCES_R,
110
+ "site" => :SITE_R,
111
+ }.each do |string, name|
112
+ it "should lex a (future reserved) keyword from '#{string}'" do
113
+ expect(tokens_scanned_from(string)).to match_tokens2(name)
114
+ end
115
+ end
116
+ end
117
+
118
+ context 'when app_managment is (turned) on' do
119
+ before(:each) do
120
+ with_app_management(true)
121
+ end
122
+
123
+ after(:each) do
124
+ with_app_management(false)
125
+ end
126
+
127
+ {
128
+ "application" => :APPLICATION,
129
+ "consumes" => :CONSUMES,
130
+ "produces" => :PRODUCES,
131
+ "site" => :SITE,
132
+ }.each do |string, name|
133
+ it "should lex a keyword from '#{string}'" do
134
+ expect(tokens_scanned_from(string)).to match_tokens2(name)
135
+ end
110
136
  end
111
137
  end
112
138
 
@@ -0,0 +1,40 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/pops'
4
+ require_relative './parser_rspec_helper'
5
+
6
+ describe "egrammar parsing of 'application'" do
7
+ include ParserRspecHelper
8
+
9
+ before(:each) do
10
+ with_app_management(true)
11
+ end
12
+
13
+ after(:each) do
14
+ with_app_management(false)
15
+ end
16
+
17
+ it "an empty body" do
18
+ expect(dump(parse("application foo { }"))).to eq("(application foo () ())")
19
+ end
20
+
21
+ it "an empty body" do
22
+ prog = <<-EPROG
23
+ application foo {
24
+ db { one:
25
+ password => 'secret'
26
+ }
27
+ }
28
+ EPROG
29
+ expect(dump(parse(prog))).to eq( [
30
+ "(application foo () (block",
31
+ " (resource db",
32
+ " (one",
33
+ " (password => 'secret')))", "))" ].join("\n"))
34
+ end
35
+
36
+ it "accepts parameters" do
37
+ s = "application foo($p1 = 'yo', $p2) { }"
38
+ expect(dump(parse(s))).to eq("(application foo ((= p1 'yo') p2) ())")
39
+ end
40
+ end
@@ -175,6 +175,10 @@ describe "egrammar parsing basic expressions" do
175
175
  expect(dump(parse("$a = $b[2]"))).to eq("(= $a (slice $b 2))")
176
176
  end
177
177
 
178
+ it "$a = $b[2,]" do
179
+ expect(dump(parse("$a = $b[2,]"))).to eq("(= $a (slice $b 2))")
180
+ end
181
+
178
182
  it "$a = [1, 2, 3][2]" do
179
183
  expect(dump(parse("$a = [1,2,3][2]"))).to eq("(= $a (slice ([] 1 2 3) 2))")
180
184
  end
@@ -0,0 +1,47 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/pops'
4
+
5
+ # relative to this spec file (./) does not work as this file is loaded by rspec
6
+ require File.join(File.dirname(__FILE__), '/parser_rspec_helper')
7
+
8
+ describe "egrammar parsing of capability mappings" do
9
+ include ParserRspecHelper
10
+
11
+ before(:each) do
12
+ with_app_management(true)
13
+ end
14
+
15
+ after(:each) do
16
+ with_app_management(false)
17
+ end
18
+
19
+ context "when parsing 'produces'" do
20
+ it "the ast contains produces and attributes" do
21
+ prog = "Foo produces Sql { name => value }"
22
+ ast = "(produces Foo Sql ((name => value)))"
23
+ expect(dump(parse(prog))).to eq(ast)
24
+ end
25
+
26
+ it "optional end comma is allowed" do
27
+ prog = "Foo produces Sql { name => value, }"
28
+ ast = "(produces Foo Sql ((name => value)))"
29
+ expect(dump(parse(prog))).to eq(ast)
30
+ end
31
+ end
32
+
33
+ context "when parsing 'consumes'" do
34
+ it "the ast contains consumes and attributes" do
35
+ prog = "Foo consumes Sql { name => value }"
36
+ ast = "(consumes Foo Sql ((name => value)))"
37
+ expect(dump(parse(prog))).to eq(ast)
38
+ end
39
+
40
+ it "optional end comma is allowed" do
41
+ prog = "Foo consumes Sql { name => value, }"
42
+ ast = "(consumes Foo Sql ((name => value)))"
43
+ expect(dump(parse(prog))).to eq(ast)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,38 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet/pops'
4
+
5
+ # relative to this spec file (./) does not work as this file is loaded by rspec
6
+ require File.join(File.dirname(__FILE__), '/parser_rspec_helper')
7
+
8
+ describe "egrammar parsing of site expression" do
9
+ include ParserRspecHelper
10
+
11
+ before(:each) do
12
+ with_app_management(true)
13
+ end
14
+
15
+ after(:each) do
16
+ with_app_management(false)
17
+ end
18
+
19
+ context "when parsing 'site'" do
20
+ it "an empty body is allowed" do
21
+ prog = "site { }"
22
+ ast = "(site ())"
23
+ expect(dump(parse(prog))).to eq(ast)
24
+ end
25
+
26
+ it "a body with one expression is allowed" do
27
+ prog = "site { $x = 1 }"
28
+ ast = "(site (block\n (= $x 1)\n))"
29
+ expect(dump(parse(prog))).to eq(ast)
30
+ end
31
+
32
+ it "a body with more than one expression is allowed" do
33
+ prog = "site { $x = 1 $y = 2}"
34
+ ast = "(site (block\n (= $x 1)\n (= $y 2)\n))"
35
+ expect(dump(parse(prog))).to eq(ast)
36
+ end
37
+ end
38
+ end
@@ -4,6 +4,11 @@ require File.join(File.dirname(__FILE__), '/../factory_rspec_helper')
4
4
 
5
5
  module ParserRspecHelper
6
6
  include FactoryRspecHelper
7
+
8
+ def with_app_management(flag)
9
+ Puppet[:app_management] = flag
10
+ end
11
+
7
12
  def parse(code)
8
13
  parser = Puppet::Pops::Parser::Parser.new()
9
14
  parser.parse_string(code)
@@ -44,4 +44,22 @@ describe Puppet::Pops::Parser::Parser do
44
44
  expect(the_error.line).to eq(1)
45
45
  expect(the_error.pos).to eq(6)
46
46
  end
47
+
48
+ it "should raise an error with position information when error is raised on token" do
49
+ parser = Puppet::Pops::Parser::Parser.new()
50
+ the_error = nil
51
+ begin
52
+ parser.parse_string(<<-EOF, 'fakefile.pp')
53
+ class whoops($a,$b,$c) {
54
+ $d = "oh noes", "b"
55
+ }
56
+ EOF
57
+ rescue Puppet::ParseError => e
58
+ the_error = e
59
+ end
60
+ expect(the_error).to be_a(Puppet::ParseError)
61
+ expect(the_error.file).to eq('fakefile.pp')
62
+ expect(the_error.line).to eq(2)
63
+ expect(the_error.pos).to eq(17)
64
+ end
47
65
  end
@@ -2,16 +2,10 @@ require 'spec_helper'
2
2
  require 'puppet/pops'
3
3
 
4
4
  describe 'The type calculator' do
5
- let(:calculator) { Puppet::Pops::Types::TypeCalculator.new() }
5
+ let(:calculator) { Puppet::Pops::Types::TypeCalculator.new }
6
6
 
7
7
  def range_t(from, to)
8
- t = Puppet::Pops::Types::PIntegerType.new
9
- t.from = from
10
- t.to = to
11
- t
12
- end
13
- def constrained_t(t, from, to)
14
- Puppet::Pops::Types::TypeFactory.constrain_size(t, from, to)
8
+ Puppet::Pops::Types::PIntegerType.new(from, to)
15
9
  end
16
10
 
17
11
  def pattern_t(*patterns)
@@ -23,22 +17,19 @@ describe 'The type calculator' do
23
17
  end
24
18
 
25
19
  def string_t(*strings)
26
- Puppet::Pops::Types::TypeFactory.string(*strings)
20
+ Puppet::Pops::Types::TypeFactory.string(nil, *strings)
27
21
  end
28
22
 
29
- def callable_t(*params)
30
- Puppet::Pops::Types::TypeFactory.callable(*params)
31
- end
32
- def all_callables_t(*params)
33
- Puppet::Pops::Types::TypeFactory.all_callables()
23
+ def constrained_string_t(size_type, *strings)
24
+ Puppet::Pops::Types::TypeFactory.string(size_type, *strings)
34
25
  end
35
26
 
36
- def with_block_t(callable_t, *params)
37
- Puppet::Pops::Types::TypeFactory.with_block(callable_t, *params)
27
+ def callable_t(*params)
28
+ Puppet::Pops::Types::TypeFactory.callable(*params)
38
29
  end
39
30
 
40
- def with_optional_block_t(callable_t, *params)
41
- Puppet::Pops::Types::TypeFactory.with_optional_block(callable_t, *params)
31
+ def all_callables_t
32
+ Puppet::Pops::Types::TypeFactory.all_callables
42
33
  end
43
34
 
44
35
  def enum_t(*strings)
@@ -49,32 +40,40 @@ describe 'The type calculator' do
49
40
  Puppet::Pops::Types::TypeFactory.variant(*types)
50
41
  end
51
42
 
52
- def integer_t()
53
- Puppet::Pops::Types::TypeFactory.integer()
43
+ def integer_t
44
+ Puppet::Pops::Types::TypeFactory.integer
45
+ end
46
+
47
+ def array_t(t, s = nil)
48
+ Puppet::Pops::Types::TypeFactory.array_of(t, s)
54
49
  end
55
50
 
56
- def array_t(t)
57
- Puppet::Pops::Types::TypeFactory.array_of(t)
51
+ def empty_array_t
52
+ empty_array = array_t(unit_t, range_t(0,0))
58
53
  end
59
54
 
60
- def hash_t(k,v)
61
- Puppet::Pops::Types::TypeFactory.hash_of(v, k)
55
+ def hash_t(k,v,s = nil)
56
+ Puppet::Pops::Types::TypeFactory.hash_of(v, k, s)
62
57
  end
63
58
 
64
- def data_t()
65
- Puppet::Pops::Types::TypeFactory.data()
59
+ def data_t
60
+ Puppet::Pops::Types::TypeFactory.data
66
61
  end
67
62
 
68
- def factory()
63
+ def factory
69
64
  Puppet::Pops::Types::TypeFactory
70
65
  end
71
66
 
72
- def collection_t()
73
- Puppet::Pops::Types::TypeFactory.collection()
67
+ def collection_t(size_type = nil)
68
+ Puppet::Pops::Types::TypeFactory.collection(size_type)
74
69
  end
75
70
 
76
71
  def tuple_t(*types)
77
- Puppet::Pops::Types::TypeFactory.tuple(*types)
72
+ Puppet::Pops::Types::TypeFactory.tuple(types)
73
+ end
74
+
75
+ def constrained_tuple_t(size_type, *types)
76
+ Puppet::Pops::Types::TypeFactory.tuple(types, size_type)
78
77
  end
79
78
 
80
79
  def struct_t(type_hash)
@@ -82,7 +81,7 @@ describe 'The type calculator' do
82
81
  end
83
82
 
84
83
  def object_t
85
- Puppet::Pops::Types::TypeFactory.any()
84
+ Puppet::Pops::Types::TypeFactory.any
86
85
  end
87
86
 
88
87
  def optional_t(t)
@@ -99,14 +98,14 @@ describe 'The type calculator' do
99
98
 
100
99
  def unit_t
101
100
  # Cannot be created via factory, the type is private to the type system
102
- Puppet::Pops::Types::PUnitType.new
101
+ Puppet::Pops::Types::PUnitType::DEFAULT
103
102
  end
104
103
 
105
104
  def types
106
105
  Puppet::Pops::Types
107
106
  end
108
107
 
109
- shared_context "types_setup" do
108
+ shared_context 'types_setup' do
110
109
 
111
110
  # Do not include the special type Unit in this list
112
111
  def all_types
@@ -186,18 +185,16 @@ describe 'The type calculator' do
186
185
  def data_compatible_types
187
186
  result = scalar_types
188
187
  result << Puppet::Pops::Types::PDataType
189
- result << array_t(types::PDataType.new)
188
+ result << array_t(types::PDataType::DEFAULT)
190
189
  result << types::TypeFactory.hash_of_data
191
190
  result << Puppet::Pops::Types::PUndefType
192
191
  result << not_undef_t(types::PDataType.new)
193
- tmp = tuple_t(types::PDataType.new)
194
- result << (tmp)
195
- tmp.size_type = range_t(0, nil)
192
+ result << constrained_tuple_t(range_t(0, nil), types::PDataType::DEFAULT)
196
193
  result
197
194
  end
198
195
 
199
196
  def type_from_class(c)
200
- c.is_a?(Class) ? c.new : c
197
+ c.is_a?(Class) ? c::DEFAULT : c
201
198
  end
202
199
  end
203
200
 
@@ -255,6 +252,30 @@ describe 'The type calculator' do
255
252
  expect(t.runtime_type_name).to eq('Foo')
256
253
  end
257
254
 
255
+ it 'Class Foo translates to PType[PRuntimeType[ruby, Foo]]' do
256
+ class Foo
257
+ end
258
+
259
+ t = calculator.infer(Foo)
260
+ expect(t.class).to eq(Puppet::Pops::Types::PType)
261
+ tt = t.type
262
+ expect(tt.class).to eq(Puppet::Pops::Types::PRuntimeType)
263
+ expect(tt.runtime).to eq(:ruby)
264
+ expect(tt.runtime_type_name).to eq('Foo')
265
+ end
266
+
267
+ it 'Module FooModule translates to PType[PRuntimeType[ruby, FooModule]]' do
268
+ module FooModule
269
+ end
270
+
271
+ t = calculator.infer(FooModule)
272
+ expect(t.class).to eq(Puppet::Pops::Types::PType)
273
+ tt = t.type
274
+ expect(tt.class).to eq(Puppet::Pops::Types::PRuntimeType)
275
+ expect(tt.runtime).to eq(:ruby)
276
+ expect(tt.runtime_type_name).to eq('FooModule')
277
+ end
278
+
258
279
  context 'array' do
259
280
  it 'translates to PArrayType' do
260
281
  expect(calculator.infer([1,2]).class).to eq(Puppet::Pops::Types::PArrayType)
@@ -275,7 +296,7 @@ describe 'The type calculator' do
275
296
  expect(t.to).to eq(42)
276
297
  end
277
298
 
278
- it "Compound string values are computed" do
299
+ it 'Compound string values are computed' do
279
300
  t = calculator.infer(['a','b', 'c']).element_type
280
301
  expect(t.class).to eq(Puppet::Pops::Types::PStringType)
281
302
  expect(t.values).to eq(['a', 'b', 'c'])
@@ -380,7 +401,7 @@ describe 'The type calculator' do
380
401
  end
381
402
 
382
403
  it 'when empty is not assignable to a PHashType with from size > 0' do
383
- expect(calculator.assignable?(constrained_t(hash_t(string_t,string_t), 1, 1), calculator.infer({}))).to eq(false)
404
+ expect(calculator.assignable?(hash_t(string_t,string_t,range_t(1, 1)), calculator.infer({}))).to eq(false)
384
405
  end
385
406
 
386
407
  context 'using infer_set' do
@@ -414,7 +435,7 @@ describe 'The type calculator' do
414
435
  end
415
436
 
416
437
  context 'patterns' do
417
- it "constructs a PPatternType" do
438
+ it 'constructs a PPatternType' do
418
439
  t = pattern_t('a(b)c')
419
440
  expect(t.class).to eq(Puppet::Pops::Types::PPatternType)
420
441
  expect(t.patterns.size).to eq(1)
@@ -423,58 +444,46 @@ describe 'The type calculator' do
423
444
  expect(t.patterns[0].regexp.match('abc')[1]).to eq('b')
424
445
  end
425
446
 
426
- it "constructs a PStringType with multiple strings" do
447
+ it 'constructs a PStringType with multiple strings' do
427
448
  t = string_t('a', 'b', 'c', 'abc')
428
- expect(t.values).to eq(['a', 'b', 'c', 'abc'])
449
+ expect(t.values).to eq(['a', 'b', 'c', 'abc'].sort)
429
450
  end
430
451
  end
431
452
 
432
453
  # Deal with cases not covered by computing common type
433
454
  context 'when computing common type' do
434
455
  it 'computes given resource type commonality' do
435
- r1 = Puppet::Pops::Types::PResourceType.new()
436
- r1.type_name = 'File'
437
- r2 = Puppet::Pops::Types::PResourceType.new()
438
- r2.type_name = 'File'
439
- expect(calculator.string(calculator.common_type(r1, r2))).to eq("File")
440
-
441
- r2 = Puppet::Pops::Types::PResourceType.new()
442
- r2.type_name = 'File'
443
- r2.title = '/tmp/foo'
444
- expect(calculator.string(calculator.common_type(r1, r2))).to eq("File")
445
-
446
- r1 = Puppet::Pops::Types::PResourceType.new()
447
- r1.type_name = 'File'
448
- r1.title = '/tmp/foo'
456
+ r1 = Puppet::Pops::Types::PResourceType.new('File', nil)
457
+ r2 = Puppet::Pops::Types::PResourceType.new('File', nil)
458
+ expect(calculator.string(calculator.common_type(r1, r2))).to eq('File')
459
+
460
+
461
+ r2 = Puppet::Pops::Types::PResourceType.new('File', '/tmp/foo')
462
+ expect(calculator.string(calculator.common_type(r1, r2))).to eq('File')
463
+
464
+ r1 = Puppet::Pops::Types::PResourceType.new('File', '/tmp/foo')
449
465
  expect(calculator.string(calculator.common_type(r1, r2))).to eq("File['/tmp/foo']")
450
466
 
451
- r1 = Puppet::Pops::Types::PResourceType.new()
452
- r1.type_name = 'File'
453
- r1.title = '/tmp/bar'
454
- expect(calculator.string(calculator.common_type(r1, r2))).to eq("File")
467
+ r1 = Puppet::Pops::Types::PResourceType.new('File', '/tmp/bar')
468
+ expect(calculator.string(calculator.common_type(r1, r2))).to eq('File')
455
469
 
456
- r2 = Puppet::Pops::Types::PResourceType.new()
457
- r2.type_name = 'Package'
458
- r2.title = 'apache'
459
- expect(calculator.string(calculator.common_type(r1, r2))).to eq("Resource")
470
+ r2 = Puppet::Pops::Types::PResourceType.new('Package', 'apache')
471
+ expect(calculator.string(calculator.common_type(r1, r2))).to eq('Resource')
460
472
  end
461
473
 
462
474
  it 'computes given hostclass type commonality' do
463
- r1 = Puppet::Pops::Types::PHostClassType.new()
464
- r1.class_name = 'foo'
465
- r2 = Puppet::Pops::Types::PHostClassType.new()
466
- r2.class_name = 'foo'
467
- expect(calculator.string(calculator.common_type(r1, r2))).to eq("Class[foo]")
475
+ r1 = Puppet::Pops::Types::PHostClassType.new('foo')
476
+ r2 = Puppet::Pops::Types::PHostClassType.new('foo')
477
+ expect(calculator.string(calculator.common_type(r1, r2))).to eq('Class[foo]')
468
478
 
469
- r2 = Puppet::Pops::Types::PHostClassType.new()
470
- r2.class_name = 'bar'
471
- expect(calculator.string(calculator.common_type(r1, r2))).to eq("Class")
479
+ r2 = Puppet::Pops::Types::PHostClassType.new('bar')
480
+ expect(calculator.string(calculator.common_type(r1, r2))).to eq('Class')
472
481
 
473
- r2 = Puppet::Pops::Types::PHostClassType.new()
474
- expect(calculator.string(calculator.common_type(r1, r2))).to eq("Class")
482
+ r2 = Puppet::Pops::Types::PHostClassType.new(nil)
483
+ expect(calculator.string(calculator.common_type(r1, r2))).to eq('Class')
475
484
 
476
- r1 = Puppet::Pops::Types::PHostClassType.new()
477
- expect(calculator.string(calculator.common_type(r1, r2))).to eq("Class")
485
+ r1 = Puppet::Pops::Types::PHostClassType.new(nil)
486
+ expect(calculator.string(calculator.common_type(r1, r2))).to eq('Class')
478
487
  end
479
488
 
480
489
  context 'of strings' do
@@ -487,10 +496,8 @@ describe 'The type calculator' do
487
496
  end
488
497
 
489
498
  it 'computes common size_type' do
490
- t1 = string_t
491
- t1.size_type = range_t(3,6)
492
- t2 = string_t
493
- t2.size_type = range_t(2,4)
499
+ t1 = constrained_string_t(range_t(3,6))
500
+ t2 = constrained_string_t(range_t(2,4))
494
501
  common_t = calculator.common_type(t1,t2)
495
502
  expect(common_t.class).to eq(Puppet::Pops::Types::PStringType)
496
503
  expect(common_t.size_type).to eq(range_t(2,6))
@@ -498,18 +505,15 @@ describe 'The type calculator' do
498
505
 
499
506
  it 'computes common size_type to be undef when one of the types has no size_type' do
500
507
  t1 = string_t
501
- t2 = string_t
502
- t2.size_type = range_t(2,4)
508
+ t2 = constrained_string_t(range_t(2,4))
503
509
  common_t = calculator.common_type(t1,t2)
504
510
  expect(common_t.class).to eq(Puppet::Pops::Types::PStringType)
505
511
  expect(common_t.size_type).to be_nil
506
512
  end
507
513
 
508
514
  it 'computes values to be empty if the one has empty values' do
509
- t1 = string_t('apa')
510
- t1.size_type = range_t(3,6)
511
- t2 = string_t
512
- t2.size_type = range_t(2,4)
515
+ t1 = constrained_string_t(range_t(3,6), 'apa')
516
+ t2 = constrained_string_t(range_t(2,4))
513
517
  common_t = calculator.common_type(t1,t2)
514
518
  expect(common_t.class).to eq(Puppet::Pops::Types::PStringType)
515
519
  expect(common_t.values).to be_empty
@@ -522,7 +526,7 @@ describe 'The type calculator' do
522
526
  common_t = calculator.common_type(t1,t2)
523
527
  expect(common_t.class).to eq(Puppet::Pops::Types::PPatternType)
524
528
  expect(common_t.patterns.map { |pr| pr.pattern }).to eq(['abc', 'xyz'])
525
- expect(calculator.string(common_t)).to eq("Pattern[/abc/, /xyz/]")
529
+ expect(calculator.string(common_t)).to eq('Pattern[/abc/, /xyz/]')
526
530
  end
527
531
 
528
532
  it 'computes enum commonality to value set sum' do
@@ -533,7 +537,7 @@ describe 'The type calculator' do
533
537
  end
534
538
 
535
539
  it 'computed variant commonality to type union where added types are not sub-types' do
536
- a_t1 = integer_t()
540
+ a_t1 = integer_t
537
541
  a_t2 = enum_t('b')
538
542
  v_a = variant_t(a_t1, a_t2)
539
543
  b_t1 = enum_t('a')
@@ -544,8 +548,8 @@ describe 'The type calculator' do
544
548
  end
545
549
 
546
550
  it 'computed variant commonality to type union where added types are sub-types' do
547
- a_t1 = integer_t()
548
- a_t2 = string_t()
551
+ a_t1 = integer_t
552
+ a_t2 = string_t
549
553
  v_a = variant_t(a_t1, a_t2)
550
554
  b_t1 = enum_t('a')
551
555
  v_b = variant_t(b_t1)
@@ -554,7 +558,7 @@ describe 'The type calculator' do
554
558
  expect(Set.new(common_t.types)).to eq(Set.new([a_t1, a_t2]))
555
559
  end
556
560
 
557
- context "of callables" do
561
+ context 'of callables' do
558
562
  it 'incompatible instances => generic callable' do
559
563
  t1 = callable_t(String)
560
564
  t2 = callable_t(Integer)
@@ -576,8 +580,10 @@ describe 'The type calculator' do
576
580
  end
577
581
 
578
582
  it 'block_type is included in the check (incompatible block)' do
579
- t1 = with_block_t(callable_t(String), String)
580
- t2 = with_block_t(callable_t(String), Integer)
583
+ b1 = callable_t(String)
584
+ b2 = callable_t(Integer)
585
+ t1 = callable_t(String, b1)
586
+ t2 = callable_t(String, b2)
581
587
  common_t = calculator.common_type(t1, t2)
582
588
  expect(common_t.class).to be(Puppet::Pops::Types::PCallableType)
583
589
  expect(common_t.param_types).to be_nil
@@ -585,9 +591,11 @@ describe 'The type calculator' do
585
591
  end
586
592
 
587
593
  it 'block_type is included in the check (compatible block)' do
588
- t1 = with_block_t(callable_t(String), String)
589
- scalar_t = Puppet::Pops::Types::PScalarType.new
590
- t2 = with_block_t(callable_t(String), scalar_t)
594
+ b1 = callable_t(String)
595
+ t1 = callable_t(String, b1)
596
+ scalar_t = Puppet::Pops::Types::PScalarType::DEFAULT
597
+ b2 = callable_t(scalar_t)
598
+ t2 = callable_t(String, b2)
591
599
  common_t = calculator.common_type(t1, t2)
592
600
  expect(common_t.param_types.class).to be(Puppet::Pops::Types::PTupleType)
593
601
  expect(common_t.block_type).to eql(callable_t(scalar_t))
@@ -596,43 +604,43 @@ describe 'The type calculator' do
596
604
  end
597
605
 
598
606
  context 'computes assignability' do
599
- include_context "types_setup"
607
+ include_context 'types_setup'
600
608
 
601
609
  it 'such that all types are assignable to themselves' do
602
610
  all_types.each do |tc|
603
- t = tc.new
611
+ t = tc::DEFAULT
604
612
  expect(t).to be_assignable_to(t)
605
613
  end
606
614
  end
607
615
 
608
616
  context 'for Unit, such that' do
609
617
  it 'all types are assignable to Unit' do
610
- t = Puppet::Pops::Types::PUnitType.new()
611
- all_types.each { |t2| expect(t2.new).to be_assignable_to(t) }
618
+ t = Puppet::Pops::Types::PUnitType::DEFAULT
619
+ all_types.each { |t2| expect(t2::DEFAULT).to be_assignable_to(t) }
612
620
  end
613
621
 
614
622
  it 'Unit is assignable to all other types' do
615
- t = Puppet::Pops::Types::PUnitType.new()
616
- all_types.each { |t2| expect(t).to be_assignable_to(t2.new) }
623
+ t = Puppet::Pops::Types::PUnitType::DEFAULT
624
+ all_types.each { |t2| expect(t).to be_assignable_to(t2::DEFAULT) }
617
625
  end
618
626
 
619
627
  it 'Unit is assignable to Unit' do
620
- t = Puppet::Pops::Types::PUnitType.new()
621
- t2 = Puppet::Pops::Types::PUnitType.new()
628
+ t = Puppet::Pops::Types::PUnitType::DEFAULT
629
+ t2 = Puppet::Pops::Types::PUnitType::DEFAULT
622
630
  expect(t).to be_assignable_to(t2)
623
631
  end
624
632
  end
625
633
 
626
- context "for Any, such that" do
634
+ context 'for Any, such that' do
627
635
  it 'all types are assignable to Any' do
628
- t = Puppet::Pops::Types::PAnyType.new()
629
- all_types.each { |t2| expect(t2.new).to be_assignable_to(t) }
636
+ t = Puppet::Pops::Types::PAnyType::DEFAULT
637
+ all_types.each { |t2| expect(t2::DEFAULT).to be_assignable_to(t) }
630
638
  end
631
639
 
632
640
  it 'Any is not assignable to anything but Any and Optional (implied Optional[Any])' do
633
641
  tested_types = all_types() - [Puppet::Pops::Types::PAnyType, Puppet::Pops::Types::POptionalType]
634
- t = Puppet::Pops::Types::PAnyType.new()
635
- tested_types.each { |t2| expect(t).not_to be_assignable_to(t2.new) }
642
+ t = Puppet::Pops::Types::PAnyType::DEFAULT
643
+ tested_types.each { |t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
636
644
  end
637
645
  end
638
646
 
@@ -640,9 +648,9 @@ describe 'The type calculator' do
640
648
  it 'all types except types assignable from Undef are assignable to NotUndef' do
641
649
  t = not_undef_t
642
650
  tc = Puppet::Pops::Types::TypeCalculator.singleton
643
- undef_t = Puppet::Pops::Types::PUndefType.new()
644
- all_types().each do |c|
645
- t2 = c.new
651
+ undef_t = Puppet::Pops::Types::PUndefType::DEFAULT
652
+ all_types.each do |c|
653
+ t2 = c::DEFAULT
646
654
  if tc.assignable?(t2, undef_t)
647
655
  expect(t2).not_to be_assignable_to(t)
648
656
  else
@@ -653,9 +661,9 @@ describe 'The type calculator' do
653
661
 
654
662
  it 'type NotUndef[T] is assignable from T unless T is assignable from Undef ' do
655
663
  tc = Puppet::Pops::Types::TypeCalculator.singleton
656
- undef_t = Puppet::Pops::Types::PUndefType.new()
664
+ undef_t = Puppet::Pops::Types::PUndefType::DEFAULT
657
665
  all_types().select do |c|
658
- t2 = c.new
666
+ t2 = c::DEFAULT
659
667
  not_undef_t = not_undef_t(t2)
660
668
  if tc.assignable?(t2, undef_t)
661
669
  expect(t2).not_to be_assignable_to(not_undef_t)
@@ -667,9 +675,9 @@ describe 'The type calculator' do
667
675
 
668
676
  it 'type T is assignable from NotUndef[T] unless T is assignable from Undef' do
669
677
  tc = Puppet::Pops::Types::TypeCalculator.singleton
670
- undef_t = Puppet::Pops::Types::PUndefType.new()
678
+ undef_t = Puppet::Pops::Types::PUndefType::DEFAULT
671
679
  all_types().select do |c|
672
- t2 = c.new
680
+ t2 = c::DEFAULT
673
681
  not_undef_t = not_undef_t(t2)
674
682
  unless tc.assignable?(t2, undef_t)
675
683
  expect(not_undef_t).to be_assignable_to(t2)
@@ -678,35 +686,35 @@ describe 'The type calculator' do
678
686
  end
679
687
  end
680
688
 
681
- context "for Data, such that" do
689
+ context 'for Data, such that' do
682
690
  it 'all scalars + array and hash are assignable to Data' do
683
- t = Puppet::Pops::Types::PDataType.new()
691
+ t = Puppet::Pops::Types::PDataType::DEFAULT
684
692
  data_compatible_types.each { |t2|
685
693
  expect(type_from_class(t2)).to be_assignable_to(t)
686
694
  }
687
695
  end
688
696
 
689
697
  it 'a Variant of scalar, hash, or array is assignable to Data' do
690
- t = Puppet::Pops::Types::PDataType.new()
698
+ t = Puppet::Pops::Types::PDataType::DEFAULT
691
699
  data_compatible_types.each { |t2| expect(variant_t(type_from_class(t2))).to be_assignable_to(t) }
692
700
  end
693
701
 
694
702
  it 'Data is not assignable to any of its subtypes' do
695
- t = Puppet::Pops::Types::PDataType.new()
703
+ t = Puppet::Pops::Types::PDataType::DEFAULT
696
704
  types_to_test = data_compatible_types- [Puppet::Pops::Types::PDataType]
697
705
  types_to_test.each {|t2| expect(t).not_to be_assignable_to(type_from_class(t2)) }
698
706
  end
699
707
 
700
708
  it 'Data is not assignable to a Variant of Data subtype' do
701
- t = Puppet::Pops::Types::PDataType.new()
709
+ t = Puppet::Pops::Types::PDataType::DEFAULT
702
710
  types_to_test = data_compatible_types- [Puppet::Pops::Types::PDataType]
703
711
  types_to_test.each { |t2| expect(t).not_to be_assignable_to(variant_t(type_from_class(t2))) }
704
712
  end
705
713
 
706
714
  it 'Data is not assignable to any disjunct type' do
707
715
  tested_types = all_types - [Puppet::Pops::Types::PAnyType, Puppet::Pops::Types::POptionalType, Puppet::Pops::Types::PDataType] - scalar_types
708
- t = Puppet::Pops::Types::PDataType.new()
709
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
716
+ t = Puppet::Pops::Types::PDataType::DEFAULT
717
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
710
718
  end
711
719
  end
712
720
 
@@ -728,35 +736,35 @@ describe 'The type calculator' do
728
736
  end
729
737
  end
730
738
 
731
- context "for Scalar, such that" do
732
- it "all scalars are assignable to Scalar" do
733
- t = Puppet::Pops::Types::PScalarType.new()
734
- scalar_types.each {|t2| expect(t2.new).to be_assignable_to(t) }
739
+ context 'for Scalar, such that' do
740
+ it 'all scalars are assignable to Scalar' do
741
+ t = Puppet::Pops::Types::PScalarType::DEFAULT
742
+ scalar_types.each {|t2| expect(t2::DEFAULT).to be_assignable_to(t) }
735
743
  end
736
744
 
737
745
  it 'Scalar is not assignable to any of its subtypes' do
738
- t = Puppet::Pops::Types::PScalarType.new()
746
+ t = Puppet::Pops::Types::PScalarType::DEFAULT
739
747
  types_to_test = scalar_types - [Puppet::Pops::Types::PScalarType]
740
- types_to_test.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
748
+ types_to_test.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
741
749
  end
742
750
 
743
751
  it 'Scalar is not assignable to any disjunct type' do
744
752
  tested_types = all_types - [Puppet::Pops::Types::PAnyType, Puppet::Pops::Types::POptionalType, Puppet::Pops::Types::PNotUndefType, Puppet::Pops::Types::PDataType] - scalar_types
745
- t = Puppet::Pops::Types::PScalarType.new()
746
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
753
+ t = Puppet::Pops::Types::PScalarType::DEFAULT
754
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
747
755
  end
748
756
  end
749
757
 
750
- context "for Numeric, such that" do
751
- it "all numerics are assignable to Numeric" do
752
- t = Puppet::Pops::Types::PNumericType.new()
753
- numeric_types.each {|t2| expect(t2.new).to be_assignable_to(t) }
758
+ context 'for Numeric, such that' do
759
+ it 'all numerics are assignable to Numeric' do
760
+ t = Puppet::Pops::Types::PNumericType::DEFAULT
761
+ numeric_types.each {|t2| expect(t2::DEFAULT).to be_assignable_to(t) }
754
762
  end
755
763
 
756
764
  it 'Numeric is not assignable to any of its subtypes' do
757
- t = Puppet::Pops::Types::PNumericType.new()
765
+ t = Puppet::Pops::Types::PNumericType::DEFAULT
758
766
  types_to_test = numeric_types - [Puppet::Pops::Types::PNumericType]
759
- types_to_test.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
767
+ types_to_test.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
760
768
  end
761
769
 
762
770
  it 'Numeric is not assignable to any disjunct type' do
@@ -767,39 +775,39 @@ describe 'The type calculator' do
767
775
  Puppet::Pops::Types::PDataType,
768
776
  Puppet::Pops::Types::PScalarType,
769
777
  ] - numeric_types
770
- t = Puppet::Pops::Types::PNumericType.new()
771
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
778
+ t = Puppet::Pops::Types::PNumericType::DEFAULT
779
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
772
780
  end
773
781
  end
774
782
 
775
- context "for Collection, such that" do
776
- it "all collections are assignable to Collection" do
777
- t = Puppet::Pops::Types::PCollectionType.new()
778
- collection_types.each {|t2| expect(t2.new).to be_assignable_to(t) }
783
+ context 'for Collection, such that' do
784
+ it 'all collections are assignable to Collection' do
785
+ t = Puppet::Pops::Types::PCollectionType::DEFAULT
786
+ collection_types.each {|t2| expect(t2::DEFAULT).to be_assignable_to(t) }
779
787
  end
780
788
 
781
789
  it 'Collection is not assignable to any of its subtypes' do
782
- t = Puppet::Pops::Types::PCollectionType.new()
790
+ t = Puppet::Pops::Types::PCollectionType::DEFAULT
783
791
  types_to_test = collection_types - [Puppet::Pops::Types::PCollectionType]
784
- types_to_test.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
792
+ types_to_test.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
785
793
  end
786
794
 
787
795
  it 'Collection is not assignable to any disjunct type' do
788
796
  tested_types = all_types - [Puppet::Pops::Types::PAnyType, Puppet::Pops::Types::POptionalType, Puppet::Pops::Types::PNotUndefType] - collection_types
789
- t = Puppet::Pops::Types::PCollectionType.new()
790
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
797
+ t = Puppet::Pops::Types::PCollectionType::DEFAULT
798
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
791
799
  end
792
800
  end
793
801
 
794
- context "for Array, such that" do
795
- it "Array is not assignable to non Array based Collection type" do
796
- t = Puppet::Pops::Types::PArrayType.new()
802
+ context 'for Array, such that' do
803
+ it 'Array is not assignable to non Array based Collection type' do
804
+ t = Puppet::Pops::Types::PArrayType::DEFAULT
797
805
  tested_types = collection_types - [
798
806
  Puppet::Pops::Types::PCollectionType,
799
807
  Puppet::Pops::Types::PNotUndefType,
800
808
  Puppet::Pops::Types::PArrayType,
801
809
  Puppet::Pops::Types::PTupleType]
802
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
810
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
803
811
  end
804
812
 
805
813
  it 'Array is not assignable to any disjunct type' do
@@ -808,19 +816,24 @@ describe 'The type calculator' do
808
816
  Puppet::Pops::Types::POptionalType,
809
817
  Puppet::Pops::Types::PNotUndefType,
810
818
  Puppet::Pops::Types::PDataType] - collection_types
811
- t = Puppet::Pops::Types::PArrayType.new()
812
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
819
+ t = Puppet::Pops::Types::PArrayType::DEFAULT
820
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
821
+ end
822
+
823
+ it 'Empty Array is assignable to an array that accepts 0 entries' do
824
+ expect(empty_array_t).to be_assignable_to(array_t(string_t))
825
+ expect(empty_array_t).to be_assignable_to(array_t(integer_t))
813
826
  end
814
827
  end
815
828
 
816
- context "for Hash, such that" do
817
- it "Hash is not assignable to any other Collection type" do
818
- t = Puppet::Pops::Types::PHashType.new()
829
+ context 'for Hash, such that' do
830
+ it 'Hash is not assignable to any other Collection type' do
831
+ t = Puppet::Pops::Types::PHashType::DEFAULT
819
832
  tested_types = collection_types - [
820
833
  Puppet::Pops::Types::PCollectionType,
821
834
  Puppet::Pops::Types::PStructType,
822
835
  Puppet::Pops::Types::PHashType]
823
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
836
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
824
837
  end
825
838
 
826
839
  it 'Hash is not assignable to any disjunct type' do
@@ -829,8 +842,8 @@ describe 'The type calculator' do
829
842
  Puppet::Pops::Types::POptionalType,
830
843
  Puppet::Pops::Types::PNotUndefType,
831
844
  Puppet::Pops::Types::PDataType] - collection_types
832
- t = Puppet::Pops::Types::PHashType.new()
833
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
845
+ t = Puppet::Pops::Types::PHashType::DEFAULT
846
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
834
847
  end
835
848
 
836
849
  it 'Struct is assignable to Hash with Pattern that matches all keys' do
@@ -850,14 +863,14 @@ describe 'The type calculator' do
850
863
  end
851
864
  end
852
865
 
853
- context "for Tuple, such that" do
854
- it "Tuple is not assignable to any other non Array based Collection type" do
855
- t = Puppet::Pops::Types::PTupleType.new()
866
+ context 'for Tuple, such that' do
867
+ it 'Tuple is not assignable to any other non Array based Collection type' do
868
+ t = Puppet::Pops::Types::PTupleType::DEFAULT
856
869
  tested_types = collection_types - [
857
870
  Puppet::Pops::Types::PCollectionType,
858
871
  Puppet::Pops::Types::PTupleType,
859
872
  Puppet::Pops::Types::PArrayType]
860
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
873
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
861
874
  end
862
875
 
863
876
  it 'Tuple is not assignable to any disjunct type' do
@@ -866,19 +879,19 @@ describe 'The type calculator' do
866
879
  Puppet::Pops::Types::POptionalType,
867
880
  Puppet::Pops::Types::PNotUndefType,
868
881
  Puppet::Pops::Types::PDataType] - collection_types
869
- t = Puppet::Pops::Types::PTupleType.new()
870
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
882
+ t = Puppet::Pops::Types::PTupleType::DEFAULT
883
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
871
884
  end
872
885
  end
873
886
 
874
- context "for Struct, such that" do
875
- it "Struct is not assignable to any other non Hashed based Collection type" do
876
- t = Puppet::Pops::Types::PStructType.new()
887
+ context 'for Struct, such that' do
888
+ it 'Struct is not assignable to any other non Hashed based Collection type' do
889
+ t = Puppet::Pops::Types::PStructType::DEFAULT
877
890
  tested_types = collection_types - [
878
891
  Puppet::Pops::Types::PCollectionType,
879
892
  Puppet::Pops::Types::PStructType,
880
893
  Puppet::Pops::Types::PHashType]
881
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
894
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
882
895
  end
883
896
 
884
897
  it 'Struct is not assignable to any disjunct type' do
@@ -887,8 +900,8 @@ describe 'The type calculator' do
887
900
  Puppet::Pops::Types::POptionalType,
888
901
  Puppet::Pops::Types::PNotUndefType,
889
902
  Puppet::Pops::Types::PDataType] - collection_types
890
- t = Puppet::Pops::Types::PStructType.new()
891
- tested_types.each {|t2| expect(t).not_to be_assignable_to(t2.new) }
903
+ t = Puppet::Pops::Types::PStructType::DEFAULT
904
+ tested_types.each {|t2| expect(t).not_to be_assignable_to(t2::DEFAULT) }
892
905
  end
893
906
 
894
907
  it 'Default key optionality is controlled by value assignability to undef' do
@@ -921,32 +934,32 @@ describe 'The type calculator' do
921
934
  end
922
935
  end
923
936
 
924
- context "for Callable, such that" do
925
- it "Callable is not assignable to any disjunct type" do
926
- t = Puppet::Pops::Types::PCallableType.new()
937
+ context 'for Callable, such that' do
938
+ it 'Callable is not assignable to any disjunct type' do
939
+ t = Puppet::Pops::Types::PCallableType::DEFAULT
927
940
  tested_types = all_types - [
928
941
  Puppet::Pops::Types::PCallableType,
929
942
  Puppet::Pops::Types::PAnyType,
930
943
  Puppet::Pops::Types::POptionalType,
931
944
  Puppet::Pops::Types::PNotUndefType]
932
- tested_types.each {|t2| expect(t).to_not be_assignable_to(t2.new) }
945
+ tested_types.each {|t2| expect(t).to_not be_assignable_to(t2::DEFAULT) }
933
946
  end
934
947
  end
935
948
 
936
949
  it 'should recognize mapped ruby types' do
937
- { Integer => Puppet::Pops::Types::PIntegerType.new,
938
- Fixnum => Puppet::Pops::Types::PIntegerType.new,
939
- Bignum => Puppet::Pops::Types::PIntegerType.new,
940
- Float => Puppet::Pops::Types::PFloatType.new,
941
- Numeric => Puppet::Pops::Types::PNumericType.new,
942
- NilClass => Puppet::Pops::Types::PUndefType.new,
943
- TrueClass => Puppet::Pops::Types::PBooleanType.new,
944
- FalseClass => Puppet::Pops::Types::PBooleanType.new,
945
- String => Puppet::Pops::Types::PStringType.new,
946
- Regexp => Puppet::Pops::Types::PRegexpType.new,
947
- Regexp => Puppet::Pops::Types::PRegexpType.new,
948
- Array => Puppet::Pops::Types::TypeFactory.array_of_data(),
949
- Hash => Puppet::Pops::Types::TypeFactory.hash_of_data()
950
+ { Integer => Puppet::Pops::Types::PIntegerType::DEFAULT,
951
+ Fixnum => Puppet::Pops::Types::PIntegerType::DEFAULT,
952
+ Bignum => Puppet::Pops::Types::PIntegerType::DEFAULT,
953
+ Float => Puppet::Pops::Types::PFloatType::DEFAULT,
954
+ Numeric => Puppet::Pops::Types::PNumericType::DEFAULT,
955
+ NilClass => Puppet::Pops::Types::PUndefType::DEFAULT,
956
+ TrueClass => Puppet::Pops::Types::PBooleanType::DEFAULT,
957
+ FalseClass => Puppet::Pops::Types::PBooleanType::DEFAULT,
958
+ String => Puppet::Pops::Types::PStringType::DEFAULT,
959
+ Regexp => Puppet::Pops::Types::PRegexpType::DEFAULT,
960
+ Regexp => Puppet::Pops::Types::PRegexpType::DEFAULT,
961
+ Array => Puppet::Pops::Types::TypeFactory.array_of_data,
962
+ Hash => Puppet::Pops::Types::TypeFactory.hash_of_data
950
963
  }.each do |ruby_type, puppet_type |
951
964
  expect(ruby_type).to be_assignable_to(puppet_type)
952
965
  end
@@ -1049,18 +1062,18 @@ describe 'The type calculator' do
1049
1062
  end
1050
1063
 
1051
1064
  it 'pattern representing all patterns should accept any pattern' do
1052
- expect(calculator.assignable?(pattern_t(), pattern_t('a'))).to eq(true)
1053
- expect(calculator.assignable?(pattern_t(), pattern_t())).to eq(true)
1065
+ expect(calculator.assignable?(pattern_t, pattern_t('a'))).to eq(true)
1066
+ expect(calculator.assignable?(pattern_t, pattern_t)).to eq(true)
1054
1067
  end
1055
1068
 
1056
1069
  it 'pattern representing all patterns should accept any enum' do
1057
- expect(calculator.assignable?(pattern_t(), enum_t('a'))).to eq(true)
1058
- expect(calculator.assignable?(pattern_t(), enum_t())).to eq(true)
1070
+ expect(calculator.assignable?(pattern_t, enum_t('a'))).to eq(true)
1071
+ expect(calculator.assignable?(pattern_t, enum_t)).to eq(true)
1059
1072
  end
1060
1073
 
1061
1074
  it 'pattern representing all patterns should accept any string' do
1062
- expect(calculator.assignable?(pattern_t(), string_t('a'))).to eq(true)
1063
- expect(calculator.assignable?(pattern_t(), string_t())).to eq(true)
1075
+ expect(calculator.assignable?(pattern_t, string_t('a'))).to eq(true)
1076
+ expect(calculator.assignable?(pattern_t, string_t)).to eq(true)
1064
1077
  end
1065
1078
 
1066
1079
  end
@@ -1079,8 +1092,8 @@ describe 'The type calculator' do
1079
1092
  end
1080
1093
 
1081
1094
  it 'non parameterized enum accepts any other enum but not the reverse' do
1082
- expect(calculator.assignable?(enum_t(), enum_t('a'))).to eq(true)
1083
- expect(calculator.assignable?(enum_t('a'), enum_t())).to eq(false)
1095
+ expect(calculator.assignable?(enum_t, enum_t('a'))).to eq(true)
1096
+ expect(calculator.assignable?(enum_t('a'), enum_t)).to eq(false)
1084
1097
  end
1085
1098
 
1086
1099
  it 'enum should accept a variant where all variants are acceptable' do
@@ -1091,51 +1104,50 @@ describe 'The type calculator' do
1091
1104
 
1092
1105
  context 'when dealing with string and enum combinations' do
1093
1106
  it 'should accept assigning any enum to unrestricted string' do
1094
- expect(calculator.assignable?(string_t(), enum_t('blue'))).to eq(true)
1095
- expect(calculator.assignable?(string_t(), enum_t('blue', 'red'))).to eq(true)
1107
+ expect(calculator.assignable?(string_t, enum_t('blue'))).to eq(true)
1108
+ expect(calculator.assignable?(string_t, enum_t('blue', 'red'))).to eq(true)
1096
1109
  end
1097
1110
 
1098
1111
  it 'should not accept assigning longer enum value to size restricted string' do
1099
- expect(calculator.assignable?(constrained_t(string_t(),2,2), enum_t('a','blue'))).to eq(false)
1112
+ expect(calculator.assignable?(constrained_string_t(range_t(2,2)), enum_t('a','blue'))).to eq(false)
1100
1113
  end
1101
1114
 
1102
1115
  it 'should accept assigning any string to empty enum' do
1103
- expect(calculator.assignable?(enum_t(), string_t())).to eq(true)
1116
+ expect(calculator.assignable?(enum_t, string_t)).to eq(true)
1104
1117
  end
1105
1118
 
1106
1119
  it 'should accept assigning empty enum to any string' do
1107
- expect(calculator.assignable?(string_t(), enum_t())).to eq(true)
1120
+ expect(calculator.assignable?(string_t, enum_t)).to eq(true)
1108
1121
  end
1109
1122
 
1110
1123
  it 'should not accept assigning empty enum to size constrained string' do
1111
- expect(calculator.assignable?(constrained_t(string_t(),2,2), enum_t())).to eq(false)
1124
+ expect(calculator.assignable?(constrained_string_t(range_t(2,2)), enum_t)).to eq(false)
1112
1125
  end
1113
1126
  end
1114
1127
 
1115
1128
  context 'when dealing with string/pattern/enum combinations' do
1116
1129
  it 'any string is equal to any enum is equal to any pattern' do
1117
- expect(calculator.assignable?(string_t(), enum_t())).to eq(true)
1118
- expect(calculator.assignable?(string_t(), pattern_t())).to eq(true)
1119
- expect(calculator.assignable?(enum_t(), string_t())).to eq(true)
1120
- expect(calculator.assignable?(enum_t(), pattern_t())).to eq(true)
1121
- expect(calculator.assignable?(pattern_t(), string_t())).to eq(true)
1122
- expect(calculator.assignable?(pattern_t(), enum_t())).to eq(true)
1130
+ expect(calculator.assignable?(string_t, enum_t)).to eq(true)
1131
+ expect(calculator.assignable?(string_t, pattern_t)).to eq(true)
1132
+ expect(calculator.assignable?(enum_t, string_t)).to eq(true)
1133
+ expect(calculator.assignable?(enum_t, pattern_t)).to eq(true)
1134
+ expect(calculator.assignable?(pattern_t, string_t)).to eq(true)
1135
+ expect(calculator.assignable?(pattern_t, enum_t)).to eq(true)
1123
1136
  end
1124
1137
  end
1125
1138
 
1126
1139
  context 'when dealing with tuples' do
1127
1140
  it 'matches empty tuples' do
1128
- tuple1 = tuple_t()
1129
- tuple2 = tuple_t()
1141
+ tuple1 = tuple_t
1142
+ tuple2 = tuple_t
1130
1143
 
1131
1144
  expect(calculator.assignable?(tuple1, tuple2)).to eq(true)
1132
1145
  expect(calculator.assignable?(tuple2, tuple1)).to eq(true)
1133
1146
  end
1134
1147
 
1135
1148
  it 'accepts an empty tuple as assignable to a tuple with a min size of 0' do
1136
- tuple1 = tuple_t(Object)
1137
- factory.constrain_size(tuple1, 0, :default)
1138
- tuple2 = tuple_t()
1149
+ tuple1 = constrained_tuple_t(range_t(0, :default), Object)
1150
+ tuple2 = tuple_t
1139
1151
 
1140
1152
  expect(calculator.assignable?(tuple1, tuple2)).to eq(true)
1141
1153
  expect(calculator.assignable?(tuple2, tuple1)).to eq(false)
@@ -1156,62 +1168,51 @@ describe 'The type calculator' do
1156
1168
  end
1157
1169
 
1158
1170
  it 'should accept ranged tuples' do
1159
- tuple1 = tuple_t(1)
1160
- factory.constrain_size(tuple1, 5, 5)
1171
+ tuple1 = constrained_tuple_t(range_t(5,5), 1)
1161
1172
  tuple2 = tuple_t(Integer,Integer, Integer, Integer, Integer)
1162
1173
  expect(calculator.assignable?(tuple1, tuple2)).to eq(true)
1163
1174
  expect(calculator.assignable?(tuple2, tuple1)).to eq(true)
1164
1175
  end
1165
1176
 
1166
1177
  it 'should reject ranged tuples when ranges does not match' do
1167
- tuple1 = tuple_t(1)
1168
- factory.constrain_size(tuple1, 4, 5)
1178
+ tuple1 = constrained_tuple_t(range_t(4, 5), 1)
1169
1179
  tuple2 = tuple_t(Integer,Integer, Integer, Integer, Integer)
1170
1180
  expect(calculator.assignable?(tuple1, tuple2)).to eq(true)
1171
1181
  expect(calculator.assignable?(tuple2, tuple1)).to eq(false)
1172
1182
  end
1173
1183
 
1174
1184
  it 'should reject ranged tuples when ranges does not match (using infinite upper bound)' do
1175
- tuple1 = tuple_t(1)
1176
- factory.constrain_size(tuple1, 4, :default)
1185
+ tuple1 = constrained_tuple_t(range_t(4, :default), 1)
1177
1186
  tuple2 = tuple_t(Integer,Integer, Integer, Integer, Integer)
1178
1187
  expect(calculator.assignable?(tuple1, tuple2)).to eq(true)
1179
1188
  expect(calculator.assignable?(tuple2, tuple1)).to eq(false)
1180
1189
  end
1181
1190
 
1182
1191
  it 'should accept matching tuples with optional entries by repeating last' do
1183
- tuple1 = tuple_t(1,2)
1184
- factory.constrain_size(tuple1, 0, :default)
1185
- tuple2 = tuple_t(Numeric,Numeric)
1186
- factory.constrain_size(tuple2, 0, :default)
1192
+ tuple1 = constrained_tuple_t(range_t(0, :default), 1,2)
1193
+ tuple2 = constrained_tuple_t(range_t(0, :default), Numeric,Numeric)
1187
1194
  expect(calculator.assignable?(tuple1, tuple2)).to eq(false)
1188
1195
  expect(calculator.assignable?(tuple2, tuple1)).to eq(true)
1189
1196
  end
1190
1197
 
1191
1198
  it 'should accept matching tuples with optional entries' do
1192
- tuple1 = tuple_t(Integer, Integer, String)
1193
- factory.constrain_size(tuple1, 1, 3)
1194
- array2 = factory.constrain_size(array_t(Integer),2,2)
1199
+ tuple1 = constrained_tuple_t(range_t(1, 3), Integer, Integer, String)
1200
+ array2 = array_t(Integer, range_t(2,2))
1195
1201
  expect(calculator.assignable?(tuple1, array2)).to eq(true)
1196
- factory.constrain_size(tuple1, 3, 3)
1202
+ tuple1 = constrained_tuple_t(range_t(3, 3), tuple1.types)
1197
1203
  expect(calculator.assignable?(tuple1, array2)).to eq(false)
1198
1204
  end
1199
1205
 
1200
1206
  it 'should accept matching array' do
1201
1207
  tuple1 = tuple_t(1,2)
1202
- array = array_t(Integer)
1203
- factory.constrain_size(array, 2, 2)
1208
+ array = array_t(Integer, range_t(2, 2))
1204
1209
  expect(calculator.assignable?(tuple1, array)).to eq(true)
1205
1210
  expect(calculator.assignable?(array, tuple1)).to eq(true)
1206
1211
  end
1207
1212
 
1208
1213
  it 'should accept empty array when tuple allows min of 0' do
1209
- tuple1 = tuple_t(Integer)
1210
- factory.constrain_size(tuple1, 0, 1)
1211
-
1212
- array = array_t(Integer)
1213
- factory.constrain_size(array, 0, 0)
1214
-
1214
+ tuple1 = constrained_tuple_t(range_t(0, 1), Integer)
1215
+ array = array_t(Integer, range_t(0, 0))
1215
1216
  expect(calculator.assignable?(tuple1, array)).to eq(true)
1216
1217
  expect(calculator.assignable?(array, tuple1)).to eq(false)
1217
1218
  end
@@ -1258,18 +1259,15 @@ describe 'The type calculator' do
1258
1259
 
1259
1260
  it 'should accept matching hash' do
1260
1261
  struct1 = struct_t({'a'=>Integer, 'b'=>Integer})
1261
- non_empty_string = string_t()
1262
- non_empty_string.size_type = range_t(1, nil)
1263
- hsh = hash_t(non_empty_string, Integer)
1264
- factory.constrain_size(hsh, 2, 2)
1262
+ non_empty_string = constrained_string_t(range_t(1, nil))
1263
+ hsh = hash_t(non_empty_string, Integer, range_t(2,2))
1265
1264
  expect(calculator.assignable?(struct1, hsh)).to eq(true)
1266
1265
  expect(calculator.assignable?(hsh, struct1)).to eq(true)
1267
1266
  end
1268
1267
 
1269
1268
  it 'should accept empty hash with key_type undef' do
1270
1269
  struct1 = struct_t({'a'=>optional_t(Integer)})
1271
- hsh = hash_t(undef_t, undef_t)
1272
- factory.constrain_size(hsh, 0, 0)
1270
+ hsh = hash_t(undef_t, undef_t, range_t(0, 0))
1273
1271
  expect(calculator.assignable?(struct1, hsh)).to eq(true)
1274
1272
  end
1275
1273
  end
@@ -1294,38 +1292,38 @@ describe 'The type calculator' do
1294
1292
  expect(calculator.assignable?(Bar, fooType)).to eq(false)
1295
1293
  end
1296
1294
 
1297
- it "should allow host class with same name" do
1295
+ it 'should allow host class with same name' do
1298
1296
  hc1 = Puppet::Pops::Types::TypeFactory.host_class('the_name')
1299
1297
  hc2 = Puppet::Pops::Types::TypeFactory.host_class('the_name')
1300
1298
  expect(calculator.assignable?(hc1, hc2)).to eq(true)
1301
1299
  end
1302
1300
 
1303
- it "should allow host class with name assigned to hostclass without name" do
1304
- hc1 = Puppet::Pops::Types::TypeFactory.host_class()
1301
+ it 'should allow host class with name assigned to hostclass without name' do
1302
+ hc1 = Puppet::Pops::Types::TypeFactory.host_class
1305
1303
  hc2 = Puppet::Pops::Types::TypeFactory.host_class('the_name')
1306
1304
  expect(calculator.assignable?(hc1, hc2)).to eq(true)
1307
1305
  end
1308
1306
 
1309
- it "should reject host classes with different names" do
1307
+ it 'should reject host classes with different names' do
1310
1308
  hc1 = Puppet::Pops::Types::TypeFactory.host_class('the_name')
1311
1309
  hc2 = Puppet::Pops::Types::TypeFactory.host_class('another_name')
1312
1310
  expect(calculator.assignable?(hc1, hc2)).to eq(false)
1313
1311
  end
1314
1312
 
1315
- it "should reject host classes without name assigned to host class with name" do
1313
+ it 'should reject host classes without name assigned to host class with name' do
1316
1314
  hc1 = Puppet::Pops::Types::TypeFactory.host_class('the_name')
1317
- hc2 = Puppet::Pops::Types::TypeFactory.host_class()
1315
+ hc2 = Puppet::Pops::Types::TypeFactory.host_class
1318
1316
  expect(calculator.assignable?(hc1, hc2)).to eq(false)
1319
1317
  end
1320
1318
 
1321
- it "should allow resource with same type_name and title" do
1319
+ it 'should allow resource with same type_name and title' do
1322
1320
  r1 = Puppet::Pops::Types::TypeFactory.resource('file', 'foo')
1323
1321
  r2 = Puppet::Pops::Types::TypeFactory.resource('file', 'foo')
1324
1322
  expect(calculator.assignable?(r1, r2)).to eq(true)
1325
1323
  end
1326
1324
 
1327
- it "should allow more specific resource assignment" do
1328
- r1 = Puppet::Pops::Types::TypeFactory.resource()
1325
+ it 'should allow more specific resource assignment' do
1326
+ r1 = Puppet::Pops::Types::TypeFactory.resource
1329
1327
  r2 = Puppet::Pops::Types::TypeFactory.resource('file')
1330
1328
  expect(calculator.assignable?(r1, r2)).to eq(true)
1331
1329
  r2 = Puppet::Pops::Types::TypeFactory.resource('file', '/tmp/foo')
@@ -1334,37 +1332,37 @@ describe 'The type calculator' do
1334
1332
  expect(calculator.assignable?(r1, r2)).to eq(true)
1335
1333
  end
1336
1334
 
1337
- it "should reject less specific resource assignment" do
1335
+ it 'should reject less specific resource assignment' do
1338
1336
  r1 = Puppet::Pops::Types::TypeFactory.resource('file', '/tmp/foo')
1339
1337
  r2 = Puppet::Pops::Types::TypeFactory.resource('file')
1340
1338
  expect(calculator.assignable?(r1, r2)).to eq(false)
1341
- r2 = Puppet::Pops::Types::TypeFactory.resource()
1339
+ r2 = Puppet::Pops::Types::TypeFactory.resource
1342
1340
  expect(calculator.assignable?(r1, r2)).to eq(false)
1343
1341
  end
1344
1342
 
1345
1343
  end
1346
1344
 
1347
1345
  context 'when testing if x is instance of type t' do
1348
- include_context "types_setup"
1346
+ include_context 'types_setup'
1349
1347
 
1350
1348
  it 'should consider undef to be instance of Any, NilType, and optional' do
1351
- expect(calculator.instance?(Puppet::Pops::Types::PUndefType.new(), nil)).to eq(true)
1352
- expect(calculator.instance?(Puppet::Pops::Types::PAnyType.new(), nil)).to eq(true)
1353
- expect(calculator.instance?(Puppet::Pops::Types::POptionalType.new(), nil)).to eq(true)
1349
+ expect(calculator.instance?(Puppet::Pops::Types::PUndefType::DEFAULT, nil)).to eq(true)
1350
+ expect(calculator.instance?(Puppet::Pops::Types::PAnyType::DEFAULT, nil)).to eq(true)
1351
+ expect(calculator.instance?(Puppet::Pops::Types::POptionalType::DEFAULT, nil)).to eq(true)
1354
1352
  end
1355
1353
 
1356
1354
  it 'all types should be (ruby) instance of PAnyType' do
1357
1355
  all_types.each do |t|
1358
- expect(t.new.is_a?(Puppet::Pops::Types::PAnyType)).to eq(true)
1356
+ expect(t::DEFAULT.is_a?(Puppet::Pops::Types::PAnyType)).to eq(true)
1359
1357
  end
1360
1358
  end
1361
1359
 
1362
1360
  it "should consider :undef to be instance of Runtime['ruby', 'Symbol]" do
1363
- expect(calculator.instance?(Puppet::Pops::Types::PRuntimeType.new(:runtime => :ruby, :runtime_type_name => 'Symbol'), :undef)).to eq(true)
1361
+ expect(calculator.instance?(Puppet::Pops::Types::PRuntimeType.new(:ruby, 'Symbol'), :undef)).to eq(true)
1364
1362
  end
1365
1363
 
1366
- it "should consider :undef to be instance of an Optional type" do
1367
- expect(calculator.instance?(Puppet::Pops::Types::POptionalType.new(), :undef)).to eq(true)
1364
+ it 'should consider :undef to be instance of an Optional type' do
1365
+ expect(calculator.instance?(Puppet::Pops::Types::POptionalType::DEFAULT, :undef)).to eq(true)
1368
1366
  end
1369
1367
 
1370
1368
  it 'should not consider undef to be an instance of any other type than Any, UndefType and Data' do
@@ -1375,13 +1373,13 @@ describe 'The type calculator' do
1375
1373
  Puppet::Pops::Types::POptionalType,
1376
1374
  ]
1377
1375
 
1378
- types_to_test.each {|t| expect(calculator.instance?(t.new, nil)).to eq(false) }
1379
- types_to_test.each {|t| expect(calculator.instance?(t.new, :undef)).to eq(false) }
1376
+ types_to_test.each {|t| expect(calculator.instance?(t::DEFAULT, nil)).to eq(false) }
1377
+ types_to_test.each {|t| expect(calculator.instance?(t::DEFAULT, :undef)).to eq(false) }
1380
1378
  end
1381
1379
 
1382
1380
  it 'should consider default to be instance of Default and Any' do
1383
- expect(calculator.instance?(Puppet::Pops::Types::PDefaultType.new(), :default)).to eq(true)
1384
- expect(calculator.instance?(Puppet::Pops::Types::PAnyType.new(), :default)).to eq(true)
1381
+ expect(calculator.instance?(Puppet::Pops::Types::PDefaultType::DEFAULT, :default)).to eq(true)
1382
+ expect(calculator.instance?(Puppet::Pops::Types::PAnyType::DEFAULT, :default)).to eq(true)
1385
1383
  end
1386
1384
 
1387
1385
  it 'should not consider "default" to be an instance of anything but Default, NotUndef, and Any' do
@@ -1391,11 +1389,11 @@ describe 'The type calculator' do
1391
1389
  Puppet::Pops::Types::PDefaultType,
1392
1390
  ]
1393
1391
 
1394
- types_to_test.each {|t| expect(calculator.instance?(t.new, :default)).to eq(false) }
1392
+ types_to_test.each {|t| expect(calculator.instance?(t::DEFAULT, :default)).to eq(false) }
1395
1393
  end
1396
1394
 
1397
1395
  it 'should consider fixnum instanceof PIntegerType' do
1398
- expect(calculator.instance?(Puppet::Pops::Types::PIntegerType.new(), 1)).to eq(true)
1396
+ expect(calculator.instance?(Puppet::Pops::Types::PIntegerType::DEFAULT, 1)).to eq(true)
1399
1397
  end
1400
1398
 
1401
1399
  it 'should consider fixnum instanceof Fixnum' do
@@ -1411,7 +1409,7 @@ describe 'The type calculator' do
1411
1409
  end
1412
1410
 
1413
1411
  it 'should consider string in length range' do
1414
- range = factory.constrain_size(string_t, 1,3)
1412
+ range = constrained_string_t(range_t(1,3))
1415
1413
  expect(calculator.instance?(range, 'a')).to eq(true)
1416
1414
  expect(calculator.instance?(range, 'abc')).to eq(true)
1417
1415
  expect(calculator.instance?(range, '')).to eq(false)
@@ -1426,7 +1424,7 @@ describe 'The type calculator' do
1426
1424
  end
1427
1425
 
1428
1426
  it 'should consider array in length range' do
1429
- range = factory.constrain_size(array_t(integer_t), 1,3)
1427
+ range = array_t(integer_t, range_t(1,3))
1430
1428
  expect(calculator.instance?(range, [1])).to eq(true)
1431
1429
  expect(calculator.instance?(range, [1,2,3])).to eq(true)
1432
1430
  expect(calculator.instance?(range, [])).to eq(false)
@@ -1434,7 +1432,7 @@ describe 'The type calculator' do
1434
1432
  end
1435
1433
 
1436
1434
  it 'should consider hash in length range' do
1437
- range = factory.constrain_size(hash_t(integer_t, integer_t), 1,2)
1435
+ range = hash_t(integer_t, integer_t, range_t(1,2))
1438
1436
  expect(calculator.instance?(range, {1=>1})).to eq(true)
1439
1437
  expect(calculator.instance?(range, {1=>1, 2=>2})).to eq(true)
1440
1438
  expect(calculator.instance?(range, {})).to eq(false)
@@ -1442,7 +1440,7 @@ describe 'The type calculator' do
1442
1440
  end
1443
1441
 
1444
1442
  it 'should consider collection in length range for array ' do
1445
- range = factory.constrain_size(collection_t, 1,3)
1443
+ range = collection_t(range_t(1,3))
1446
1444
  expect(calculator.instance?(range, [1])).to eq(true)
1447
1445
  expect(calculator.instance?(range, [1,2,3])).to eq(true)
1448
1446
  expect(calculator.instance?(range, [])).to eq(false)
@@ -1450,7 +1448,7 @@ describe 'The type calculator' do
1450
1448
  end
1451
1449
 
1452
1450
  it 'should consider collection in length range for hash' do
1453
- range = factory.constrain_size(collection_t, 1,2)
1451
+ range = collection_t(range_t(1,2))
1454
1452
  expect(calculator.instance?(range, {1=>1})).to eq(true)
1455
1453
  expect(calculator.instance?(range, {1=>1, 2=>2})).to eq(true)
1456
1454
  expect(calculator.instance?(range, {})).to eq(false)
@@ -1581,7 +1579,7 @@ describe 'The type calculator' do
1581
1579
  end
1582
1580
  end
1583
1581
 
1584
- context "and t is something Callable" do
1582
+ context 'and t is something Callable' do
1585
1583
 
1586
1584
  it 'a Closure should be considered a Callable' do
1587
1585
  factory = Puppet::Pops::Model::Factory
@@ -1657,66 +1655,57 @@ describe 'The type calculator' do
1657
1655
 
1658
1656
  context 'when representing the type as string' do
1659
1657
  it 'should yield \'Type\' for PType' do
1660
- expect(calculator.string(Puppet::Pops::Types::PType.new())).to eq('Type')
1658
+ expect(calculator.string(Puppet::Pops::Types::PType::DEFAULT)).to eq('Type')
1661
1659
  end
1662
1660
 
1663
1661
  it 'should yield \'Object\' for PAnyType' do
1664
- expect(calculator.string(Puppet::Pops::Types::PAnyType.new())).to eq('Any')
1662
+ expect(calculator.string(Puppet::Pops::Types::PAnyType::DEFAULT)).to eq('Any')
1665
1663
  end
1666
1664
 
1667
1665
  it 'should yield \'Scalar\' for PScalarType' do
1668
- expect(calculator.string(Puppet::Pops::Types::PScalarType.new())).to eq('Scalar')
1666
+ expect(calculator.string(Puppet::Pops::Types::PScalarType::DEFAULT)).to eq('Scalar')
1669
1667
  end
1670
1668
 
1671
1669
  it 'should yield \'Boolean\' for PBooleanType' do
1672
- expect(calculator.string(Puppet::Pops::Types::PBooleanType.new())).to eq('Boolean')
1670
+ expect(calculator.string(Puppet::Pops::Types::PBooleanType::DEFAULT)).to eq('Boolean')
1673
1671
  end
1674
1672
 
1675
1673
  it 'should yield \'Data\' for PDataType' do
1676
- expect(calculator.string(Puppet::Pops::Types::PDataType.new())).to eq('Data')
1674
+ expect(calculator.string(Puppet::Pops::Types::PDataType::DEFAULT)).to eq('Data')
1677
1675
  end
1678
1676
 
1679
1677
  it 'should yield \'Numeric\' for PNumericType' do
1680
- expect(calculator.string(Puppet::Pops::Types::PNumericType.new())).to eq('Numeric')
1678
+ expect(calculator.string(Puppet::Pops::Types::PNumericType::DEFAULT)).to eq('Numeric')
1681
1679
  end
1682
1680
 
1683
1681
  it 'should yield \'Integer\' and from/to for PIntegerType' do
1684
1682
  int_T = Puppet::Pops::Types::PIntegerType
1685
- expect(calculator.string(int_T.new())).to eq('Integer')
1686
- int = int_T.new()
1687
- int.from = 1
1688
- int.to = 1
1683
+ expect(calculator.string(int_T::DEFAULT)).to eq('Integer')
1684
+ int = int_T.new(1, 1)
1689
1685
  expect(calculator.string(int)).to eq('Integer[1, 1]')
1690
- int = int_T.new()
1691
- int.from = 1
1692
- int.to = 2
1686
+ int = int_T.new(1, 2)
1693
1687
  expect(calculator.string(int)).to eq('Integer[1, 2]')
1694
- int = int_T.new()
1695
- int.from = nil
1696
- int.to = 2
1688
+ int = int_T.new(nil, 2)
1697
1689
  expect(calculator.string(int)).to eq('Integer[default, 2]')
1698
- int = int_T.new()
1699
- int.from = 2
1700
- int.to = nil
1690
+ int = int_T.new(2, nil)
1701
1691
  expect(calculator.string(int)).to eq('Integer[2, default]')
1702
1692
  end
1703
1693
 
1704
1694
  it 'should yield \'Float\' for PFloatType' do
1705
- expect(calculator.string(Puppet::Pops::Types::PFloatType.new())).to eq('Float')
1695
+ expect(calculator.string(Puppet::Pops::Types::PFloatType::DEFAULT)).to eq('Float')
1706
1696
  end
1707
1697
 
1708
1698
  it 'should yield \'Regexp\' for PRegexpType' do
1709
- expect(calculator.string(Puppet::Pops::Types::PRegexpType.new())).to eq('Regexp')
1699
+ expect(calculator.string(Puppet::Pops::Types::PRegexpType::DEFAULT)).to eq('Regexp')
1710
1700
  end
1711
1701
 
1712
1702
  it 'should yield \'Regexp[/pat/]\' for parameterized PRegexpType' do
1713
- t = Puppet::Pops::Types::PRegexpType.new()
1714
- t.pattern = ('a/b')
1715
- expect(calculator.string(Puppet::Pops::Types::PRegexpType.new())).to eq('Regexp')
1703
+ t = Puppet::Pops::Types::PRegexpType.new('a/b')
1704
+ expect(calculator.string(t)).to eq('Regexp[/a\/b/]')
1716
1705
  end
1717
1706
 
1718
1707
  it 'should yield \'String\' for PStringType' do
1719
- expect(calculator.string(Puppet::Pops::Types::PStringType.new())).to eq('String')
1708
+ expect(calculator.string(Puppet::Pops::Types::PStringType::DEFAULT)).to eq('String')
1720
1709
  end
1721
1710
 
1722
1711
  it 'should yield \'String\' for PStringType with multiple values' do
@@ -1725,104 +1714,94 @@ describe 'The type calculator' do
1725
1714
 
1726
1715
  it 'should yield \'String\' and from/to for PStringType' do
1727
1716
  string_T = Puppet::Pops::Types::PStringType
1728
- expect(calculator.string(factory.constrain_size(string_T.new(), 1,1))).to eq('String[1, 1]')
1729
- expect(calculator.string(factory.constrain_size(string_T.new(), 1,2))).to eq('String[1, 2]')
1730
- expect(calculator.string(factory.constrain_size(string_T.new(), :default, 2))).to eq('String[default, 2]')
1731
- expect(calculator.string(factory.constrain_size(string_T.new(), 2, :default))).to eq('String[2, default]')
1717
+ expect(calculator.string(string_T.new(range_t(1,1)))).to eq('String[1, 1]')
1718
+ expect(calculator.string(string_T.new(range_t(1,2)))).to eq('String[1, 2]')
1719
+ expect(calculator.string(string_T.new(range_t(:default, 2)))).to eq('String[default, 2]')
1720
+ expect(calculator.string(string_T.new(range_t(2, :default)))).to eq('String[2, default]')
1732
1721
  end
1733
1722
 
1734
1723
  it 'should yield \'Array[Integer]\' for PArrayType[PIntegerType]' do
1735
- t = Puppet::Pops::Types::PArrayType.new()
1736
- t.element_type = Puppet::Pops::Types::PIntegerType.new()
1724
+ t = Puppet::Pops::Types::PArrayType.new(Puppet::Pops::Types::PIntegerType::DEFAULT)
1737
1725
  expect(calculator.string(t)).to eq('Array[Integer]')
1738
1726
  end
1739
1727
 
1728
+ it 'should yield \'Array[Unit, 0, 0]\' for an empty array' do
1729
+ t = empty_array_t
1730
+ expect(calculator.string(t)).to eq('Array[Unit, 0, 0]')
1731
+ end
1732
+
1740
1733
  it 'should yield \'Collection\' and from/to for PCollectionType' do
1741
- col = collection_t()
1742
- expect(calculator.string(factory.constrain_size(col.copy, 1,1))).to eq('Collection[1, 1]')
1743
- expect(calculator.string(factory.constrain_size(col.copy, 1,2))).to eq('Collection[1, 2]')
1744
- expect(calculator.string(factory.constrain_size(col.copy, :default, 2))).to eq('Collection[default, 2]')
1745
- expect(calculator.string(factory.constrain_size(col.copy, 2, :default))).to eq('Collection[2, default]')
1734
+ expect(calculator.string(collection_t(range_t(1,1)))).to eq('Collection[1, 1]')
1735
+ expect(calculator.string(collection_t(range_t(1,2)))).to eq('Collection[1, 2]')
1736
+ expect(calculator.string(collection_t(range_t(:default, 2)))).to eq('Collection[default, 2]')
1737
+ expect(calculator.string(collection_t(range_t(2, :default)))).to eq('Collection[2, default]')
1746
1738
  end
1747
1739
 
1748
1740
  it 'should yield \'Array\' and from/to for PArrayType' do
1749
- arr = array_t(string_t)
1750
- expect(calculator.string(factory.constrain_size(arr.copy, 1,1))).to eq('Array[String, 1, 1]')
1751
- expect(calculator.string(factory.constrain_size(arr.copy, 1,2))).to eq('Array[String, 1, 2]')
1752
- expect(calculator.string(factory.constrain_size(arr.copy, :default, 2))).to eq('Array[String, default, 2]')
1753
- expect(calculator.string(factory.constrain_size(arr.copy, 2, :default))).to eq('Array[String, 2, default]')
1741
+ expect(calculator.string(array_t(string_t, range_t(1,1)))).to eq('Array[String, 1, 1]')
1742
+ expect(calculator.string(array_t(string_t, range_t(1,2)))).to eq('Array[String, 1, 2]')
1743
+ expect(calculator.string(array_t(string_t, range_t(:default, 2)))).to eq('Array[String, default, 2]')
1744
+ expect(calculator.string(array_t(string_t, range_t(2, :default)))).to eq('Array[String, 2, default]')
1754
1745
  end
1755
1746
 
1756
1747
  it 'should yield \'Tuple[Integer]\' for PTupleType[PIntegerType]' do
1757
- t = Puppet::Pops::Types::PTupleType.new()
1758
- t.addTypes(Puppet::Pops::Types::PIntegerType.new())
1748
+ t = Puppet::Pops::Types::PTupleType.new([Puppet::Pops::Types::PIntegerType::DEFAULT])
1759
1749
  expect(calculator.string(t)).to eq('Tuple[Integer]')
1760
1750
  end
1761
1751
 
1762
1752
  it 'should yield \'Tuple[T, T,..]\' for PTupleType[T, T, ...]' do
1763
- t = Puppet::Pops::Types::PTupleType.new()
1764
- t.addTypes(Puppet::Pops::Types::PIntegerType.new())
1765
- t.addTypes(Puppet::Pops::Types::PIntegerType.new())
1766
- t.addTypes(Puppet::Pops::Types::PStringType.new())
1753
+ t = Puppet::Pops::Types::PTupleType.new([Puppet::Pops::Types::PIntegerType::DEFAULT, Puppet::Pops::Types::PIntegerType::DEFAULT, Puppet::Pops::Types::PStringType::DEFAULT])
1767
1754
  expect(calculator.string(t)).to eq('Tuple[Integer, Integer, String]')
1768
1755
  end
1769
1756
 
1770
1757
  it 'should yield \'Tuple\' and from/to for PTupleType' do
1771
- tuple_t = tuple_t(string_t)
1772
- expect(calculator.string(factory.constrain_size(tuple_t.copy, 1,1))).to eq('Tuple[String, 1, 1]')
1773
- expect(calculator.string(factory.constrain_size(tuple_t.copy, 1,2))).to eq('Tuple[String, 1, 2]')
1774
- expect(calculator.string(factory.constrain_size(tuple_t.copy, :default, 2))).to eq('Tuple[String, default, 2]')
1775
- expect(calculator.string(factory.constrain_size(tuple_t.copy, 2, :default))).to eq('Tuple[String, 2, default]')
1758
+ expect(calculator.string(constrained_tuple_t(range_t(1,1), string_t))).to eq('Tuple[String, 1, 1]')
1759
+ expect(calculator.string(constrained_tuple_t(range_t(1,2), string_t))).to eq('Tuple[String, 1, 2]')
1760
+ expect(calculator.string(constrained_tuple_t(range_t(:default, 2), string_t))).to eq('Tuple[String, 0, 2]')
1761
+ expect(calculator.string(constrained_tuple_t(range_t(2, :default), string_t))).to eq('Tuple[String, 2, default]')
1776
1762
  end
1777
1763
 
1778
1764
  it 'should yield \'Struct\' and details for PStructType' do
1779
1765
  struct_t = struct_t({'a'=>Integer, 'b'=>String})
1780
1766
  expect(calculator.string(struct_t)).to eq("Struct[{'a'=>Integer, 'b'=>String}]")
1781
1767
  struct_t = struct_t({})
1782
- expect(calculator.string(struct_t)).to eq("Struct")
1768
+ expect(calculator.string(struct_t)).to eq('Struct')
1783
1769
  end
1784
1770
 
1785
1771
  it 'should yield \'Hash[String, Integer]\' for PHashType[PStringType, PIntegerType]' do
1786
- t = Puppet::Pops::Types::PHashType.new()
1787
- t.key_type = Puppet::Pops::Types::PStringType.new()
1788
- t.element_type = Puppet::Pops::Types::PIntegerType.new()
1772
+ t = Puppet::Pops::Types::PHashType.new(Puppet::Pops::Types::PStringType::DEFAULT, Puppet::Pops::Types::PIntegerType::DEFAULT)
1789
1773
  expect(calculator.string(t)).to eq('Hash[String, Integer]')
1790
1774
  end
1791
1775
 
1792
1776
  it 'should yield \'Hash\' and from/to for PHashType' do
1793
- hsh = hash_t(string_t, string_t)
1794
- expect(calculator.string(factory.constrain_size(hsh.copy, 1,1))).to eq('Hash[String, String, 1, 1]')
1795
- expect(calculator.string(factory.constrain_size(hsh.copy, 1,2))).to eq('Hash[String, String, 1, 2]')
1796
- expect(calculator.string(factory.constrain_size(hsh.copy, :default, 2))).to eq('Hash[String, String, default, 2]')
1797
- expect(calculator.string(factory.constrain_size(hsh.copy, 2, :default))).to eq('Hash[String, String, 2, default]')
1777
+ expect(calculator.string(hash_t(string_t, string_t, range_t(1,1)))).to eq('Hash[String, String, 1, 1]')
1778
+ expect(calculator.string(hash_t(string_t, string_t, range_t(1,2)))).to eq('Hash[String, String, 1, 2]')
1779
+ expect(calculator.string(hash_t(string_t, string_t, range_t(:default, 2)))).to eq('Hash[String, String, default, 2]')
1780
+ expect(calculator.string(hash_t(string_t, string_t, range_t(2, :default)))).to eq('Hash[String, String, 2, default]')
1798
1781
  end
1799
1782
 
1800
1783
  it "should yield 'Class' for a PHostClassType" do
1801
- t = Puppet::Pops::Types::PHostClassType.new()
1784
+ t = Puppet::Pops::Types::PHostClassType::DEFAULT
1802
1785
  expect(calculator.string(t)).to eq('Class')
1803
1786
  end
1804
1787
 
1805
1788
  it "should yield 'Class[x]' for a PHostClassType[x]" do
1806
- t = Puppet::Pops::Types::PHostClassType.new()
1807
- t.class_name = 'x'
1789
+ t = Puppet::Pops::Types::PHostClassType.new('x')
1808
1790
  expect(calculator.string(t)).to eq('Class[x]')
1809
1791
  end
1810
1792
 
1811
1793
  it "should yield 'Resource' for a PResourceType" do
1812
- t = Puppet::Pops::Types::PResourceType.new()
1794
+ t = Puppet::Pops::Types::PResourceType::DEFAULT
1813
1795
  expect(calculator.string(t)).to eq('Resource')
1814
1796
  end
1815
1797
 
1816
1798
  it 'should yield \'File\' for a PResourceType[\'File\']' do
1817
- t = Puppet::Pops::Types::PResourceType.new()
1818
- t.type_name = 'File'
1799
+ t = Puppet::Pops::Types::PResourceType.new('File')
1819
1800
  expect(calculator.string(t)).to eq('File')
1820
1801
  end
1821
1802
 
1822
1803
  it "should yield 'File['/tmp/foo']' for a PResourceType['File', '/tmp/foo']" do
1823
- t = Puppet::Pops::Types::PResourceType.new()
1824
- t.type_name = 'File'
1825
- t.title = '/tmp/foo'
1804
+ t = Puppet::Pops::Types::PResourceType.new('File', '/tmp/foo')
1826
1805
  expect(calculator.string(t)).to eq("File['/tmp/foo']")
1827
1806
  end
1828
1807
 
@@ -1834,8 +1813,8 @@ describe 'The type calculator' do
1834
1813
  it "should yield 'Pattern[/pat/,...]' for a PPatternType['pat',...]" do
1835
1814
  t = pattern_t('a')
1836
1815
  t2 = pattern_t('a', 'b', 'c')
1837
- expect(calculator.string(t)).to eq("Pattern[/a/]")
1838
- expect(calculator.string(t2)).to eq("Pattern[/a/, /b/, /c/]")
1816
+ expect(calculator.string(t)).to eq('Pattern[/a/]')
1817
+ expect(calculator.string(t2)).to eq('Pattern[/a/, /b/, /c/]')
1839
1818
  end
1840
1819
 
1841
1820
  it "should escape special characters in the string for a PPatternType['pat',...]" do
@@ -1844,46 +1823,46 @@ describe 'The type calculator' do
1844
1823
  end
1845
1824
 
1846
1825
  it "should yield 'Variant[t1,t2,...]' for a PVariantType[t1, t2,...]" do
1847
- t1 = string_t()
1848
- t2 = integer_t()
1826
+ t1 = string_t
1827
+ t2 = integer_t
1849
1828
  t3 = pattern_t('a')
1850
1829
  t = variant_t(t1, t2, t3)
1851
- expect(calculator.string(t)).to eq("Variant[String, Integer, Pattern[/a/]]")
1830
+ expect(calculator.string(t)).to eq('Variant[String, Integer, Pattern[/a/]]')
1852
1831
  end
1853
1832
 
1854
1833
  it "should yield 'Callable' for generic callable" do
1855
- expect(calculator.string(all_callables_t)).to eql("Callable")
1834
+ expect(calculator.string(all_callables_t)).to eql('Callable')
1856
1835
  end
1857
1836
 
1858
1837
  it "should yield 'Callable[0,0]' for callable without params" do
1859
- expect(calculator.string(callable_t)).to eql("Callable[0, 0]")
1838
+ expect(calculator.string(callable_t)).to eql('Callable[0, 0]')
1860
1839
  end
1861
1840
 
1862
1841
  it "should yield 'Callable[t,t]' for callable with typed parameters" do
1863
- expect(calculator.string(callable_t(String, Integer))).to eql("Callable[String, Integer]")
1842
+ expect(calculator.string(callable_t(String, Integer))).to eql('Callable[String, Integer]')
1864
1843
  end
1865
1844
 
1866
1845
  it "should yield 'Callable[t,min,max]' for callable with size constraint (infinite max)" do
1867
- expect(calculator.string(callable_t(String, 0))).to eql("Callable[String, 0, default]")
1846
+ expect(calculator.string(callable_t(String, 0))).to eql('Callable[String, 0, default]')
1868
1847
  end
1869
1848
 
1870
1849
  it "should yield 'Callable[t,min,max]' for callable with size constraint (capped max)" do
1871
- expect(calculator.string(callable_t(String, 0, 3))).to eql("Callable[String, 0, 3]")
1850
+ expect(calculator.string(callable_t(String, 0, 3))).to eql('Callable[String, 0, 3]')
1872
1851
  end
1873
1852
 
1874
1853
  it "should yield 'Callable[min,max]' callable with size > 0" do
1875
- expect(calculator.string(callable_t(0, 0))).to eql("Callable[0, 0]")
1876
- expect(calculator.string(callable_t(0, 1))).to eql("Callable[0, 1]")
1877
- expect(calculator.string(callable_t(0, :default))).to eql("Callable[0, default]")
1854
+ expect(calculator.string(callable_t(0, 0))).to eql('Callable[0, 0]')
1855
+ expect(calculator.string(callable_t(0, 1))).to eql('Callable[0, 1]')
1856
+ expect(calculator.string(callable_t(0, :default))).to eql('Callable[0, default]')
1878
1857
  end
1879
1858
 
1880
1859
  it "should yield 'Callable[Callable]' for callable with block" do
1881
- expect(calculator.string(callable_t(all_callables_t))).to eql("Callable[0, 0, Callable]")
1882
- expect(calculator.string(callable_t(string_t, all_callables_t))).to eql("Callable[String, Callable]")
1883
- expect(calculator.string(callable_t(string_t, 1,1, all_callables_t))).to eql("Callable[String, 1, 1, Callable]")
1860
+ expect(calculator.string(callable_t(all_callables_t))).to eql('Callable[0, 0, Callable]')
1861
+ expect(calculator.string(callable_t(string_t, all_callables_t))).to eql('Callable[String, Callable]')
1862
+ expect(calculator.string(callable_t(string_t, 1,1, all_callables_t))).to eql('Callable[String, 1, 1, Callable]')
1884
1863
  end
1885
1864
 
1886
- it "should yield Unit for a Unit type" do
1865
+ it 'should yield Unit for a Unit type' do
1887
1866
  expect(calculator.string(unit_t)).to eql('Unit')
1888
1867
  end
1889
1868
 
@@ -1906,63 +1885,62 @@ describe 'The type calculator' do
1906
1885
  context 'when processing meta type' do
1907
1886
  it 'should infer PType as the type of all other types' do
1908
1887
  ptype = Puppet::Pops::Types::PType
1909
- expect(calculator.infer(Puppet::Pops::Types::PUndefType.new() ).is_a?(ptype)).to eq(true)
1910
- expect(calculator.infer(Puppet::Pops::Types::PDataType.new() ).is_a?(ptype)).to eq(true)
1911
- expect(calculator.infer(Puppet::Pops::Types::PScalarType.new() ).is_a?(ptype)).to eq(true)
1912
- expect(calculator.infer(Puppet::Pops::Types::PStringType.new() ).is_a?(ptype)).to eq(true)
1913
- expect(calculator.infer(Puppet::Pops::Types::PNumericType.new() ).is_a?(ptype)).to eq(true)
1914
- expect(calculator.infer(Puppet::Pops::Types::PIntegerType.new() ).is_a?(ptype)).to eq(true)
1915
- expect(calculator.infer(Puppet::Pops::Types::PFloatType.new() ).is_a?(ptype)).to eq(true)
1916
- expect(calculator.infer(Puppet::Pops::Types::PRegexpType.new() ).is_a?(ptype)).to eq(true)
1917
- expect(calculator.infer(Puppet::Pops::Types::PBooleanType.new() ).is_a?(ptype)).to eq(true)
1918
- expect(calculator.infer(Puppet::Pops::Types::PCollectionType.new()).is_a?(ptype)).to eq(true)
1919
- expect(calculator.infer(Puppet::Pops::Types::PArrayType.new() ).is_a?(ptype)).to eq(true)
1920
- expect(calculator.infer(Puppet::Pops::Types::PHashType.new() ).is_a?(ptype)).to eq(true)
1921
- expect(calculator.infer(Puppet::Pops::Types::PRuntimeType.new() ).is_a?(ptype)).to eq(true)
1922
- expect(calculator.infer(Puppet::Pops::Types::PHostClassType.new() ).is_a?(ptype)).to eq(true)
1923
- expect(calculator.infer(Puppet::Pops::Types::PResourceType.new() ).is_a?(ptype)).to eq(true)
1924
- expect(calculator.infer(Puppet::Pops::Types::PEnumType.new() ).is_a?(ptype)).to eq(true)
1925
- expect(calculator.infer(Puppet::Pops::Types::PPatternType.new() ).is_a?(ptype)).to eq(true)
1926
- expect(calculator.infer(Puppet::Pops::Types::PVariantType.new() ).is_a?(ptype)).to eq(true)
1927
- expect(calculator.infer(Puppet::Pops::Types::PTupleType.new() ).is_a?(ptype)).to eq(true)
1928
- expect(calculator.infer(Puppet::Pops::Types::POptionalType.new() ).is_a?(ptype)).to eq(true)
1929
- expect(calculator.infer(Puppet::Pops::Types::PCallableType.new() ).is_a?(ptype)).to eq(true)
1888
+ expect(calculator.infer(Puppet::Pops::Types::PUndefType::DEFAULT ).is_a?(ptype)).to eq(true)
1889
+ expect(calculator.infer(Puppet::Pops::Types::PDataType::DEFAULT ).is_a?(ptype)).to eq(true)
1890
+ expect(calculator.infer(Puppet::Pops::Types::PScalarType::DEFAULT ).is_a?(ptype)).to eq(true)
1891
+ expect(calculator.infer(Puppet::Pops::Types::PStringType::DEFAULT ).is_a?(ptype)).to eq(true)
1892
+ expect(calculator.infer(Puppet::Pops::Types::PNumericType::DEFAULT ).is_a?(ptype)).to eq(true)
1893
+ expect(calculator.infer(Puppet::Pops::Types::PIntegerType::DEFAULT ).is_a?(ptype)).to eq(true)
1894
+ expect(calculator.infer(Puppet::Pops::Types::PFloatType::DEFAULT ).is_a?(ptype)).to eq(true)
1895
+ expect(calculator.infer(Puppet::Pops::Types::PRegexpType::DEFAULT ).is_a?(ptype)).to eq(true)
1896
+ expect(calculator.infer(Puppet::Pops::Types::PBooleanType::DEFAULT ).is_a?(ptype)).to eq(true)
1897
+ expect(calculator.infer(Puppet::Pops::Types::PCollectionType::DEFAULT).is_a?(ptype)).to eq(true)
1898
+ expect(calculator.infer(Puppet::Pops::Types::PArrayType::DEFAULT ).is_a?(ptype)).to eq(true)
1899
+ expect(calculator.infer(Puppet::Pops::Types::PHashType::DEFAULT ).is_a?(ptype)).to eq(true)
1900
+ expect(calculator.infer(Puppet::Pops::Types::PRuntimeType::DEFAULT ).is_a?(ptype)).to eq(true)
1901
+ expect(calculator.infer(Puppet::Pops::Types::PHostClassType::DEFAULT ).is_a?(ptype)).to eq(true)
1902
+ expect(calculator.infer(Puppet::Pops::Types::PResourceType::DEFAULT ).is_a?(ptype)).to eq(true)
1903
+ expect(calculator.infer(Puppet::Pops::Types::PEnumType::DEFAULT ).is_a?(ptype)).to eq(true)
1904
+ expect(calculator.infer(Puppet::Pops::Types::PPatternType::DEFAULT ).is_a?(ptype)).to eq(true)
1905
+ expect(calculator.infer(Puppet::Pops::Types::PVariantType::DEFAULT ).is_a?(ptype)).to eq(true)
1906
+ expect(calculator.infer(Puppet::Pops::Types::PTupleType::DEFAULT ).is_a?(ptype)).to eq(true)
1907
+ expect(calculator.infer(Puppet::Pops::Types::POptionalType::DEFAULT ).is_a?(ptype)).to eq(true)
1908
+ expect(calculator.infer(Puppet::Pops::Types::PCallableType::DEFAULT ).is_a?(ptype)).to eq(true)
1930
1909
  end
1931
1910
 
1932
1911
  it 'should infer PType as the type of all other types' do
1933
- ptype = Puppet::Pops::Types::PType
1934
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PUndefType.new() ))).to eq("Type[Undef]")
1935
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PDataType.new() ))).to eq("Type[Data]")
1936
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PScalarType.new() ))).to eq("Type[Scalar]")
1937
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PStringType.new() ))).to eq("Type[String]")
1938
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PNumericType.new() ))).to eq("Type[Numeric]")
1939
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PIntegerType.new() ))).to eq("Type[Integer]")
1940
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PFloatType.new() ))).to eq("Type[Float]")
1941
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PRegexpType.new() ))).to eq("Type[Regexp]")
1942
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PBooleanType.new() ))).to eq("Type[Boolean]")
1943
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PCollectionType.new()))).to eq("Type[Collection]")
1944
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PArrayType.new() ))).to eq("Type[Array[?]]")
1945
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PHashType.new() ))).to eq("Type[Hash[?, ?]]")
1946
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PRuntimeType.new() ))).to eq("Type[Runtime[?, ?]]")
1947
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PHostClassType.new() ))).to eq("Type[Class]")
1948
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PResourceType.new() ))).to eq("Type[Resource]")
1949
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PEnumType.new() ))).to eq("Type[Enum]")
1950
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PVariantType.new() ))).to eq("Type[Variant]")
1951
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PPatternType.new() ))).to eq("Type[Pattern]")
1952
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PTupleType.new() ))).to eq("Type[Tuple]")
1953
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::POptionalType.new() ))).to eq("Type[Optional]")
1954
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PCallableType.new() ))).to eq("Type[Callable]")
1955
-
1956
- expect(calculator.infer(Puppet::Pops::Types::PResourceType.new(:type_name => 'foo::fee::fum')).to_s).to eq("Type[Foo::Fee::Fum]")
1957
- expect(calculator.string(calculator.infer(Puppet::Pops::Types::PResourceType.new(:type_name => 'foo::fee::fum')))).to eq("Type[Foo::Fee::Fum]")
1958
- expect(calculator.infer(Puppet::Pops::Types::PResourceType.new(:type_name => 'Foo::Fee::Fum')).to_s).to eq("Type[Foo::Fee::Fum]")
1912
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PUndefType::DEFAULT ))).to eq('Type[Undef]')
1913
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PDataType::DEFAULT ))).to eq('Type[Data]')
1914
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PScalarType::DEFAULT ))).to eq('Type[Scalar]')
1915
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PStringType::DEFAULT ))).to eq('Type[String]')
1916
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PNumericType::DEFAULT ))).to eq('Type[Numeric]')
1917
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PIntegerType::DEFAULT ))).to eq('Type[Integer]')
1918
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PFloatType::DEFAULT ))).to eq('Type[Float]')
1919
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PRegexpType::DEFAULT ))).to eq('Type[Regexp]')
1920
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PBooleanType::DEFAULT ))).to eq('Type[Boolean]')
1921
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PCollectionType::DEFAULT))).to eq('Type[Collection]')
1922
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PArrayType::DEFAULT ))).to eq('Type[Array[?]]')
1923
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PHashType::DEFAULT ))).to eq('Type[Hash[?, ?]]')
1924
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PRuntimeType::DEFAULT ))).to eq('Type[Runtime[?, ?]]')
1925
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PHostClassType::DEFAULT ))).to eq('Type[Class]')
1926
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PResourceType::DEFAULT ))).to eq('Type[Resource]')
1927
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PEnumType::DEFAULT ))).to eq('Type[Enum]')
1928
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PVariantType::DEFAULT ))).to eq('Type[Variant]')
1929
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PPatternType::DEFAULT ))).to eq('Type[Pattern]')
1930
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PTupleType::DEFAULT ))).to eq('Type[Tuple]')
1931
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::POptionalType::DEFAULT ))).to eq('Type[Optional]')
1932
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PCallableType::DEFAULT ))).to eq('Type[Callable]')
1933
+
1934
+ expect(calculator.infer(Puppet::Pops::Types::PResourceType.new('foo::fee::fum')).to_s).to eq('Type[Foo::Fee::Fum]')
1935
+ expect(calculator.string(calculator.infer(Puppet::Pops::Types::PResourceType.new('foo::fee::fum')))).to eq('Type[Foo::Fee::Fum]')
1936
+ expect(calculator.infer(Puppet::Pops::Types::PResourceType.new('Foo::Fee::Fum')).to_s).to eq('Type[Foo::Fee::Fum]')
1959
1937
  end
1960
1938
 
1961
1939
  it "computes the common type of PType's type parameter" do
1962
- int_t = Puppet::Pops::Types::PIntegerType.new()
1963
- string_t = Puppet::Pops::Types::PStringType.new()
1964
- expect(calculator.string(calculator.infer([int_t]))).to eq("Array[Type[Integer], 1, 1]")
1965
- expect(calculator.string(calculator.infer([int_t, string_t]))).to eq("Array[Type[Scalar], 2, 2]")
1940
+ int_t = Puppet::Pops::Types::PIntegerType::DEFAULT
1941
+ string_t = Puppet::Pops::Types::PStringType::DEFAULT
1942
+ expect(calculator.string(calculator.infer([int_t]))).to eq('Array[Type[Integer], 1, 1]')
1943
+ expect(calculator.string(calculator.infer([int_t, string_t]))).to eq('Array[Type[Scalar], 2, 2]')
1966
1944
  end
1967
1945
 
1968
1946
  it 'should infer PType as the type of ruby classes' do
@@ -1974,19 +1952,19 @@ describe 'The type calculator' do
1974
1952
  end
1975
1953
 
1976
1954
  it 'should infer PType as the type of PType (meta regression short-circuit)' do
1977
- expect(calculator.infer(Puppet::Pops::Types::PType.new()).is_a?(Puppet::Pops::Types::PType)).to eq(true)
1955
+ expect(calculator.infer(Puppet::Pops::Types::PType::DEFAULT).is_a?(Puppet::Pops::Types::PType)).to eq(true)
1978
1956
  end
1979
1957
 
1980
1958
  it 'computes instance? to be true if parameterized and type match' do
1981
- int_t = Puppet::Pops::Types::PIntegerType.new()
1959
+ int_t = Puppet::Pops::Types::PIntegerType::DEFAULT
1982
1960
  type_t = Puppet::Pops::Types::TypeFactory.type_type(int_t)
1983
1961
  type_type_t = Puppet::Pops::Types::TypeFactory.type_type(type_t)
1984
1962
  expect(calculator.instance?(type_type_t, type_t)).to eq(true)
1985
1963
  end
1986
1964
 
1987
1965
  it 'computes instance? to be false if parameterized and type do not match' do
1988
- int_t = Puppet::Pops::Types::PIntegerType.new()
1989
- string_t = Puppet::Pops::Types::PStringType.new()
1966
+ int_t = Puppet::Pops::Types::PIntegerType::DEFAULT
1967
+ string_t = Puppet::Pops::Types::PStringType::DEFAULT
1990
1968
  type_t = Puppet::Pops::Types::TypeFactory.type_type(int_t)
1991
1969
  type_t2 = Puppet::Pops::Types::TypeFactory.type_type(string_t)
1992
1970
  type_type_t = Puppet::Pops::Types::TypeFactory.type_type(type_t)
@@ -1995,77 +1973,71 @@ describe 'The type calculator' do
1995
1973
  end
1996
1974
 
1997
1975
  it 'computes instance? to be true if unparameterized and matched against a type[?]' do
1998
- int_t = Puppet::Pops::Types::PIntegerType.new()
1976
+ int_t = Puppet::Pops::Types::PIntegerType::DEFAULT
1999
1977
  type_t = Puppet::Pops::Types::TypeFactory.type_type(int_t)
2000
- expect(calculator.instance?(Puppet::Pops::Types::PType.new, type_t)).to eq(true)
1978
+ expect(calculator.instance?(Puppet::Pops::Types::PType::DEFAULT, type_t)).to eq(true)
2001
1979
  end
2002
1980
  end
2003
1981
 
2004
- context "when asking for an enumerable " do
2005
- it "should produce an enumerable for an Integer range that is not infinite" do
2006
- t = Puppet::Pops::Types::PIntegerType.new()
2007
- t.from = 1
2008
- t.to = 10
1982
+ context 'when asking for an enumerable ' do
1983
+ it 'should produce an enumerable for an Integer range that is not infinite' do
1984
+ t = Puppet::Pops::Types::PIntegerType.new(1, 10)
2009
1985
  expect(calculator.enumerable(t).respond_to?(:each)).to eq(true)
2010
1986
  end
2011
1987
 
2012
- it "should not produce an enumerable for an Integer range that has an infinite side" do
2013
- t = Puppet::Pops::Types::PIntegerType.new()
2014
- t.from = nil
2015
- t.to = 10
1988
+ it 'should not produce an enumerable for an Integer range that has an infinite side' do
1989
+ t = Puppet::Pops::Types::PIntegerType.new(nil, 10)
2016
1990
  expect(calculator.enumerable(t)).to eq(nil)
2017
1991
 
2018
- t = Puppet::Pops::Types::PIntegerType.new()
2019
- t.from = 1
2020
- t.to = nil
1992
+ t = Puppet::Pops::Types::PIntegerType.new(1, nil)
2021
1993
  expect(calculator.enumerable(t)).to eq(nil)
2022
1994
  end
2023
1995
 
2024
- it "all but Integer range are not enumerable" do
1996
+ it 'all but Integer range are not enumerable' do
2025
1997
  [Object, Numeric, Float, String, Regexp, Array, Hash].each do |t|
2026
1998
  expect(calculator.enumerable(calculator.type(t))).to eq(nil)
2027
1999
  end
2028
2000
  end
2029
2001
  end
2030
2002
 
2031
- context "when dealing with different types of inference" do
2032
- it "an instance specific inference is produced by infer" do
2003
+ context 'when dealing with different types of inference' do
2004
+ it 'an instance specific inference is produced by infer' do
2033
2005
  expect(calculator.infer(['a','b']).element_type.values).to eq(['a', 'b'])
2034
2006
  end
2035
2007
 
2036
- it "a generic inference is produced using infer_generic" do
2008
+ it 'a generic inference is produced using infer_generic' do
2037
2009
  expect(calculator.infer_generic(['a','b']).element_type.values).to eq([])
2038
2010
  end
2039
2011
 
2040
- it "a generic result is created by generalize! given an instance specific result for an Array" do
2012
+ it 'a generic result is created by generalize given an instance specific result for an Array' do
2041
2013
  generic = calculator.infer(['a','b'])
2042
2014
  expect(generic.element_type.values).to eq(['a', 'b'])
2043
- calculator.generalize!(generic)
2015
+ generic = generic.generalize
2044
2016
  expect(generic.element_type.values).to eq([])
2045
2017
  end
2046
2018
 
2047
- it 'a generic result is created by generalize! given an instance specific result for a Hash' do
2019
+ it 'a generic result is created by generalize given an instance specific result for a Hash' do
2048
2020
  generic = calculator.infer({'a' =>1,'b' => 2})
2049
2021
  expect(generic.key_type.values.sort).to eq(['a', 'b'])
2050
2022
  expect(generic.element_type.from).to eq(1)
2051
2023
  expect(generic.element_type.to).to eq(2)
2052
- calculator.generalize!(generic)
2024
+ generic = generic.generalize
2053
2025
  expect(generic.key_type.values).to eq([])
2054
2026
  expect(generic.element_type.from).to eq(nil)
2055
2027
  expect(generic.element_type.to).to eq(nil)
2056
2028
  end
2057
2029
 
2058
2030
  it 'ensures that Struct key types are not generalized' do
2059
- generic = calculator.generalize!(struct_t({'a' => object_t}))
2031
+ generic = struct_t({'a' => object_t}).generalize
2060
2032
  expect(calculator.string(generic)).to eq("Struct[{'a'=>Any}]")
2061
- generic = calculator.generalize!(struct_t({not_undef_t('a') => object_t}))
2033
+ generic = struct_t({not_undef_t('a') => object_t}).generalize
2062
2034
  expect(calculator.string(generic)).to eq("Struct[{NotUndef['a']=>Any}]")
2063
- generic = calculator.generalize!(struct_t({optional_t('a') => string_t}))
2035
+ generic = struct_t({optional_t('a') => string_t}).generalize
2064
2036
  expect(calculator.string(generic)).to eq("Struct[{Optional['a']=>String}]")
2065
2037
  end
2066
2038
 
2067
2039
  it 'ensures that Struct value types are generalized' do
2068
- generic = calculator.generalize!(struct_t({'a' => range_t(1, 3)}))
2040
+ generic = struct_t({'a' => range_t(1, 3)}).generalize
2069
2041
  expect(calculator.string(generic)).to eq("Struct[{'a'=>Integer}]")
2070
2042
  end
2071
2043
 
@@ -2081,7 +2053,7 @@ describe 'The type calculator' do
2081
2053
  expect(element_types[3].class).to eq(Puppet::Pops::Types::PIntegerType)
2082
2054
  end
2083
2055
 
2084
- it "does not reduce by combining types when using infer_set and values are undef" do
2056
+ it 'does not reduce by combining types when using infer_set and values are undef' do
2085
2057
  element_type = calculator.infer(['a',nil]).element_type
2086
2058
  expect(element_type.class).to eq(Puppet::Pops::Types::PStringType)
2087
2059
  inferred_type = calculator.infer_set(['a',nil])
@@ -2090,6 +2062,18 @@ describe 'The type calculator' do
2090
2062
  expect(element_types[0].class).to eq(Puppet::Pops::Types::PStringType)
2091
2063
  expect(element_types[1].class).to eq(Puppet::Pops::Types::PUndefType)
2092
2064
  end
2065
+
2066
+ it 'infers on an empty Array produces Array[Unit,0,0]' do
2067
+ inferred_type = calculator.infer([])
2068
+ expect(inferred_type.element_type.class).to eq(Puppet::Pops::Types::PUnitType)
2069
+ expect(inferred_type.size_range).to eq([0, 0])
2070
+ end
2071
+
2072
+ it 'infer_set on an empty Array produces Array[Unit,0,0]' do
2073
+ inferred_type = calculator.infer_set([])
2074
+ expect(inferred_type.element_type.class).to eq(Puppet::Pops::Types::PUnitType)
2075
+ expect(inferred_type.size_range).to eq([0, 0])
2076
+ end
2093
2077
  end
2094
2078
 
2095
2079
  context 'when determening callability' do
@@ -2114,8 +2098,7 @@ describe 'The type calculator' do
2114
2098
 
2115
2099
  it 'with args array' do
2116
2100
  required = callable_t(string_t)
2117
- given = array_t(string_t)
2118
- factory.constrain_size(given, 1, 1)
2101
+ given = array_t(string_t, range_t(1, 1))
2119
2102
  expect(calculator.callable?(required, given)).to eq(true)
2120
2103
  end
2121
2104
  end