diff --git a/lib/semver_normalizer.rb b/lib/semver_normalizer.rb old mode 100644 new mode 100755 index d2ebc622..ce0cbcd7 --- a/lib/semver_normalizer.rb +++ b/lib/semver_normalizer.rb @@ -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") => # + 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 diff --git a/spec/lib/semver_normalizer_spec.rb b/spec/lib/semver_normalizer_spec.rb index 2c36027f..d0759d93 100755 --- a/spec/lib/semver_normalizer_spec.rb +++ b/spec/lib/semver_normalizer_spec.rb @@ -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