Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix semvar normalizer #139

Merged
merged 2 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/semver_normalizer.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
# For example, "v3.4-20181225" gets normalized to "3.4.20181225".
# We have to normalize because +Semverse::Version+ requires version tags to be of the form "x.y.z".

# ("1.2.3-rc.1+build.1") => #<Version: @major=1, @minor=2, @patch=3, @pre_release='rc.1', @build='build.1'>

class SemverNormalizer
def self.call(tag)
return tag unless tag

tag
.to_s
.strip
.sub(/\Av/i, '') # strip off any leading 'v'
.gsub(/[-_]/, '.') # convert hyphens and underscores to dots
.strip # strip off any leading or trailing /t or /n or spaces
.sub(/\Av/i, '') # strip off any leading 'v'
.strip # strip any spaces after removing "v"
# stripping hypends and underscores substantially changes the version string
#.gsub(/[-_]/, '.') # convert hyphens and underscores to dots
end
end
11 changes: 6 additions & 5 deletions spec/lib/semver_normalizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

it 'strips off any leading "v" character' do
expect(subject.call("v790")).to eq '790'
expect(subject.call("V097")).to eq '097'
expect(subject.call("V097.1.0")).to eq '097.1.0'
expect(subject.call("V 097.1.0")).to eq '097.1.0'
end

it 'strips any leading and trailing whitespace' do
expect(subject.call("\t\nv790 ")).to eq '790'
expect(subject.call("\t\nv790.1.0 ")).to eq '790.1.0'
end

it 'replaces pseudo dots with dots' do
expect(subject.call("v7-0_9.0")).to eq '7.0.9.0'
expect(subject.call("V0.9-7_1")).to eq '0.9.7.1'
it 'does not replace underscore or hypen' do
expect(subject.call("v7.1.0-pre")).to eq '7.1.0-pre'
expect(subject.call("V0.9.1-7_1")).to eq '0.9.1-7_1'
end
end
end