File tree 2 files changed +35
-7
lines changed
2 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -88,19 +88,21 @@ func (version Version) MarshalControl() (string, error) {
88
88
return version .String (), nil
89
89
}
90
90
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
98
93
if len (v .Revision ) > 0 {
99
94
result += "-" + v .Revision
100
95
}
101
96
return result
102
97
}
103
98
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
+
104
106
func cisdigit (r rune ) bool {
105
107
return r >= '0' && r <= '9'
106
108
}
Original file line number Diff line number Diff line change 29
29
package version // import "pault.ag/go/debian/version"
30
30
31
31
import (
32
+ "strings"
32
33
"testing"
33
34
)
34
35
@@ -357,4 +358,29 @@ func TestParseInvalidCharactersInRevision(t *testing.T) {
357
358
}
358
359
}
359
360
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
+
360
386
// vim:ts=4:sw=4:noexpandtab foldmethod=marker
You can’t perform that action at this time.
0 commit comments