Skip to content

Commit 8daf434

Browse files
authored
Merge pull request #8616 from joshcooper/semver_11077
(PUP-11077) Pass SemVer prerelease and build as an array
2 parents c59f276 + 63dbb09 commit 8daf434

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/puppet/pops/types/p_sem_ver_type.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,22 @@ def from_string(str)
9595
end
9696

9797
def from_args(major, minor, patch, prerelease = nil, build = nil)
98-
SemanticPuppet::Version.new(major, minor, patch, prerelease, build)
98+
SemanticPuppet::Version.new(major, minor, patch, to_array(prerelease), to_array(build))
9999
end
100100

101101
def from_hash(hash)
102-
SemanticPuppet::Version.new(hash['major'], hash['minor'], hash['patch'], hash['prerelease'], hash['build'])
102+
SemanticPuppet::Version.new(hash['major'], hash['minor'], hash['patch'], to_array(hash['prerelease']), to_array(hash['build']))
103103
end
104104

105105
def on_error(str)
106106
_("The string '%{str}' cannot be converted to a SemVer") % { str: str }
107107
end
108+
109+
private
110+
111+
def to_array(component)
112+
component ? [component] : nil
113+
end
108114
end
109115
end
110116

spec/unit/pops/types/p_sem_ver_type_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ module Types
125125
expect(eval_and_collect_notices(code)).to eql(['true', 'false'])
126126
end
127127

128+
it 'can be compared to another instance created from arguments' do
129+
code = <<-CODE
130+
$x = SemVer('1.2.3-rc4+5')
131+
$y = SemVer(1, 2, 3, 'rc4', '5')
132+
notice($x == $y)
133+
CODE
134+
expect(eval_and_collect_notices(code)).to eql(['true'])
135+
end
136+
137+
it 'can be compared to another instance created from a hash' do
138+
code = <<-CODE
139+
$x = SemVer('1.2.3-rc4+5')
140+
$y = SemVer(major => 1, minor => 2, patch => 3, prerelease => 'rc4', build => '5')
141+
notice($x == $y)
142+
CODE
143+
expect(eval_and_collect_notices(code)).to eql(['true'])
144+
end
145+
128146
it 'can be compared to another instance for magnitude' do
129147
code = <<-CODE
130148
$x = SemVer('1.1.1')

0 commit comments

Comments
 (0)