References #61

This commit is contained in:
Jguer 2017-10-30 21:19:05 +09:00
parent 83e8c54caa
commit 1f29de4805
6 changed files with 31 additions and 32 deletions

2
Gopkg.lock generated
View File

@ -17,7 +17,7 @@
branch = "master"
name = "github.com/mikkeloscar/gopkgbuild"
packages = ["."]
revision = "46d010163d87513b0f05fb67400475348bd50cc9"
revision = "a185f55210904932d0a58aaf30890f2c17218604"
[solve-meta]
analyzer-name = "dep"

View File

@ -80,11 +80,11 @@ func (u upSlice) Print(start int) {
fmt.Printf("\x1b[1;%dm%s\x1b[0m/\x1b[1;39m%-25s\t\t\x1b[0m", f(i.Repository), i.Repository, i.Name)
if old.Version != new.Version {
fmt.Printf("\x1b[31m%18s\x1b[0m-%d -> \x1b[1;32m%s\x1b[0m-%d\x1b[0m",
fmt.Printf("\x1b[31m%18s\x1b[0m-%s -> \x1b[1;32m%s\x1b[0m-%s\x1b[0m",
old.Version, old.Pkgrel,
new.Version, new.Pkgrel)
} else {
fmt.Printf("\x1b[0m%18s-\x1b[31m%d\x1b[0m -> %s-\x1b[32m%d\x1b[0m",
fmt.Printf("\x1b[0m%18s-\x1b[31m%s\x1b[0m -> %s-\x1b[32m%s\x1b[0m",
old.Version, old.Pkgrel,
new.Version, new.Pkgrel)
}

View File

@ -64,7 +64,7 @@ type Dependency struct {
type PKGBUILD struct {
Pkgnames []string
Pkgver Version // required
Pkgrel int // required
Pkgrel Version // required
Pkgdir string
Epoch int
Pkgbase string
@ -132,10 +132,10 @@ func (p *PKGBUILD) Older(p2 *PKGBUILD) bool {
// Version returns the full version of the PKGBUILD (including epoch and rel)
func (p *PKGBUILD) Version() string {
if p.Epoch > 0 {
return fmt.Sprintf("%d:%s-%d", p.Epoch, p.Pkgver, p.Pkgrel)
return fmt.Sprintf("%d:%s-%s", p.Epoch, p.Pkgver, p.Pkgrel)
}
return fmt.Sprintf("%s-%d", p.Pkgver, p.Pkgrel)
return fmt.Sprintf("%s-%s", p.Pkgver, p.Pkgrel)
}
// CompleteVersion returns a Complete version struct including version, rel and
@ -144,7 +144,7 @@ func (p *PKGBUILD) CompleteVersion() CompleteVersion {
return CompleteVersion{
Version: p.Pkgver,
Epoch: uint8(p.Epoch),
Pkgrel: uint8(p.Pkgrel),
Pkgrel: p.Pkgrel,
}
}
@ -257,11 +257,11 @@ Loop:
pkgbuild.Pkgver = version
case itemPkgrel:
next = lexer.nextItem()
rel, err := strconv.ParseInt(next.val, 10, 0)
rel, err := parseVersion(next.val)
if err != nil {
return nil, err
}
pkgbuild.Pkgrel = int(rel)
pkgbuild.Pkgrel = rel
case itemPkgdir:
next = lexer.nextItem()
pkgbuild.Pkgdir = next.val

View File

@ -31,9 +31,9 @@ func TestVersionParsing(t *testing.T) {
// Test complete-version parsing
func TestCompleteVersionParsing(t *testing.T) {
versions := map[string]*CompleteVersion{
"1:1.0beta": &CompleteVersion{Version("1.0beta"), 1, 0},
"1.0": &CompleteVersion{Version("1.0"), 0, 0},
"2.3-2": &CompleteVersion{Version("2.3"), 0, 2},
"1:1.0beta": &CompleteVersion{Version("1.0beta"), 1, ""},
"1.0": &CompleteVersion{Version("1.0"), 0, ""},
"2.3-2": &CompleteVersion{Version("2.3"), 0, "2"},
"1::": nil,
"4.3--1": nil,
"4.1-a": nil,
@ -60,22 +60,22 @@ func TestNewer(t *testing.T) {
a := &PKGBUILD{
Epoch: 0,
Pkgver: Version("1.0"),
Pkgrel: 1,
Pkgrel: "1",
}
b := &PKGBUILD{
Epoch: 0,
Pkgver: Version("2.0"),
Pkgrel: 1,
Pkgrel: "1",
}
c := &PKGBUILD{
Epoch: 1,
Pkgver: Version("1.0"),
Pkgrel: 1,
Pkgrel: "1",
}
d := &PKGBUILD{
Epoch: 0,
Pkgver: Version("1.0"),
Pkgrel: 2,
Pkgrel: "2",
}
if a.Newer(b) {
@ -100,22 +100,22 @@ func TestOlder(t *testing.T) {
a := &PKGBUILD{
Epoch: 0,
Pkgver: Version("1.0"),
Pkgrel: 1,
Pkgrel: "1",
}
b := &PKGBUILD{
Epoch: 0,
Pkgver: Version("2.0"),
Pkgrel: 1,
Pkgrel: "1",
}
c := &PKGBUILD{
Epoch: 1,
Pkgver: Version("1.0"),
Pkgrel: 1,
Pkgrel: "1",
}
d := &PKGBUILD{
Epoch: 0,
Pkgver: Version("1.0"),
Pkgrel: 2,
Pkgrel: "2",
}
if !a.Older(b) {
@ -140,7 +140,7 @@ func TestVersionMethod(t *testing.T) {
a := &PKGBUILD{
Epoch: 0,
Pkgver: Version("1.0"),
Pkgrel: 1,
Pkgrel: "1",
}
version := "1.0-1"
@ -152,7 +152,7 @@ func TestVersionMethod(t *testing.T) {
b := &PKGBUILD{
Epoch: 4,
Pkgver: Version("1.0"),
Pkgrel: 1,
Pkgrel: "1",
}
version = "4:1.0-1"

View File

@ -12,7 +12,7 @@ type Version string
type CompleteVersion struct {
Version Version
Epoch uint8
Pkgrel uint8
Pkgrel Version
}
func (c *CompleteVersion) String() string {
@ -24,7 +24,7 @@ func (c *CompleteVersion) String() string {
func NewCompleteVersion(s string) (*CompleteVersion, error) {
var err error
epoch := 0
rel := 0
rel := Version("")
// handle possible epoch
versions := strings.Split(s, ":")
@ -46,10 +46,7 @@ func NewCompleteVersion(s string) (*CompleteVersion, error) {
}
if len(versions) > 1 {
rel, err = strconv.Atoi(versions[1])
if err != nil {
return nil, err
}
rel = Version(versions[1])
}
// finally check that the actual version is valid
@ -57,7 +54,7 @@ func NewCompleteVersion(s string) (*CompleteVersion, error) {
return &CompleteVersion{
Version: Version(versions[0]),
Epoch: uint8(epoch),
Pkgrel: uint8(rel),
Pkgrel: rel,
}, nil
}
@ -115,11 +112,11 @@ func (a *CompleteVersion) cmp(b *CompleteVersion) int8 {
return -1
}
if a.Pkgrel > b.Pkgrel {
if a.Pkgrel.bigger(b.Pkgrel) {
return 1
}
if a.Pkgrel < b.Pkgrel {
if b.Pkgrel.bigger(a.Pkgrel) {
return -1
}

View File

@ -86,12 +86,13 @@ func TestCompleteVersionComparison(t *testing.T) {
a := &CompleteVersion{
Version: "2",
Epoch: 1,
Pkgrel: 2,
Pkgrel: Version("2"),
}
older := []string{
"0-3-4",
"1-2-1",
"1-2-1.5",
"1-1-1",
}
@ -105,6 +106,7 @@ func TestCompleteVersionComparison(t *testing.T) {
"2-1-1",
"1-3-1",
"1-2-3",
"1-2-2.1",
}
for _, n := range newer {