summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Lindberg <henrik.lindberg@cloudsmith.com>2014-10-03 02:07:09 +0200
committerHenrik Lindberg <henrik.lindberg@cloudsmith.com>2014-10-03 02:07:09 +0200
commite45bc0a09a6ab31f4c6f7d809dc06d0c5ec2dfd1 (patch)
treeadf0d3147f8e0c0ed10e6c1049c6cc2895c79891
parent7b4f1bc25ef5e442e587a00de3f19d75fc7ed6c6 (diff)
downloadpuppet-e45bc0a09a6ab31f4c6f7d809dc06d0c5ec2dfd1.tar.gz
(PUP-3366) Correct comparisson of Enum > Enum[a]
Comparissons involving an unparentesized Enum were not correct because an iteration with all? returns true if the set being enumerated is empty. This modifies the logic, and adds missing tests.
-rw-r--r--lib/puppet/pops/types/type_calculator.rb4
-rw-r--r--spec/unit/pops/types/type_calculator_spec.rb5
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/puppet/pops/types/type_calculator.rb b/lib/puppet/pops/types/type_calculator.rb
index 1fe7fbea4..fd1487b78 100644
--- a/lib/puppet/pops/types/type_calculator.rb
+++ b/lib/puppet/pops/types/type_calculator.rb
@@ -1159,7 +1159,9 @@ class Puppet::Pops::Types::TypeCalculator
when Types::PVariantType
t2.types.all? {|variant_t| assignable_PEnumType(t, variant_t) }
when Types::PEnumType
- t2.values.all? { |s| t.values.any? {|e| e == s }}
+ # empty means any enum
+ return true if t.values.empty?
+ !t2.values.empty? && t2.values.all? { |s| t.values.any? {|e| e == s }}
else
false
end
diff --git a/spec/unit/pops/types/type_calculator_spec.rb b/spec/unit/pops/types/type_calculator_spec.rb
index e60a53651..b11ed23a9 100644
--- a/spec/unit/pops/types/type_calculator_spec.rb
+++ b/spec/unit/pops/types/type_calculator_spec.rb
@@ -845,6 +845,11 @@ describe 'The type calculator' do
calculator.assignable?(enum_t('a', 'b'), enum_t('c')).should == false
end
+ it 'non parameterized enum accepts any other enum but not the reverse' do
+ calculator.assignable?(enum_t(), enum_t('a')).should == true
+ calculator.assignable?(enum_t('a'), enum_t()).should == false
+ end
+
it 'enum should accept a variant where all variants are acceptable' do
enum = enum_t('a', 'b')
calculator.assignable?(enum, variant_t(string_t('a'), string_t('b'))).should == true