Skip to content

Commit 11f3817

Browse files
committed
update Version to enable Version string without the Epoch
This is used in a few filepaths.
1 parent 184de2b commit 11f3817

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

version/version.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,21 @@ func (version Version) MarshalControl() (string, error) {
8888
return version.String(), nil
8989
}
9090

91-
func (v Version) String() string {
92-
var result string
93-
if v.Epoch > 0 {
94-
result = strconv.Itoa(int(v.Epoch)) + ":" + v.Version
95-
} else {
96-
result = v.Version
97-
}
91+
func (v Version) StringWithoutEpoch() string {
92+
result := v.Version
9893
if len(v.Revision) > 0 {
9994
result += "-" + v.Revision
10095
}
10196
return result
10297
}
10398

99+
func (v Version) String() string {
100+
if v.Epoch > 0 {
101+
return fmt.Sprintf("%d:%s", v.Epoch, v.StringWithoutEpoch())
102+
}
103+
return v.StringWithoutEpoch()
104+
}
105+
104106
func cisdigit(r rune) bool {
105107
return r >= '0' && r <= '9'
106108
}

version/version_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
package version // import "pault.ag/go/debian/version"
3030

3131
import (
32+
"strings"
3233
"testing"
3334
)
3435

@@ -357,4 +358,29 @@ func TestParseInvalidCharactersInRevision(t *testing.T) {
357358
}
358359
}
359360

361+
func TestString(t *testing.T) {
362+
if strings.Compare("1.0-1", Version{
363+
Version: "1.0",
364+
Revision: "1",
365+
}.String()) != 0 {
366+
t.Errorf("String() returned malformed Version")
367+
}
368+
369+
if strings.Compare("1:1.0-1", Version{
370+
Epoch: 1,
371+
Version: "1.0",
372+
Revision: "1",
373+
}.String()) != 0 {
374+
t.Errorf("String() returned malformed Version with Epoch")
375+
}
376+
377+
if strings.Compare("1.0-1", Version{
378+
Epoch: 1,
379+
Version: "1.0",
380+
Revision: "1",
381+
}.StringWithoutEpoch()) != 0 {
382+
t.Errorf("StringWithoutEpoch() returned malformed Version with Epoch")
383+
}
384+
}
385+
360386
// vim:ts=4:sw=4:noexpandtab foldmethod=marker

0 commit comments

Comments
 (0)