Skip to content

Commit b633f91

Browse files
committed
add short version
1 parent 6a9244f commit b633f91

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

semver/semver.go

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func (v Version) String() string {
8282
return vers
8383
}
8484

85+
func (v Version) Short() string {
86+
return fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)
87+
}
88+
8589
func (v Version) IsZero() bool {
8690
return v.Major == 0 && v.Minor == 0 && v.Patch == 0 && v.PreRelease == "" && v.BuildMeta == ""
8791
}

semver/semver_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ func TestIsZero(t *testing.T) {
119119
assert.False(t, Version{Major: 1}.IsZero(), "expected non-zero value to not be zero")
120120
}
121121

122+
func TestShort(t *testing.T) {
123+
v := Version{Major: 1, Minor: 2, Patch: 3, PreRelease: "alpha.4", BuildMeta: "exp.sha.5114f85"}
124+
assert.Equal(t, "1.2.3-alpha.4+exp.sha.5114f85", v.String(), "expected string representation to match")
125+
assert.Equal(t, "1.2.3", v.Short(), "expected short string representation to match")
126+
}
127+
122128
func TestSpecifies(t *testing.T) {
123129
// This test is covered more extensively in range tests.
124130
ver := MustParse("1.2.3")

0 commit comments

Comments
 (0)