mirror of https://github.com/liamg/aminal.git
added version check
This commit is contained in:
parent
c60f95b880
commit
f47e47babd
|
@ -73,6 +73,12 @@
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "05fccaae8fc423476d98fd4c3e4699ba0fbbde48"
|
revision = "05fccaae8fc423476d98fd4c3e4699ba0fbbde48"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/mcuadros/go-version"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "6d5863ca60fa6fe914b5fd43ed8533d7567c5b0b"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/pkg/errors"
|
name = "github.com/pkg/errors"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
|
@ -124,6 +130,6 @@
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "d8686fe64e6699ef2d4e566a5e2a9226ab49a277e1027d9191bd31b93413c302"
|
inputs-digest = "8db8975813116b361486306a6cc003f93f2811face80fee3d2728c179d8796df"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
4
Makefile
4
Makefile
|
@ -30,12 +30,12 @@ update-fonts: install-tools
|
||||||
.PHONY: build-linux
|
.PHONY: build-linux
|
||||||
build-linux:
|
build-linux:
|
||||||
mkdir -p bin/linux
|
mkdir -p bin/linux
|
||||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o bin/linux/${BINARY}-linux-amd64 -ldflags "-X main.Version='${CIRCLE_TAG}'"
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o bin/linux/${BINARY}-linux-amd64 -ldflags "-X version.Version='${CIRCLE_TAG}'"
|
||||||
|
|
||||||
.PHONY: build-darwin
|
.PHONY: build-darwin
|
||||||
build-darwin:
|
build-darwin:
|
||||||
mkdir -p bin/darwin
|
mkdir -p bin/darwin
|
||||||
xgo -x -v -ldflags "-X main.Version='${CIRCLE_TAG}'" --targets=darwin/amd64 -out bin/darwin/${BINARY} .
|
xgo -x -v -ldflags "-X version.Version='${CIRCLE_TAG}'" --targets=darwin/amd64 -out bin/darwin/${BINARY} .
|
||||||
|
|
||||||
.PHONY: package-debian
|
.PHONY: package-debian
|
||||||
package-debian: build-linux
|
package-debian: build-linux
|
||||||
|
|
|
@ -7,10 +7,9 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/liamg/aminal/config"
|
"github.com/liamg/aminal/config"
|
||||||
|
"github.com/liamg/aminal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version string
|
|
||||||
|
|
||||||
func getConfig() *config.Config {
|
func getConfig() *config.Config {
|
||||||
|
|
||||||
showVersion := false
|
showVersion := false
|
||||||
|
@ -31,10 +30,10 @@ func getConfig() *config.Config {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if showVersion {
|
if showVersion {
|
||||||
if Version == "" {
|
if version.Version == "" {
|
||||||
Version = "development"
|
version.Version = "development"
|
||||||
}
|
}
|
||||||
fmt.Printf("Aminal %s\n", Version)
|
fmt.Printf("Aminal %s\n", version.Version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
21
gui/gui.go
21
gui/gui.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-gl/gl/all-core/gl"
|
"github.com/go-gl/gl/all-core/gl"
|
||||||
|
@ -11,6 +12,7 @@ import (
|
||||||
"github.com/liamg/aminal/buffer"
|
"github.com/liamg/aminal/buffer"
|
||||||
"github.com/liamg/aminal/config"
|
"github.com/liamg/aminal/config"
|
||||||
"github.com/liamg/aminal/terminal"
|
"github.com/liamg/aminal/terminal"
|
||||||
|
"github.com/liamg/aminal/version"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -189,6 +191,17 @@ func (gui *GUI) Render() error {
|
||||||
|
|
||||||
gui.terminal.SetProgram(program)
|
gui.terminal.SetProgram(program)
|
||||||
|
|
||||||
|
latestVersion := ""
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
r, err := version.GetNewerRelease()
|
||||||
|
if err == nil && r != nil {
|
||||||
|
latestVersion = r.TagName
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
for !gui.window.ShouldClose() {
|
for !gui.window.ShouldClose() {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@ -276,6 +289,14 @@ Buffer Size: %d lines
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if latestVersion != "" && time.Since(startTime) < time.Second*10 {
|
||||||
|
_, h := gui.terminal.GetSize()
|
||||||
|
gui.textbox(2, uint16(h-3), fmt.Sprintf("Version %s of Aminal is now available.", strings.Replace(latestVersion, "v", "", -1)),
|
||||||
|
[3]float32{1, 1, 1},
|
||||||
|
[3]float32{0, 0.5, 0},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
gui.window.SwapBuffers()
|
gui.window.SwapBuffers()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ DONE:
|
||||||
f.SetColor(fg[0], fg[1], fg[2], 1)
|
f.SetColor(fg[0], fg[1], fg[2], 1)
|
||||||
|
|
||||||
for i, line := range lines {
|
for i, line := range lines {
|
||||||
y := float32(row+1+uint16(i)) * gui.renderer.cellHeight
|
y := float32(row+1+uint16(i))*gui.renderer.cellHeight + f.MinY()
|
||||||
f.Print(x, y, fmt.Sprintf(" %s", line))
|
f.Print(x, y, fmt.Sprintf(" %s", line))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Folders
|
||||||
|
_obj
|
||||||
|
_test
|
||||||
|
|
||||||
|
# Architecture specific extensions/prefixes
|
||||||
|
*.[568vq]
|
||||||
|
[568vq].out
|
||||||
|
|
||||||
|
*.cgo1.go
|
||||||
|
*.cgo2.c
|
||||||
|
_cgo_defun.c
|
||||||
|
_cgo_gotypes.go
|
||||||
|
_cgo_export.*
|
||||||
|
|
||||||
|
_testmain.go
|
||||||
|
|
||||||
|
*.exe
|
|
@ -0,0 +1 @@
|
||||||
|
language: go
|
|
@ -0,0 +1,19 @@
|
||||||
|
Copyright (c) 2013 Máximo Cuadros
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
|
@ -0,0 +1,80 @@
|
||||||
|
go-version [](https://travis-ci.org/mcuadros/go-version) [](http://godoc.org/github.com/mcuadros/go-version)
|
||||||
|
==============================
|
||||||
|
|
||||||
|
Version normalizer and comparison library for go, heavy based on PHP version_compare function and Version comparsion libs from [Composer](https://github.com/composer/composer) PHP project
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
|
||||||
|
The recommended way to install go-version
|
||||||
|
|
||||||
|
```
|
||||||
|
go get github.com/mcuadros/go-version
|
||||||
|
```
|
||||||
|
|
||||||
|
Examples
|
||||||
|
--------
|
||||||
|
|
||||||
|
How import the package
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"github.com/mcuadros/go-version"
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
`version.Normalize()`: Normalizes a version string to be able to perform comparisons on it
|
||||||
|
|
||||||
|
```go
|
||||||
|
version.Normalize("10.4.13-b")
|
||||||
|
//Returns: 10.4.13.0-beta
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
`version.CompareSimple()`: Compares two normalizated version number strings
|
||||||
|
|
||||||
|
```go
|
||||||
|
version.CompareSimple("1.2", "1.0.1")
|
||||||
|
//Returns: 1
|
||||||
|
|
||||||
|
version.CompareSimple("1.0rc1", "1.0")
|
||||||
|
//Returns: -1
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
`version.Compare()`: Compares two normalizated version number strings, for a particular relationship
|
||||||
|
|
||||||
|
```go
|
||||||
|
version.Compare("1.0-dev", "1.0", "<")
|
||||||
|
//Returns: true
|
||||||
|
|
||||||
|
version.Compare("1.0rc1", "1.0", ">=")
|
||||||
|
//Returns: false
|
||||||
|
|
||||||
|
version.Compare("2.3.4", "v3.1.2", "<")
|
||||||
|
//Returns: true
|
||||||
|
```
|
||||||
|
|
||||||
|
`version.ConstrainGroup.Match()`: Match a given version againts a group of constrains, read about constraint string format at [Composer documentation](http://getcomposer.org/doc/01-basic-usage.md#package-versions)
|
||||||
|
|
||||||
|
```go
|
||||||
|
c := version.NewConstrainGroupFromString(">2.0,<=3.0")
|
||||||
|
c.Match("2.5.0beta")
|
||||||
|
//Returns: true
|
||||||
|
|
||||||
|
c := version.NewConstrainGroupFromString("~1.2.3")
|
||||||
|
c.Match("1.2.3.5")
|
||||||
|
//Returns: true
|
||||||
|
```
|
||||||
|
|
||||||
|
`version.Sort()`: Sorts a string slice of version number strings using version.CompareSimple()
|
||||||
|
|
||||||
|
```go
|
||||||
|
version.Sort([]string{"1.10-dev", "1.0rc1", "1.0", "1.0-dev"})
|
||||||
|
//Returns []string{"1.0-dev", "1.0rc1", "1.0", "1.10-dev"}
|
||||||
|
```
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
MIT, see [LICENSE](LICENSE)
|
|
@ -0,0 +1,171 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var regexpSigns = regexp.MustCompile(`[_\-+]`)
|
||||||
|
var regexpDotBeforeDigit = regexp.MustCompile(`([^.\d]+)`)
|
||||||
|
var regexpMultipleDots = regexp.MustCompile(`\.{2,}`)
|
||||||
|
|
||||||
|
var specialForms = map[string]int{
|
||||||
|
"dev": -6,
|
||||||
|
"alpha": -5,
|
||||||
|
"a": -5,
|
||||||
|
"beta": -4,
|
||||||
|
"b": -4,
|
||||||
|
"RC": -3,
|
||||||
|
"rc": -3,
|
||||||
|
"#": -2,
|
||||||
|
"p": 1,
|
||||||
|
"pl": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
var unknownForm int = -7
|
||||||
|
|
||||||
|
// Compares two version number strings, for a particular relationship
|
||||||
|
//
|
||||||
|
// Usage
|
||||||
|
// version.Compare("2.3.4", "v3.1.2", "<")
|
||||||
|
// Returns: true
|
||||||
|
//
|
||||||
|
// version.Compare("1.0rc1", "1.0", ">=")
|
||||||
|
// Returns: false
|
||||||
|
func Compare(version1, version2, operator string) bool {
|
||||||
|
version1N := Normalize(version1)
|
||||||
|
version2N := Normalize(version2)
|
||||||
|
|
||||||
|
return CompareNormalized(version1N, version2N, operator)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compares two normalizated version number strings, for a particular relationship
|
||||||
|
//
|
||||||
|
// The function first replaces _, - and + with a dot . in the version strings
|
||||||
|
// and also inserts dots . before and after any non number so that for example
|
||||||
|
// '4.3.2RC1' becomes '4.3.2.RC.1'.
|
||||||
|
//
|
||||||
|
// Then it splits the results like if you were using Split(version, '.').
|
||||||
|
// Then it compares the parts starting from left to right. If a part contains
|
||||||
|
// special version strings these are handled in the following order: any string
|
||||||
|
// not found in this list:
|
||||||
|
// < dev < alpha = a < beta = b < RC = rc < # < pl = p.
|
||||||
|
//
|
||||||
|
// Usage
|
||||||
|
// version.CompareNormalized("1.0-dev", "1.0", "<")
|
||||||
|
// Returns: true
|
||||||
|
//
|
||||||
|
// version.CompareNormalized("1.0rc1", "1.0", ">=")
|
||||||
|
// Returns: false
|
||||||
|
//
|
||||||
|
// version.CompareNormalized("1.0", "1.0b1", "ge")
|
||||||
|
// Returns: true
|
||||||
|
func CompareNormalized(version1, version2, operator string) bool {
|
||||||
|
compare := CompareSimple(version1, version2)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case operator == ">" || operator == "gt":
|
||||||
|
return compare > 0
|
||||||
|
case operator == ">=" || operator == "ge":
|
||||||
|
return compare >= 0
|
||||||
|
case operator == "<=" || operator == "le":
|
||||||
|
return compare <= 0
|
||||||
|
case operator == "==" || operator == "=" || operator == "eq":
|
||||||
|
return compare == 0
|
||||||
|
case operator == "<>" || operator == "!=" || operator == "ne":
|
||||||
|
return compare != 0
|
||||||
|
case operator == "" || operator == "<" || operator == "lt":
|
||||||
|
return compare < 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compares two normalizated version number strings
|
||||||
|
//
|
||||||
|
// Just the same of CompareVersion but return a int result, 0 if both version
|
||||||
|
// are equal, 1 if the right side is bigger and -1 if the right side is lower
|
||||||
|
//
|
||||||
|
// Usage
|
||||||
|
// version.CompareSimple("1.2", "1.0.1")
|
||||||
|
// Returns: 1
|
||||||
|
//
|
||||||
|
// version.CompareSimple("1.0rc1", "1.0")
|
||||||
|
// Returns: -1
|
||||||
|
func CompareSimple(version1, version2 string) int {
|
||||||
|
var x, r, l int = 0, 0, 0
|
||||||
|
|
||||||
|
v1, v2 := prepVersion(version1), prepVersion(version2)
|
||||||
|
len1, len2 := len(v1), len(v2)
|
||||||
|
|
||||||
|
if len1 > len2 {
|
||||||
|
x = len1
|
||||||
|
} else {
|
||||||
|
x = len2
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < x; i++ {
|
||||||
|
if i < len1 && i < len2 {
|
||||||
|
if v1[i] == v2[i] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r = 0
|
||||||
|
if i < len1 {
|
||||||
|
r = numVersion(v1[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
l = 0
|
||||||
|
if i < len2 {
|
||||||
|
l = numVersion(v2[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
if r < l {
|
||||||
|
return -1
|
||||||
|
} else if r > l {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func prepVersion(version string) []string {
|
||||||
|
if len(version) == 0 {
|
||||||
|
return []string{""}
|
||||||
|
}
|
||||||
|
|
||||||
|
version = regexpSigns.ReplaceAllString(version, ".")
|
||||||
|
version = regexpDotBeforeDigit.ReplaceAllString(version, ".$1.")
|
||||||
|
version = regexpMultipleDots.ReplaceAllString(version, ".")
|
||||||
|
|
||||||
|
return strings.Split(version, ".")
|
||||||
|
}
|
||||||
|
|
||||||
|
func numVersion(value string) int {
|
||||||
|
if value == "" {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if number, err := strconv.Atoi(value); err == nil {
|
||||||
|
return number
|
||||||
|
}
|
||||||
|
|
||||||
|
if special, ok := specialForms[value]; ok {
|
||||||
|
return special
|
||||||
|
}
|
||||||
|
|
||||||
|
return unknownForm
|
||||||
|
}
|
||||||
|
|
||||||
|
func ValidSimpleVersionFormat(value string) bool {
|
||||||
|
normalized := Normalize(value)
|
||||||
|
for _, component := range prepVersion(normalized) {
|
||||||
|
if numVersion(component) == unknownForm {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
|
@ -0,0 +1,842 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var prepVersionValues = map[string]string{
|
||||||
|
"1-stable": "1.stable.",
|
||||||
|
"1....0.0": "1.0.0",
|
||||||
|
"1-2_3-4": "1.2.3.4",
|
||||||
|
"1-2_3-..4-beta": "1.2.3.4.beta.",
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPrepVersion(t *testing.T) {
|
||||||
|
for in, out := range prepVersionValues {
|
||||||
|
if x := prepVersion(in); strings.Join(x, ".") != out {
|
||||||
|
t.Errorf("FAIL: Normalize(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var numVersionValues = map[string]int{
|
||||||
|
"foo": -7,
|
||||||
|
"10": 10,
|
||||||
|
"12212": 12212,
|
||||||
|
"": 0,
|
||||||
|
"dev": -6,
|
||||||
|
"alpha": -5,
|
||||||
|
"a": -5,
|
||||||
|
"beta": -4,
|
||||||
|
"b": -4,
|
||||||
|
"RC": -3,
|
||||||
|
"rc": -3,
|
||||||
|
"#": -2,
|
||||||
|
"p": 1,
|
||||||
|
"pl": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNumVersion(t *testing.T) {
|
||||||
|
for in, out := range numVersionValues {
|
||||||
|
if x := numVersion(in); x != out {
|
||||||
|
t.Errorf("FAIL: Normalize(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var compareVersionSimpleValues = map[string]int{
|
||||||
|
"1|2": -1,
|
||||||
|
"10|2": 1,
|
||||||
|
"1.0|1.1": -1,
|
||||||
|
"1.2|1.0.1": 1,
|
||||||
|
"1.0-dev|1.0-dev": 0,
|
||||||
|
"1.0-dev|1.0a1": -1,
|
||||||
|
"1.0-dev|1.0b1": -1,
|
||||||
|
"1.0-dev|1.0RC1": -1,
|
||||||
|
"1.0-dev|1.0rc1": -1,
|
||||||
|
"1.0-dev|1.0": -1,
|
||||||
|
"1.0-dev|1.0pl1": -1,
|
||||||
|
"1.0a1|1.0-dev": 1,
|
||||||
|
"1.0a1|1.0a1": 0,
|
||||||
|
"1.0a1|1.0b1": -1,
|
||||||
|
"1.0a1|1.0RC1": -1,
|
||||||
|
"1.0a1|1.0rc1": -1,
|
||||||
|
"1.0a1|1.0": -1,
|
||||||
|
"1.0a1|1.0pl1": -1,
|
||||||
|
"1.0b1|1.0-dev": 1,
|
||||||
|
"1.0b1|1.0a1": 1,
|
||||||
|
"1.0b1|1.0b1": 0,
|
||||||
|
"1.0b1|1.0RC1": -1,
|
||||||
|
"1.0b1|1.0rc1": -1,
|
||||||
|
"1.0b1|1.0": -1,
|
||||||
|
"1.0b1|1.0pl1": -1,
|
||||||
|
"1.0RC1|1.0-dev": 1,
|
||||||
|
"1.0RC1|1.0a1": 1,
|
||||||
|
"1.0RC1|1.0b1": 1,
|
||||||
|
"1.0RC1|1.0RC1": 0,
|
||||||
|
"1.0RC1|1.0rc1": 0,
|
||||||
|
"1.0RC1|1.0": -1,
|
||||||
|
"1.0RC1|1.0pl1": -1,
|
||||||
|
"1.0rc1|1.0-dev": 1,
|
||||||
|
"1.0rc1|1.0a1": 1,
|
||||||
|
"1.0rc1|1.0b1": 1,
|
||||||
|
"1.0rc1|1.0RC1": 0,
|
||||||
|
"1.0rc1|1.0rc1": 0,
|
||||||
|
"1.0rc1|1.0": -1,
|
||||||
|
"1.0rc1|1.0pl1": -1,
|
||||||
|
"1.0|1.0-dev": 1,
|
||||||
|
"1.0|1.0a1": 1,
|
||||||
|
"1.0|1.0b1": 1,
|
||||||
|
"1.0|1.0RC1": 1,
|
||||||
|
"1.0|1.0rc1": 1,
|
||||||
|
"1.0|1.0": 0,
|
||||||
|
"1.0|1.0pl1": -1,
|
||||||
|
"1.0pl1|1.0-dev": 1,
|
||||||
|
"1.0pl1|1.0a1": 1,
|
||||||
|
"1.0pl1|1.0b1": 1,
|
||||||
|
"1.0pl1|1.0RC1": 1,
|
||||||
|
"1.0pl1|1.0rc1": 1,
|
||||||
|
"1.0pl1|1.0": 1,
|
||||||
|
"1.0pl1|1.0pl1": 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompareVersionSimple(t *testing.T) {
|
||||||
|
for in, out := range compareVersionSimpleValues {
|
||||||
|
v := strings.Split(in, "|")
|
||||||
|
if x := CompareSimple(v[0], v[1]); x != out {
|
||||||
|
t.Errorf("FAIL: CompareVersionSimple(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var compareNormalizedVersionValues = map[string]bool{
|
||||||
|
"1.0-dev lt 1.0-dev": false,
|
||||||
|
"1.0-dev < 1.0-dev": false,
|
||||||
|
"1.0-dev le 1.0-dev": true,
|
||||||
|
"1.0-dev <= 1.0-dev": true,
|
||||||
|
"1.0-dev gt 1.0-dev": false,
|
||||||
|
"1.0-dev > 1.0-dev": false,
|
||||||
|
"1.0-dev ge 1.0-dev": true,
|
||||||
|
"1.0-dev >= 1.0-dev": true,
|
||||||
|
"1.0-dev eq 1.0-dev": true,
|
||||||
|
"1.0-dev = 1.0-dev": true,
|
||||||
|
"1.0-dev == 1.0-dev": true,
|
||||||
|
"1.0-dev ne 1.0-dev": false,
|
||||||
|
"1.0-dev <> 1.0-dev": false,
|
||||||
|
"1.0-dev != 1.0-dev": false,
|
||||||
|
"1.0-dev lt 1.0a1": true,
|
||||||
|
"1.0-dev < 1.0a1": true,
|
||||||
|
"1.0-dev le 1.0a1": true,
|
||||||
|
"1.0-dev <= 1.0a1": true,
|
||||||
|
"1.0-dev gt 1.0a1": false,
|
||||||
|
"1.0-dev > 1.0a1": false,
|
||||||
|
"1.0-dev ge 1.0a1": false,
|
||||||
|
"1.0-dev >= 1.0a1": false,
|
||||||
|
"1.0-dev eq 1.0a1": false,
|
||||||
|
"1.0-dev = 1.0a1": false,
|
||||||
|
"1.0-dev == 1.0a1": false,
|
||||||
|
"1.0-dev ne 1.0a1": true,
|
||||||
|
"1.0-dev <> 1.0a1": true,
|
||||||
|
"1.0-dev != 1.0a1": true,
|
||||||
|
"1.0-dev lt 1.0b1": true,
|
||||||
|
"1.0-dev < 1.0b1": true,
|
||||||
|
"1.0-dev le 1.0b1": true,
|
||||||
|
"1.0-dev <= 1.0b1": true,
|
||||||
|
"1.0-dev gt 1.0b1": false,
|
||||||
|
"1.0-dev > 1.0b1": false,
|
||||||
|
"1.0-dev ge 1.0b1": false,
|
||||||
|
"1.0-dev >= 1.0b1": false,
|
||||||
|
"1.0-dev eq 1.0b1": false,
|
||||||
|
"1.0-dev = 1.0b1": false,
|
||||||
|
"1.0-dev == 1.0b1": false,
|
||||||
|
"1.0-dev ne 1.0b1": true,
|
||||||
|
"1.0-dev <> 1.0b1": true,
|
||||||
|
"1.0-dev != 1.0b1": true,
|
||||||
|
"1.0-dev lt 1.0RC1": true,
|
||||||
|
"1.0-dev < 1.0RC1": true,
|
||||||
|
"1.0-dev le 1.0RC1": true,
|
||||||
|
"1.0-dev <= 1.0RC1": true,
|
||||||
|
"1.0-dev gt 1.0RC1": false,
|
||||||
|
"1.0-dev > 1.0RC1": false,
|
||||||
|
"1.0-dev ge 1.0RC1": false,
|
||||||
|
"1.0-dev >= 1.0RC1": false,
|
||||||
|
"1.0-dev eq 1.0RC1": false,
|
||||||
|
"1.0-dev = 1.0RC1": false,
|
||||||
|
"1.0-dev == 1.0RC1": false,
|
||||||
|
"1.0-dev ne 1.0RC1": true,
|
||||||
|
"1.0-dev <> 1.0RC1": true,
|
||||||
|
"1.0-dev != 1.0RC1": true,
|
||||||
|
"1.0-dev lt 1.0rc1": true,
|
||||||
|
"1.0-dev < 1.0rc1": true,
|
||||||
|
"1.0-dev le 1.0rc1": true,
|
||||||
|
"1.0-dev <= 1.0rc1": true,
|
||||||
|
"1.0-dev gt 1.0rc1": false,
|
||||||
|
"1.0-dev > 1.0rc1": false,
|
||||||
|
"1.0-dev ge 1.0rc1": false,
|
||||||
|
"1.0-dev >= 1.0rc1": false,
|
||||||
|
"1.0-dev eq 1.0rc1": false,
|
||||||
|
"1.0-dev = 1.0rc1": false,
|
||||||
|
"1.0-dev == 1.0rc1": false,
|
||||||
|
"1.0-dev ne 1.0rc1": true,
|
||||||
|
"1.0-dev <> 1.0rc1": true,
|
||||||
|
"1.0-dev != 1.0rc1": true,
|
||||||
|
"1.0-dev lt 1.0": true,
|
||||||
|
"1.0-dev < 1.0": true,
|
||||||
|
"1.0-dev le 1.0": true,
|
||||||
|
"1.0-dev <= 1.0": true,
|
||||||
|
"1.0-dev gt 1.0": false,
|
||||||
|
"1.0-dev > 1.0": false,
|
||||||
|
"1.0-dev ge 1.0": false,
|
||||||
|
"1.0-dev >= 1.0": false,
|
||||||
|
"1.0-dev eq 1.0": false,
|
||||||
|
"1.0-dev = 1.0": false,
|
||||||
|
"1.0-dev == 1.0": false,
|
||||||
|
"1.0-dev ne 1.0": true,
|
||||||
|
"1.0-dev <> 1.0": true,
|
||||||
|
"1.0-dev != 1.0": true,
|
||||||
|
"1.0-dev lt 1.0pl1": true,
|
||||||
|
"1.0-dev < 1.0pl1": true,
|
||||||
|
"1.0-dev le 1.0pl1": true,
|
||||||
|
"1.0-dev <= 1.0pl1": true,
|
||||||
|
"1.0-dev gt 1.0pl1": false,
|
||||||
|
"1.0-dev > 1.0pl1": false,
|
||||||
|
"1.0-dev ge 1.0pl1": false,
|
||||||
|
"1.0-dev >= 1.0pl1": false,
|
||||||
|
"1.0-dev eq 1.0pl1": false,
|
||||||
|
"1.0-dev = 1.0pl1": false,
|
||||||
|
"1.0-dev == 1.0pl1": false,
|
||||||
|
"1.0-dev ne 1.0pl1": true,
|
||||||
|
"1.0-dev <> 1.0pl1": true,
|
||||||
|
"1.0-dev != 1.0pl1": true,
|
||||||
|
"1.0a1 lt 1.0-dev": false,
|
||||||
|
"1.0a1 < 1.0-dev": false,
|
||||||
|
"1.0a1 le 1.0-dev": false,
|
||||||
|
"1.0a1 <= 1.0-dev": false,
|
||||||
|
"1.0a1 gt 1.0-dev": true,
|
||||||
|
"1.0a1 > 1.0-dev": true,
|
||||||
|
"1.0a1 ge 1.0-dev": true,
|
||||||
|
"1.0a1 >= 1.0-dev": true,
|
||||||
|
"1.0a1 eq 1.0-dev": false,
|
||||||
|
"1.0a1 = 1.0-dev": false,
|
||||||
|
"1.0a1 == 1.0-dev": false,
|
||||||
|
"1.0a1 ne 1.0-dev": true,
|
||||||
|
"1.0a1 <> 1.0-dev": true,
|
||||||
|
"1.0a1 != 1.0-dev": true,
|
||||||
|
"1.0a1 lt 1.0a1": false,
|
||||||
|
"1.0a1 < 1.0a1": false,
|
||||||
|
"1.0a1 le 1.0a1": true,
|
||||||
|
"1.0a1 <= 1.0a1": true,
|
||||||
|
"1.0a1 gt 1.0a1": false,
|
||||||
|
"1.0a1 > 1.0a1": false,
|
||||||
|
"1.0a1 ge 1.0a1": true,
|
||||||
|
"1.0a1 >= 1.0a1": true,
|
||||||
|
"1.0a1 eq 1.0a1": true,
|
||||||
|
"1.0a1 = 1.0a1": true,
|
||||||
|
"1.0a1 == 1.0a1": true,
|
||||||
|
"1.0a1 ne 1.0a1": false,
|
||||||
|
"1.0a1 <> 1.0a1": false,
|
||||||
|
"1.0a1 != 1.0a1": false,
|
||||||
|
"1.0a1 lt 1.0b1": true,
|
||||||
|
"1.0a1 < 1.0b1": true,
|
||||||
|
"1.0a1 le 1.0b1": true,
|
||||||
|
"1.0a1 <= 1.0b1": true,
|
||||||
|
"1.0a1 gt 1.0b1": false,
|
||||||
|
"1.0a1 > 1.0b1": false,
|
||||||
|
"1.0a1 ge 1.0b1": false,
|
||||||
|
"1.0a1 >= 1.0b1": false,
|
||||||
|
"1.0a1 eq 1.0b1": false,
|
||||||
|
"1.0a1 = 1.0b1": false,
|
||||||
|
"1.0a1 == 1.0b1": false,
|
||||||
|
"1.0a1 ne 1.0b1": true,
|
||||||
|
"1.0a1 <> 1.0b1": true,
|
||||||
|
"1.0a1 != 1.0b1": true,
|
||||||
|
"1.0a1 lt 1.0RC1": true,
|
||||||
|
"1.0a1 < 1.0RC1": true,
|
||||||
|
"1.0a1 le 1.0RC1": true,
|
||||||
|
"1.0a1 <= 1.0RC1": true,
|
||||||
|
"1.0a1 gt 1.0RC1": false,
|
||||||
|
"1.0a1 > 1.0RC1": false,
|
||||||
|
"1.0a1 ge 1.0RC1": false,
|
||||||
|
"1.0a1 >= 1.0RC1": false,
|
||||||
|
"1.0a1 eq 1.0RC1": false,
|
||||||
|
"1.0a1 = 1.0RC1": false,
|
||||||
|
"1.0a1 == 1.0RC1": false,
|
||||||
|
"1.0a1 ne 1.0RC1": true,
|
||||||
|
"1.0a1 <> 1.0RC1": true,
|
||||||
|
"1.0a1 != 1.0RC1": true,
|
||||||
|
"1.0a1 lt 1.0rc1": true,
|
||||||
|
"1.0a1 < 1.0rc1": true,
|
||||||
|
"1.0a1 le 1.0rc1": true,
|
||||||
|
"1.0a1 <= 1.0rc1": true,
|
||||||
|
"1.0a1 gt 1.0rc1": false,
|
||||||
|
"1.0a1 > 1.0rc1": false,
|
||||||
|
"1.0a1 ge 1.0rc1": false,
|
||||||
|
"1.0a1 >= 1.0rc1": false,
|
||||||
|
"1.0a1 eq 1.0rc1": false,
|
||||||
|
"1.0a1 = 1.0rc1": false,
|
||||||
|
"1.0a1 == 1.0rc1": false,
|
||||||
|
"1.0a1 ne 1.0rc1": true,
|
||||||
|
"1.0a1 <> 1.0rc1": true,
|
||||||
|
"1.0a1 != 1.0rc1": true,
|
||||||
|
"1.0a1 lt 1.0": true,
|
||||||
|
"1.0a1 < 1.0": true,
|
||||||
|
"1.0a1 le 1.0": true,
|
||||||
|
"1.0a1 <= 1.0": true,
|
||||||
|
"1.0a1 gt 1.0": false,
|
||||||
|
"1.0a1 > 1.0": false,
|
||||||
|
"1.0a1 ge 1.0": false,
|
||||||
|
"1.0a1 >= 1.0": false,
|
||||||
|
"1.0a1 eq 1.0": false,
|
||||||
|
"1.0a1 = 1.0": false,
|
||||||
|
"1.0a1 == 1.0": false,
|
||||||
|
"1.0a1 ne 1.0": true,
|
||||||
|
"1.0a1 <> 1.0": true,
|
||||||
|
"1.0a1 != 1.0": true,
|
||||||
|
"1.0a1 lt 1.0pl1": true,
|
||||||
|
"1.0a1 < 1.0pl1": true,
|
||||||
|
"1.0a1 le 1.0pl1": true,
|
||||||
|
"1.0a1 <= 1.0pl1": true,
|
||||||
|
"1.0a1 gt 1.0pl1": false,
|
||||||
|
"1.0a1 > 1.0pl1": false,
|
||||||
|
"1.0a1 ge 1.0pl1": false,
|
||||||
|
"1.0a1 >= 1.0pl1": false,
|
||||||
|
"1.0a1 eq 1.0pl1": false,
|
||||||
|
"1.0a1 = 1.0pl1": false,
|
||||||
|
"1.0a1 == 1.0pl1": false,
|
||||||
|
"1.0a1 ne 1.0pl1": true,
|
||||||
|
"1.0a1 <> 1.0pl1": true,
|
||||||
|
"1.0a1 != 1.0pl1": true,
|
||||||
|
"1.0b1 lt 1.0-dev": false,
|
||||||
|
"1.0b1 < 1.0-dev": false,
|
||||||
|
"1.0b1 le 1.0-dev": false,
|
||||||
|
"1.0b1 <= 1.0-dev": false,
|
||||||
|
"1.0b1 gt 1.0-dev": true,
|
||||||
|
"1.0b1 > 1.0-dev": true,
|
||||||
|
"1.0b1 ge 1.0-dev": true,
|
||||||
|
"1.0b1 >= 1.0-dev": true,
|
||||||
|
"1.0b1 eq 1.0-dev": false,
|
||||||
|
"1.0b1 = 1.0-dev": false,
|
||||||
|
"1.0b1 == 1.0-dev": false,
|
||||||
|
"1.0b1 ne 1.0-dev": true,
|
||||||
|
"1.0b1 <> 1.0-dev": true,
|
||||||
|
"1.0b1 != 1.0-dev": true,
|
||||||
|
"1.0b1 lt 1.0a1": false,
|
||||||
|
"1.0b1 < 1.0a1": false,
|
||||||
|
"1.0b1 le 1.0a1": false,
|
||||||
|
"1.0b1 <= 1.0a1": false,
|
||||||
|
"1.0b1 gt 1.0a1": true,
|
||||||
|
"1.0b1 > 1.0a1": true,
|
||||||
|
"1.0b1 ge 1.0a1": true,
|
||||||
|
"1.0b1 >= 1.0a1": true,
|
||||||
|
"1.0b1 eq 1.0a1": false,
|
||||||
|
"1.0b1 = 1.0a1": false,
|
||||||
|
"1.0b1 == 1.0a1": false,
|
||||||
|
"1.0b1 ne 1.0a1": true,
|
||||||
|
"1.0b1 <> 1.0a1": true,
|
||||||
|
"1.0b1 != 1.0a1": true,
|
||||||
|
"1.0b1 lt 1.0b1": false,
|
||||||
|
"1.0b1 < 1.0b1": false,
|
||||||
|
"1.0b1 le 1.0b1": true,
|
||||||
|
"1.0b1 <= 1.0b1": true,
|
||||||
|
"1.0b1 gt 1.0b1": false,
|
||||||
|
"1.0b1 > 1.0b1": false,
|
||||||
|
"1.0b1 ge 1.0b1": true,
|
||||||
|
"1.0b1 >= 1.0b1": true,
|
||||||
|
"1.0b1 eq 1.0b1": true,
|
||||||
|
"1.0b1 = 1.0b1": true,
|
||||||
|
"1.0b1 == 1.0b1": true,
|
||||||
|
"1.0b1 ne 1.0b1": false,
|
||||||
|
"1.0b1 <> 1.0b1": false,
|
||||||
|
"1.0b1 != 1.0b1": false,
|
||||||
|
"1.0b1 lt 1.0RC1": true,
|
||||||
|
"1.0b1 < 1.0RC1": true,
|
||||||
|
"1.0b1 le 1.0RC1": true,
|
||||||
|
"1.0b1 <= 1.0RC1": true,
|
||||||
|
"1.0b1 gt 1.0RC1": false,
|
||||||
|
"1.0b1 > 1.0RC1": false,
|
||||||
|
"1.0b1 ge 1.0RC1": false,
|
||||||
|
"1.0b1 >= 1.0RC1": false,
|
||||||
|
"1.0b1 eq 1.0RC1": false,
|
||||||
|
"1.0b1 = 1.0RC1": false,
|
||||||
|
"1.0b1 == 1.0RC1": false,
|
||||||
|
"1.0b1 ne 1.0RC1": true,
|
||||||
|
"1.0b1 <> 1.0RC1": true,
|
||||||
|
"1.0b1 != 1.0RC1": true,
|
||||||
|
"1.0b1 lt 1.0rc1": true,
|
||||||
|
"1.0b1 < 1.0rc1": true,
|
||||||
|
"1.0b1 le 1.0rc1": true,
|
||||||
|
"1.0b1 <= 1.0rc1": true,
|
||||||
|
"1.0b1 gt 1.0rc1": false,
|
||||||
|
"1.0b1 > 1.0rc1": false,
|
||||||
|
"1.0b1 ge 1.0rc1": false,
|
||||||
|
"1.0b1 >= 1.0rc1": false,
|
||||||
|
"1.0b1 eq 1.0rc1": false,
|
||||||
|
"1.0b1 = 1.0rc1": false,
|
||||||
|
"1.0b1 == 1.0rc1": false,
|
||||||
|
"1.0b1 ne 1.0rc1": true,
|
||||||
|
"1.0b1 <> 1.0rc1": true,
|
||||||
|
"1.0b1 != 1.0rc1": true,
|
||||||
|
"1.0b1 lt 1.0": true,
|
||||||
|
"1.0b1 < 1.0": true,
|
||||||
|
"1.0b1 le 1.0": true,
|
||||||
|
"1.0b1 <= 1.0": true,
|
||||||
|
"1.0b1 gt 1.0": false,
|
||||||
|
"1.0b1 > 1.0": false,
|
||||||
|
"1.0b1 ge 1.0": false,
|
||||||
|
"1.0b1 >= 1.0": false,
|
||||||
|
"1.0b1 eq 1.0": false,
|
||||||
|
"1.0b1 = 1.0": false,
|
||||||
|
"1.0b1 == 1.0": false,
|
||||||
|
"1.0b1 ne 1.0": true,
|
||||||
|
"1.0b1 <> 1.0": true,
|
||||||
|
"1.0b1 != 1.0": true,
|
||||||
|
"1.0b1 lt 1.0pl1": true,
|
||||||
|
"1.0b1 < 1.0pl1": true,
|
||||||
|
"1.0b1 le 1.0pl1": true,
|
||||||
|
"1.0b1 <= 1.0pl1": true,
|
||||||
|
"1.0b1 gt 1.0pl1": false,
|
||||||
|
"1.0b1 > 1.0pl1": false,
|
||||||
|
"1.0b1 ge 1.0pl1": false,
|
||||||
|
"1.0b1 >= 1.0pl1": false,
|
||||||
|
"1.0b1 eq 1.0pl1": false,
|
||||||
|
"1.0b1 = 1.0pl1": false,
|
||||||
|
"1.0b1 == 1.0pl1": false,
|
||||||
|
"1.0b1 ne 1.0pl1": true,
|
||||||
|
"1.0b1 <> 1.0pl1": true,
|
||||||
|
"1.0b1 != 1.0pl1": true,
|
||||||
|
"1.0RC1 lt 1.0-dev": false,
|
||||||
|
"1.0RC1 < 1.0-dev": false,
|
||||||
|
"1.0RC1 le 1.0-dev": false,
|
||||||
|
"1.0RC1 <= 1.0-dev": false,
|
||||||
|
"1.0RC1 gt 1.0-dev": true,
|
||||||
|
"1.0RC1 > 1.0-dev": true,
|
||||||
|
"1.0RC1 ge 1.0-dev": true,
|
||||||
|
"1.0RC1 >= 1.0-dev": true,
|
||||||
|
"1.0RC1 eq 1.0-dev": false,
|
||||||
|
"1.0RC1 = 1.0-dev": false,
|
||||||
|
"1.0RC1 == 1.0-dev": false,
|
||||||
|
"1.0RC1 ne 1.0-dev": true,
|
||||||
|
"1.0RC1 <> 1.0-dev": true,
|
||||||
|
"1.0RC1 != 1.0-dev": true,
|
||||||
|
"1.0RC1 lt 1.0a1": false,
|
||||||
|
"1.0RC1 < 1.0a1": false,
|
||||||
|
"1.0RC1 le 1.0a1": false,
|
||||||
|
"1.0RC1 <= 1.0a1": false,
|
||||||
|
"1.0RC1 gt 1.0a1": true,
|
||||||
|
"1.0RC1 > 1.0a1": true,
|
||||||
|
"1.0RC1 ge 1.0a1": true,
|
||||||
|
"1.0RC1 >= 1.0a1": true,
|
||||||
|
"1.0RC1 eq 1.0a1": false,
|
||||||
|
"1.0RC1 = 1.0a1": false,
|
||||||
|
"1.0RC1 == 1.0a1": false,
|
||||||
|
"1.0RC1 ne 1.0a1": true,
|
||||||
|
"1.0RC1 <> 1.0a1": true,
|
||||||
|
"1.0RC1 != 1.0a1": true,
|
||||||
|
"1.0RC1 lt 1.0b1": false,
|
||||||
|
"1.0RC1 < 1.0b1": false,
|
||||||
|
"1.0RC1 le 1.0b1": false,
|
||||||
|
"1.0RC1 <= 1.0b1": false,
|
||||||
|
"1.0RC1 gt 1.0b1": true,
|
||||||
|
"1.0RC1 > 1.0b1": true,
|
||||||
|
"1.0RC1 ge 1.0b1": true,
|
||||||
|
"1.0RC1 >= 1.0b1": true,
|
||||||
|
"1.0RC1 eq 1.0b1": false,
|
||||||
|
"1.0RC1 = 1.0b1": false,
|
||||||
|
"1.0RC1 == 1.0b1": false,
|
||||||
|
"1.0RC1 ne 1.0b1": true,
|
||||||
|
"1.0RC1 <> 1.0b1": true,
|
||||||
|
"1.0RC1 != 1.0b1": true,
|
||||||
|
"1.0RC1 lt 1.0RC1": false,
|
||||||
|
"1.0RC1 < 1.0RC1": false,
|
||||||
|
"1.0RC1 le 1.0RC1": true,
|
||||||
|
"1.0RC1 <= 1.0RC1": true,
|
||||||
|
"1.0RC1 gt 1.0RC1": false,
|
||||||
|
"1.0RC1 > 1.0RC1": false,
|
||||||
|
"1.0RC1 ge 1.0RC1": true,
|
||||||
|
"1.0RC1 >= 1.0RC1": true,
|
||||||
|
"1.0RC1 eq 1.0RC1": true,
|
||||||
|
"1.0RC1 = 1.0RC1": true,
|
||||||
|
"1.0RC1 == 1.0RC1": true,
|
||||||
|
"1.0RC1 ne 1.0RC1": false,
|
||||||
|
"1.0RC1 <> 1.0RC1": false,
|
||||||
|
"1.0RC1 != 1.0RC1": false,
|
||||||
|
"1.0RC1 lt 1.0rc1": false,
|
||||||
|
"1.0RC1 < 1.0rc1": false,
|
||||||
|
"1.0RC1 le 1.0rc1": true,
|
||||||
|
"1.0RC1 <= 1.0rc1": true,
|
||||||
|
"1.0RC1 gt 1.0rc1": false,
|
||||||
|
"1.0RC1 > 1.0rc1": false,
|
||||||
|
"1.0RC1 ge 1.0rc1": true,
|
||||||
|
"1.0RC1 >= 1.0rc1": true,
|
||||||
|
"1.0RC1 eq 1.0rc1": true,
|
||||||
|
"1.0RC1 = 1.0rc1": true,
|
||||||
|
"1.0RC1 == 1.0rc1": true,
|
||||||
|
"1.0RC1 ne 1.0rc1": false,
|
||||||
|
"1.0RC1 <> 1.0rc1": false,
|
||||||
|
"1.0RC1 != 1.0rc1": false,
|
||||||
|
"1.0RC1 lt 1.0": true,
|
||||||
|
"1.0RC1 < 1.0": true,
|
||||||
|
"1.0RC1 le 1.0": true,
|
||||||
|
"1.0RC1 <= 1.0": true,
|
||||||
|
"1.0RC1 gt 1.0": false,
|
||||||
|
"1.0RC1 > 1.0": false,
|
||||||
|
"1.0RC1 ge 1.0": false,
|
||||||
|
"1.0RC1 >= 1.0": false,
|
||||||
|
"1.0RC1 eq 1.0": false,
|
||||||
|
"1.0RC1 = 1.0": false,
|
||||||
|
"1.0RC1 == 1.0": false,
|
||||||
|
"1.0RC1 ne 1.0": true,
|
||||||
|
"1.0RC1 <> 1.0": true,
|
||||||
|
"1.0RC1 != 1.0": true,
|
||||||
|
"1.0RC1 lt 1.0pl1": true,
|
||||||
|
"1.0RC1 < 1.0pl1": true,
|
||||||
|
"1.0RC1 le 1.0pl1": true,
|
||||||
|
"1.0RC1 <= 1.0pl1": true,
|
||||||
|
"1.0RC1 gt 1.0pl1": false,
|
||||||
|
"1.0RC1 > 1.0pl1": false,
|
||||||
|
"1.0RC1 ge 1.0pl1": false,
|
||||||
|
"1.0RC1 >= 1.0pl1": false,
|
||||||
|
"1.0RC1 eq 1.0pl1": false,
|
||||||
|
"1.0RC1 = 1.0pl1": false,
|
||||||
|
"1.0RC1 == 1.0pl1": false,
|
||||||
|
"1.0RC1 ne 1.0pl1": true,
|
||||||
|
"1.0RC1 <> 1.0pl1": true,
|
||||||
|
"1.0RC1 != 1.0pl1": true,
|
||||||
|
"1.0rc1 lt 1.0-dev": false,
|
||||||
|
"1.0rc1 < 1.0-dev": false,
|
||||||
|
"1.0rc1 le 1.0-dev": false,
|
||||||
|
"1.0rc1 <= 1.0-dev": false,
|
||||||
|
"1.0rc1 gt 1.0-dev": true,
|
||||||
|
"1.0rc1 > 1.0-dev": true,
|
||||||
|
"1.0rc1 ge 1.0-dev": true,
|
||||||
|
"1.0rc1 >= 1.0-dev": true,
|
||||||
|
"1.0rc1 eq 1.0-dev": false,
|
||||||
|
"1.0rc1 = 1.0-dev": false,
|
||||||
|
"1.0rc1 == 1.0-dev": false,
|
||||||
|
"1.0rc1 ne 1.0-dev": true,
|
||||||
|
"1.0rc1 <> 1.0-dev": true,
|
||||||
|
"1.0rc1 != 1.0-dev": true,
|
||||||
|
"1.0rc1 lt 1.0a1": false,
|
||||||
|
"1.0rc1 < 1.0a1": false,
|
||||||
|
"1.0rc1 le 1.0a1": false,
|
||||||
|
"1.0rc1 <= 1.0a1": false,
|
||||||
|
"1.0rc1 gt 1.0a1": true,
|
||||||
|
"1.0rc1 > 1.0a1": true,
|
||||||
|
"1.0rc1 ge 1.0a1": true,
|
||||||
|
"1.0rc1 >= 1.0a1": true,
|
||||||
|
"1.0rc1 eq 1.0a1": false,
|
||||||
|
"1.0rc1 = 1.0a1": false,
|
||||||
|
"1.0rc1 == 1.0a1": false,
|
||||||
|
"1.0rc1 ne 1.0a1": true,
|
||||||
|
"1.0rc1 <> 1.0a1": true,
|
||||||
|
"1.0rc1 != 1.0a1": true,
|
||||||
|
"1.0rc1 lt 1.0b1": false,
|
||||||
|
"1.0rc1 < 1.0b1": false,
|
||||||
|
"1.0rc1 le 1.0b1": false,
|
||||||
|
"1.0rc1 <= 1.0b1": false,
|
||||||
|
"1.0rc1 gt 1.0b1": true,
|
||||||
|
"1.0rc1 > 1.0b1": true,
|
||||||
|
"1.0rc1 ge 1.0b1": true,
|
||||||
|
"1.0rc1 >= 1.0b1": true,
|
||||||
|
"1.0rc1 eq 1.0b1": false,
|
||||||
|
"1.0rc1 = 1.0b1": false,
|
||||||
|
"1.0rc1 == 1.0b1": false,
|
||||||
|
"1.0rc1 ne 1.0b1": true,
|
||||||
|
"1.0rc1 <> 1.0b1": true,
|
||||||
|
"1.0rc1 != 1.0b1": true,
|
||||||
|
"1.0rc1 lt 1.0RC1": false,
|
||||||
|
"1.0rc1 < 1.0RC1": false,
|
||||||
|
"1.0rc1 le 1.0RC1": true,
|
||||||
|
"1.0rc1 <= 1.0RC1": true,
|
||||||
|
"1.0rc1 gt 1.0RC1": false,
|
||||||
|
"1.0rc1 > 1.0RC1": false,
|
||||||
|
"1.0rc1 ge 1.0RC1": true,
|
||||||
|
"1.0rc1 >= 1.0RC1": true,
|
||||||
|
"1.0rc1 eq 1.0RC1": true,
|
||||||
|
"1.0rc1 = 1.0RC1": true,
|
||||||
|
"1.0rc1 == 1.0RC1": true,
|
||||||
|
"1.0rc1 ne 1.0RC1": false,
|
||||||
|
"1.0rc1 <> 1.0RC1": false,
|
||||||
|
"1.0rc1 != 1.0RC1": false,
|
||||||
|
"1.0rc1 lt 1.0rc1": false,
|
||||||
|
"1.0rc1 < 1.0rc1": false,
|
||||||
|
"1.0rc1 le 1.0rc1": true,
|
||||||
|
"1.0rc1 <= 1.0rc1": true,
|
||||||
|
"1.0rc1 gt 1.0rc1": false,
|
||||||
|
"1.0rc1 > 1.0rc1": false,
|
||||||
|
"1.0rc1 ge 1.0rc1": true,
|
||||||
|
"1.0rc1 >= 1.0rc1": true,
|
||||||
|
"1.0rc1 eq 1.0rc1": true,
|
||||||
|
"1.0rc1 = 1.0rc1": true,
|
||||||
|
"1.0rc1 == 1.0rc1": true,
|
||||||
|
"1.0rc1 ne 1.0rc1": false,
|
||||||
|
"1.0rc1 <> 1.0rc1": false,
|
||||||
|
"1.0rc1 != 1.0rc1": false,
|
||||||
|
"1.0rc1 lt 1.0": true,
|
||||||
|
"1.0rc1 < 1.0": true,
|
||||||
|
"1.0rc1 le 1.0": true,
|
||||||
|
"1.0rc1 <= 1.0": true,
|
||||||
|
"1.0rc1 gt 1.0": false,
|
||||||
|
"1.0rc1 > 1.0": false,
|
||||||
|
"1.0rc1 ge 1.0": false,
|
||||||
|
"1.0rc1 >= 1.0": false,
|
||||||
|
"1.0rc1 eq 1.0": false,
|
||||||
|
"1.0rc1 = 1.0": false,
|
||||||
|
"1.0rc1 == 1.0": false,
|
||||||
|
"1.0rc1 ne 1.0": true,
|
||||||
|
"1.0rc1 <> 1.0": true,
|
||||||
|
"1.0rc1 != 1.0": true,
|
||||||
|
"1.0rc1 lt 1.0pl1": true,
|
||||||
|
"1.0rc1 < 1.0pl1": true,
|
||||||
|
"1.0rc1 le 1.0pl1": true,
|
||||||
|
"1.0rc1 <= 1.0pl1": true,
|
||||||
|
"1.0rc1 gt 1.0pl1": false,
|
||||||
|
"1.0rc1 > 1.0pl1": false,
|
||||||
|
"1.0rc1 ge 1.0pl1": false,
|
||||||
|
"1.0rc1 >= 1.0pl1": false,
|
||||||
|
"1.0rc1 eq 1.0pl1": false,
|
||||||
|
"1.0rc1 = 1.0pl1": false,
|
||||||
|
"1.0rc1 == 1.0pl1": false,
|
||||||
|
"1.0rc1 ne 1.0pl1": true,
|
||||||
|
"1.0rc1 <> 1.0pl1": true,
|
||||||
|
"1.0rc1 != 1.0pl1": true,
|
||||||
|
"1.0 lt 1.0-dev": false,
|
||||||
|
"1.0 < 1.0-dev": false,
|
||||||
|
"1.0 le 1.0-dev": false,
|
||||||
|
"1.0 <= 1.0-dev": false,
|
||||||
|
"1.0 gt 1.0-dev": true,
|
||||||
|
"1.0 > 1.0-dev": true,
|
||||||
|
"1.0 ge 1.0-dev": true,
|
||||||
|
"1.0 >= 1.0-dev": true,
|
||||||
|
"1.0 eq 1.0-dev": false,
|
||||||
|
"1.0 = 1.0-dev": false,
|
||||||
|
"1.0 == 1.0-dev": false,
|
||||||
|
"1.0 ne 1.0-dev": true,
|
||||||
|
"1.0 <> 1.0-dev": true,
|
||||||
|
"1.0 != 1.0-dev": true,
|
||||||
|
"1.0 lt 1.0a1": false,
|
||||||
|
"1.0 < 1.0a1": false,
|
||||||
|
"1.0 le 1.0a1": false,
|
||||||
|
"1.0 <= 1.0a1": false,
|
||||||
|
"1.0 gt 1.0a1": true,
|
||||||
|
"1.0 > 1.0a1": true,
|
||||||
|
"1.0 ge 1.0a1": true,
|
||||||
|
"1.0 >= 1.0a1": true,
|
||||||
|
"1.0 eq 1.0a1": false,
|
||||||
|
"1.0 = 1.0a1": false,
|
||||||
|
"1.0 == 1.0a1": false,
|
||||||
|
"1.0 ne 1.0a1": true,
|
||||||
|
"1.0 <> 1.0a1": true,
|
||||||
|
"1.0 != 1.0a1": true,
|
||||||
|
"1.0 lt 1.0b1": false,
|
||||||
|
"1.0 < 1.0b1": false,
|
||||||
|
"1.0 le 1.0b1": false,
|
||||||
|
"1.0 <= 1.0b1": false,
|
||||||
|
"1.0 gt 1.0b1": true,
|
||||||
|
"1.0 > 1.0b1": true,
|
||||||
|
"1.0 ge 1.0b1": true,
|
||||||
|
"1.0 >= 1.0b1": true,
|
||||||
|
"1.0 eq 1.0b1": false,
|
||||||
|
"1.0 = 1.0b1": false,
|
||||||
|
"1.0 == 1.0b1": false,
|
||||||
|
"1.0 ne 1.0b1": true,
|
||||||
|
"1.0 <> 1.0b1": true,
|
||||||
|
"1.0 != 1.0b1": true,
|
||||||
|
"1.0 lt 1.0RC1": false,
|
||||||
|
"1.0 < 1.0RC1": false,
|
||||||
|
"1.0 le 1.0RC1": false,
|
||||||
|
"1.0 <= 1.0RC1": false,
|
||||||
|
"1.0 gt 1.0RC1": true,
|
||||||
|
"1.0 > 1.0RC1": true,
|
||||||
|
"1.0 ge 1.0RC1": true,
|
||||||
|
"1.0 >= 1.0RC1": true,
|
||||||
|
"1.0 eq 1.0RC1": false,
|
||||||
|
"1.0 = 1.0RC1": false,
|
||||||
|
"1.0 == 1.0RC1": false,
|
||||||
|
"1.0 ne 1.0RC1": true,
|
||||||
|
"1.0 <> 1.0RC1": true,
|
||||||
|
"1.0 != 1.0RC1": true,
|
||||||
|
"1.0 lt 1.0rc1": false,
|
||||||
|
"1.0 < 1.0rc1": false,
|
||||||
|
"1.0 le 1.0rc1": false,
|
||||||
|
"1.0 <= 1.0rc1": false,
|
||||||
|
"1.0 gt 1.0rc1": true,
|
||||||
|
"1.0 > 1.0rc1": true,
|
||||||
|
"1.0 ge 1.0rc1": true,
|
||||||
|
"1.0 >= 1.0rc1": true,
|
||||||
|
"1.0 eq 1.0rc1": false,
|
||||||
|
"1.0 = 1.0rc1": false,
|
||||||
|
"1.0 == 1.0rc1": false,
|
||||||
|
"1.0 ne 1.0rc1": true,
|
||||||
|
"1.0 <> 1.0rc1": true,
|
||||||
|
"1.0 != 1.0rc1": true,
|
||||||
|
"1.0 lt 1.0": false,
|
||||||
|
"1.0 < 1.0": false,
|
||||||
|
"1.0 le 1.0": true,
|
||||||
|
"1.0 <= 1.0": true,
|
||||||
|
"1.0 gt 1.0": false,
|
||||||
|
"1.0 > 1.0": false,
|
||||||
|
"1.0 ge 1.0": true,
|
||||||
|
"1.0 >= 1.0": true,
|
||||||
|
"1.0 eq 1.0": true,
|
||||||
|
"1.0 = 1.0": true,
|
||||||
|
"1.0 == 1.0": true,
|
||||||
|
"1.0 ne 1.0": false,
|
||||||
|
"1.0 <> 1.0": false,
|
||||||
|
"1.0 != 1.0": false,
|
||||||
|
"1.0 lt 1.0pl1": true,
|
||||||
|
"1.0 < 1.0pl1": true,
|
||||||
|
"1.0 le 1.0pl1": true,
|
||||||
|
"1.0 <= 1.0pl1": true,
|
||||||
|
"1.0 gt 1.0pl1": false,
|
||||||
|
"1.0 > 1.0pl1": false,
|
||||||
|
"1.0 ge 1.0pl1": false,
|
||||||
|
"1.0 >= 1.0pl1": false,
|
||||||
|
"1.0 eq 1.0pl1": false,
|
||||||
|
"1.0 = 1.0pl1": false,
|
||||||
|
"1.0 == 1.0pl1": false,
|
||||||
|
"1.0 ne 1.0pl1": true,
|
||||||
|
"1.0 <> 1.0pl1": true,
|
||||||
|
"1.0 != 1.0pl1": true,
|
||||||
|
"1.0pl1 lt 1.0-dev": false,
|
||||||
|
"1.0pl1 < 1.0-dev": false,
|
||||||
|
"1.0pl1 le 1.0-dev": false,
|
||||||
|
"1.0pl1 <= 1.0-dev": false,
|
||||||
|
"1.0pl1 gt 1.0-dev": true,
|
||||||
|
"1.0pl1 > 1.0-dev": true,
|
||||||
|
"1.0pl1 ge 1.0-dev": true,
|
||||||
|
"1.0pl1 >= 1.0-dev": true,
|
||||||
|
"1.0pl1 eq 1.0-dev": false,
|
||||||
|
"1.0pl1 = 1.0-dev": false,
|
||||||
|
"1.0pl1 == 1.0-dev": false,
|
||||||
|
"1.0pl1 ne 1.0-dev": true,
|
||||||
|
"1.0pl1 <> 1.0-dev": true,
|
||||||
|
"1.0pl1 != 1.0-dev": true,
|
||||||
|
"1.0pl1 lt 1.0a1": false,
|
||||||
|
"1.0pl1 < 1.0a1": false,
|
||||||
|
"1.0pl1 le 1.0a1": false,
|
||||||
|
"1.0pl1 <= 1.0a1": false,
|
||||||
|
"1.0pl1 gt 1.0a1": true,
|
||||||
|
"1.0pl1 > 1.0a1": true,
|
||||||
|
"1.0pl1 ge 1.0a1": true,
|
||||||
|
"1.0pl1 >= 1.0a1": true,
|
||||||
|
"1.0pl1 eq 1.0a1": false,
|
||||||
|
"1.0pl1 = 1.0a1": false,
|
||||||
|
"1.0pl1 == 1.0a1": false,
|
||||||
|
"1.0pl1 ne 1.0a1": true,
|
||||||
|
"1.0pl1 <> 1.0a1": true,
|
||||||
|
"1.0pl1 != 1.0a1": true,
|
||||||
|
"1.0pl1 lt 1.0b1": false,
|
||||||
|
"1.0pl1 < 1.0b1": false,
|
||||||
|
"1.0pl1 le 1.0b1": false,
|
||||||
|
"1.0pl1 <= 1.0b1": false,
|
||||||
|
"1.0pl1 gt 1.0b1": true,
|
||||||
|
"1.0pl1 > 1.0b1": true,
|
||||||
|
"1.0pl1 ge 1.0b1": true,
|
||||||
|
"1.0pl1 >= 1.0b1": true,
|
||||||
|
"1.0pl1 eq 1.0b1": false,
|
||||||
|
"1.0pl1 = 1.0b1": false,
|
||||||
|
"1.0pl1 == 1.0b1": false,
|
||||||
|
"1.0pl1 ne 1.0b1": true,
|
||||||
|
"1.0pl1 <> 1.0b1": true,
|
||||||
|
"1.0pl1 != 1.0b1": true,
|
||||||
|
"1.0pl1 lt 1.0RC1": false,
|
||||||
|
"1.0pl1 < 1.0RC1": false,
|
||||||
|
"1.0pl1 le 1.0RC1": false,
|
||||||
|
"1.0pl1 <= 1.0RC1": false,
|
||||||
|
"1.0pl1 gt 1.0RC1": true,
|
||||||
|
"1.0pl1 > 1.0RC1": true,
|
||||||
|
"1.0pl1 ge 1.0RC1": true,
|
||||||
|
"1.0pl1 >= 1.0RC1": true,
|
||||||
|
"1.0pl1 eq 1.0RC1": false,
|
||||||
|
"1.0pl1 = 1.0RC1": false,
|
||||||
|
"1.0pl1 == 1.0RC1": false,
|
||||||
|
"1.0pl1 ne 1.0RC1": true,
|
||||||
|
"1.0pl1 <> 1.0RC1": true,
|
||||||
|
"1.0pl1 != 1.0RC1": true,
|
||||||
|
"1.0pl1 lt 1.0rc1": false,
|
||||||
|
"1.0pl1 < 1.0rc1": false,
|
||||||
|
"1.0pl1 le 1.0rc1": false,
|
||||||
|
"1.0pl1 <= 1.0rc1": false,
|
||||||
|
"1.0pl1 gt 1.0rc1": true,
|
||||||
|
"1.0pl1 > 1.0rc1": true,
|
||||||
|
"1.0pl1 ge 1.0rc1": true,
|
||||||
|
"1.0pl1 >= 1.0rc1": true,
|
||||||
|
"1.0pl1 eq 1.0rc1": false,
|
||||||
|
"1.0pl1 = 1.0rc1": false,
|
||||||
|
"1.0pl1 == 1.0rc1": false,
|
||||||
|
"1.0pl1 ne 1.0rc1": true,
|
||||||
|
"1.0pl1 <> 1.0rc1": true,
|
||||||
|
"1.0pl1 != 1.0rc1": true,
|
||||||
|
"1.0pl1 lt 1.0": false,
|
||||||
|
"1.0pl1 < 1.0": false,
|
||||||
|
"1.0pl1 le 1.0": false,
|
||||||
|
"1.0pl1 <= 1.0": false,
|
||||||
|
"1.0pl1 gt 1.0": true,
|
||||||
|
"1.0pl1 > 1.0": true,
|
||||||
|
"1.0pl1 ge 1.0": true,
|
||||||
|
"1.0pl1 >= 1.0": true,
|
||||||
|
"1.0pl1 eq 1.0": false,
|
||||||
|
"1.0pl1 = 1.0": false,
|
||||||
|
"1.0pl1 == 1.0": false,
|
||||||
|
"1.0pl1 ne 1.0": true,
|
||||||
|
"1.0pl1 <> 1.0": true,
|
||||||
|
"1.0pl1 != 1.0": true,
|
||||||
|
"1.0pl1 lt 1.0pl1": false,
|
||||||
|
"1.0pl1 < 1.0pl1": false,
|
||||||
|
"1.0pl1 le 1.0pl1": true,
|
||||||
|
"1.0pl1 <= 1.0pl1": true,
|
||||||
|
"1.0pl1 gt 1.0pl1": false,
|
||||||
|
"1.0pl1 > 1.0pl1": false,
|
||||||
|
"1.0pl1 ge 1.0pl1": true,
|
||||||
|
"1.0pl1 >= 1.0pl1": true,
|
||||||
|
"1.0pl1 eq 1.0pl1": true,
|
||||||
|
"1.0pl1 = 1.0pl1": true,
|
||||||
|
"1.0pl1 == 1.0pl1": true,
|
||||||
|
"1.0pl1 ne 1.0pl1": false,
|
||||||
|
"1.0pl1 <> 1.0pl1": false,
|
||||||
|
"1.0pl1 != 1.0pl1": false,
|
||||||
|
"2.2.3.0 < 2.4.0.0-dev": true,
|
||||||
|
//Test unnormalized strings
|
||||||
|
"2.3.4 < v3.1.2": false,
|
||||||
|
"dev-master = 9999999-dev": false,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompareNormalized(t *testing.T) {
|
||||||
|
for in, out := range compareNormalizedVersionValues {
|
||||||
|
v := strings.Split(in, " ")
|
||||||
|
if x := CompareNormalized(v[0], v[2], v[1]); x != out {
|
||||||
|
t.Errorf("FAIL: CompareNormalized(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var compareVersionValues = map[string]bool{
|
||||||
|
"2.3.4 < v3.1.2": true,
|
||||||
|
"dev-master = 9999999-dev": true,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompare(t *testing.T) {
|
||||||
|
for in, out := range compareVersionValues {
|
||||||
|
v := strings.Split(in, " ")
|
||||||
|
if x := Compare(v[0], v[2], v[1]); x != out {
|
||||||
|
t.Errorf("FAIL: Compare(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var simpleVersionFormatValues = map[string]bool{
|
||||||
|
"9999999-dev": true,
|
||||||
|
"1.2.3": true,
|
||||||
|
"abcdef": false,
|
||||||
|
"1.abcdef": false,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidSimpleVersionFormat(t *testing.T) {
|
||||||
|
for in, out := range simpleVersionFormatValues {
|
||||||
|
if x := ValidSimpleVersionFormat(in); x != out {
|
||||||
|
t.Errorf("FAIL: ValidSimpleVersionFormat(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Constraint struct {
|
||||||
|
operator string
|
||||||
|
version string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a new Constrain and sets operator and version to compare
|
||||||
|
func NewConstrain(operator, version string) *Constraint {
|
||||||
|
constraint := new(Constraint)
|
||||||
|
constraint.SetOperator(operator)
|
||||||
|
constraint.SetVersion(version)
|
||||||
|
|
||||||
|
return constraint
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets operator to compare
|
||||||
|
func (self *Constraint) SetOperator(operator string) {
|
||||||
|
self.operator = operator
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get operator to compare
|
||||||
|
func (self *Constraint) GetOperator() string {
|
||||||
|
return self.operator
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets version to compare
|
||||||
|
func (self *Constraint) SetVersion(version string) {
|
||||||
|
self.version = version
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get version to compare
|
||||||
|
func (self *Constraint) GetVersion() string {
|
||||||
|
return self.version
|
||||||
|
}
|
||||||
|
|
||||||
|
// Match a given version againts the constraint
|
||||||
|
func (self *Constraint) Match(version string) bool {
|
||||||
|
return Compare(version, self.version, self.operator)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a string representation
|
||||||
|
func (self *Constraint) String() string {
|
||||||
|
return strings.Trim(self.operator+" "+self.version, " ")
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetOperator(t *testing.T) {
|
||||||
|
constraint := NewConstrain("=", "1.0.0")
|
||||||
|
out := "="
|
||||||
|
|
||||||
|
if x := constraint.GetOperator(); x != "=" {
|
||||||
|
t.Errorf("FAIL: GetOperator() = {%s}: want {%s}", x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetVersion(t *testing.T) {
|
||||||
|
constraint := NewConstrain("=", "1.0.0")
|
||||||
|
out := "1.0.0"
|
||||||
|
|
||||||
|
if x := constraint.GetVersion(); x != "1.0.0" {
|
||||||
|
t.Errorf("FAIL: GetVersion() = {%s}: want {%s}", x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestString(t *testing.T) {
|
||||||
|
constraint := NewConstrain("=", "1.0.0")
|
||||||
|
out := "= 1.0.0"
|
||||||
|
|
||||||
|
if x := constraint.String(); x != out {
|
||||||
|
t.Errorf("FAIL: String() = {%s}: want {%s}", x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMatchSuccess(t *testing.T) {
|
||||||
|
constraint := NewConstrain("=", "1.0.0")
|
||||||
|
out := true
|
||||||
|
|
||||||
|
if x := constraint.Match("1.0"); x != out {
|
||||||
|
t.Errorf("FAIL: Match() = {%v}: want {%v}", x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMatchFail(t *testing.T) {
|
||||||
|
constraint := NewConstrain("=", "1.0.0")
|
||||||
|
out := false
|
||||||
|
|
||||||
|
if x := constraint.Match("2.0"); x != out {
|
||||||
|
t.Errorf("FAIL: Match() = {%v}: want {%v}", x, out)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
/*
|
||||||
|
Version normalizer and comparison library for go, heavy based on PHP
|
||||||
|
version_compare function and Version comparsion libs from Composer
|
||||||
|
(https://github.com/composer/composer) PHP project
|
||||||
|
*/
|
||||||
|
package version
|
|
@ -0,0 +1,300 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConstraintGroup struct {
|
||||||
|
constraints []*Constraint
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a new NewConstrainGroup
|
||||||
|
func NewConstrainGroup() *ConstraintGroup {
|
||||||
|
group := new(ConstraintGroup)
|
||||||
|
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return a new NewConstrainGroup and create the constraints based on a string
|
||||||
|
//
|
||||||
|
// Version constraints can be specified in a few different ways:
|
||||||
|
//
|
||||||
|
// Exact version: You can specify the exact version of a package, for
|
||||||
|
// example 1.0.2.
|
||||||
|
//
|
||||||
|
// Range: By using comparison operators you can specify ranges of valid versions.
|
||||||
|
// Valid operators are >, >=, <, <=, !=. An example range would be >=1.0. You can
|
||||||
|
// define multiple ranges, separated by a comma: >=1.0,<2.0.
|
||||||
|
//
|
||||||
|
// Wildcard: You can specify a pattern with a * wildcard. 1.0.* is the equivalent
|
||||||
|
// of >=1.0,<1.1.
|
||||||
|
//
|
||||||
|
// Next Significant Release (Tilde Operator): The ~ operator is best explained by
|
||||||
|
// example: ~1.2 is equivalent to >=1.2,<2.0, while ~1.2.3 is equivalent to
|
||||||
|
// >=1.2.3,<1.3. As you can see it is mostly useful for projects respecting
|
||||||
|
// semantic versioning. A common usage would be to mark the minimum minor
|
||||||
|
// version you depend on, like ~1.2 (which allows anything up to, but not
|
||||||
|
// including, 2.0). Since in theory there should be no backwards compatibility
|
||||||
|
// breaks until 2.0, that works well. Another way of looking at it is that
|
||||||
|
// using ~ specifies a minimum version, but allows the last digit specified
|
||||||
|
// to go up.
|
||||||
|
//
|
||||||
|
// By default only stable releases are taken into consideration. If you would like
|
||||||
|
// to also get RC, beta, alpha or dev versions of your dependencies you can do so
|
||||||
|
// using stability flags. To change that for all packages instead of doing per
|
||||||
|
// dependency you can also use the minimum-stability setting.
|
||||||
|
//
|
||||||
|
// From: http://getcomposer.org/doc/01-basic-usage.md#package-versions
|
||||||
|
func NewConstrainGroupFromString(name string) *ConstraintGroup {
|
||||||
|
group := new(ConstraintGroup)
|
||||||
|
group.fromString(name)
|
||||||
|
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adds a Contraint to the group
|
||||||
|
func (self *ConstraintGroup) AddConstraint(constraint ...*Constraint) {
|
||||||
|
if self.constraints == nil {
|
||||||
|
self.constraints = make([]*Constraint, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.constraints = append(self.constraints, constraint...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return all the constraints
|
||||||
|
func (self *ConstraintGroup) GetConstraints() []*Constraint {
|
||||||
|
return self.constraints
|
||||||
|
}
|
||||||
|
|
||||||
|
// Match a given version againts the group
|
||||||
|
//
|
||||||
|
// Usage
|
||||||
|
// c := version.NewConstrainGroupFromString(">2.0,<=3.0")
|
||||||
|
// c.Match("2.5.0beta")
|
||||||
|
// Returns: true
|
||||||
|
//
|
||||||
|
// c := version.NewConstrainGroupFromString("~1.2.3")
|
||||||
|
// c.Match("1.2.3.5")
|
||||||
|
// Returns: true
|
||||||
|
func (self *ConstraintGroup) Match(version string) bool {
|
||||||
|
for _, constraint := range self.constraints {
|
||||||
|
if constraint.Match(version) == false {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *ConstraintGroup) fromString(constraint string) bool {
|
||||||
|
result := RegFind(`(?i)^([^,\s]*?)@(stable|RC|beta|alpha|dev)$`, constraint)
|
||||||
|
if result != nil {
|
||||||
|
constraint = result[1]
|
||||||
|
if constraint == "" {
|
||||||
|
constraint = "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = RegFind(`(?i)^(dev-[^,\s@]+?|[^,\s@]+?\.x-dev)#.+$`, constraint)
|
||||||
|
if result != nil {
|
||||||
|
if result[1] != "" {
|
||||||
|
constraint = result[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constraints := RegSplit(`\s*,\s*`, strings.Trim(constraint, " "))
|
||||||
|
|
||||||
|
if len(constraints) > 1 {
|
||||||
|
for _, part := range constraints {
|
||||||
|
self.AddConstraint(self.parseConstraint(part)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
self.AddConstraint(self.parseConstraint(constraints[0])...)
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *ConstraintGroup) parseConstraint(constraint string) []*Constraint {
|
||||||
|
|
||||||
|
stabilityModifier := ""
|
||||||
|
|
||||||
|
result := RegFind(`(?i)^([^,\s]+?)@(stable|RC|beta|alpha|dev)$`, constraint)
|
||||||
|
if result != nil {
|
||||||
|
constraint = result[1]
|
||||||
|
if result[2] != "stable" {
|
||||||
|
stabilityModifier = result[2]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = RegFind(`^[x*](\.[x*])*$`, constraint)
|
||||||
|
if result != nil {
|
||||||
|
return make([]*Constraint, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
highVersion := ""
|
||||||
|
lowVersion := ""
|
||||||
|
|
||||||
|
result = RegFind(`(?i)^~(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?`+modifierRegex+`?$`, constraint)
|
||||||
|
if result != nil {
|
||||||
|
if len(result) > 4 && result[4] != "" {
|
||||||
|
last, _ := strconv.Atoi(result[3])
|
||||||
|
highVersion = result[1] + "." + result[2] + "." + strconv.Itoa(last+1) + ".0-dev"
|
||||||
|
lowVersion = result[1] + "." + result[2] + "." + result[3] + "." + result[4]
|
||||||
|
} else if len(result) > 3 && result[3] != "" {
|
||||||
|
last, _ := strconv.Atoi(result[2])
|
||||||
|
highVersion = result[1] + "." + strconv.Itoa(last+1) + ".0.0-dev"
|
||||||
|
lowVersion = result[1] + "." + result[2] + "." + result[3] + ".0"
|
||||||
|
} else {
|
||||||
|
last, _ := strconv.Atoi(result[1])
|
||||||
|
highVersion = strconv.Itoa(last+1) + ".0.0.0-dev"
|
||||||
|
if len(result) > 2 && result[2] != "" {
|
||||||
|
lowVersion = result[1] + "." + result[2] + ".0.0"
|
||||||
|
} else {
|
||||||
|
lowVersion = result[1] + ".0.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result) > 5 && result[5] != "" {
|
||||||
|
lowVersion = lowVersion + "-" + expandStability(result[5])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result) > 6 && result[6] != "" {
|
||||||
|
lowVersion = lowVersion + result[6]
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result) > 7 && result[7] != "" {
|
||||||
|
lowVersion = lowVersion + "-dev"
|
||||||
|
}
|
||||||
|
|
||||||
|
return []*Constraint{
|
||||||
|
{">=", lowVersion},
|
||||||
|
{"<", highVersion},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = RegFind(`^(\d+)(?:\.(\d+))?(?:\.(\d+))?\.[x*]$`, constraint)
|
||||||
|
if result != nil {
|
||||||
|
if len(result) > 3 && result[3] != "" {
|
||||||
|
highVersion = result[1] + "." + result[2] + "." + result[3] + ".9999999"
|
||||||
|
if result[3] == "0" {
|
||||||
|
last, _ := strconv.Atoi(result[2])
|
||||||
|
lowVersion = result[1] + "." + strconv.Itoa(last-1) + ".9999999.9999999"
|
||||||
|
} else {
|
||||||
|
last, _ := strconv.Atoi(result[3])
|
||||||
|
lowVersion = result[1] + "." + result[2] + "." + strconv.Itoa(last-1) + ".9999999"
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if len(result) > 2 && result[2] != "" {
|
||||||
|
highVersion = result[1] + "." + result[2] + ".9999999.9999999"
|
||||||
|
if result[2] == "0" {
|
||||||
|
last, _ := strconv.Atoi(result[1])
|
||||||
|
lowVersion = strconv.Itoa(last-1) + ".9999999.9999999.9999999"
|
||||||
|
} else {
|
||||||
|
last, _ := strconv.Atoi(result[2])
|
||||||
|
lowVersion = result[1] + "." + strconv.Itoa(last-1) + ".9999999.9999999"
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
highVersion = result[1] + ".9999999.9999999.9999999"
|
||||||
|
if result[1] == "0" {
|
||||||
|
return []*Constraint{{"<", highVersion}}
|
||||||
|
} else {
|
||||||
|
last, _ := strconv.Atoi(result[1])
|
||||||
|
lowVersion = strconv.Itoa(last-1) + ".9999999.9999999.9999999"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return []*Constraint{
|
||||||
|
{">", lowVersion},
|
||||||
|
{"<", highVersion},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// match operators constraints
|
||||||
|
result = RegFind(`^(<>|!=|>=?|<=?|==?)?\s*(.*)`, constraint)
|
||||||
|
if result != nil {
|
||||||
|
version := Normalize(result[2])
|
||||||
|
|
||||||
|
if stabilityModifier != "" && parseStability(version) == "stable" {
|
||||||
|
version = version + "-" + stabilityModifier
|
||||||
|
} else if result[1] == "<" {
|
||||||
|
match := RegFind(`(?i)-stable$`, result[2])
|
||||||
|
if match == nil {
|
||||||
|
version = version + "-dev"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result) > 1 && result[1] != "" {
|
||||||
|
return []*Constraint{{result[1], version}}
|
||||||
|
} else {
|
||||||
|
return []*Constraint{{"=", version}}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return []*Constraint{{constraint, stabilityModifier}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PCRegMap : PreCompiled Regex Map
|
||||||
|
type PCRegMap struct {
|
||||||
|
sync.RWMutex
|
||||||
|
m map[string]*regexp.Regexp
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustCompile : to replace regexp.MustCompile in RegFind.
|
||||||
|
func (p *PCRegMap) MustCompile(pattern string) *regexp.Regexp {
|
||||||
|
p.RLock()
|
||||||
|
ret, exist := p.m[pattern]
|
||||||
|
p.RUnlock()
|
||||||
|
if exist {
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
ret = regexp.MustCompile(pattern)
|
||||||
|
p.Lock()
|
||||||
|
p.m[pattern] = ret
|
||||||
|
p.Unlock()
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
regexpCache *PCRegMap
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
regexpCache = new(PCRegMap)
|
||||||
|
regexpCache.m = make(map[string]*regexp.Regexp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegFind(pattern, subject string) []string {
|
||||||
|
reg := regexpCache.MustCompile(pattern)
|
||||||
|
matched := reg.FindAllStringSubmatch(subject, -1)
|
||||||
|
|
||||||
|
if matched != nil {
|
||||||
|
return matched[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegSplit(pattern, subject string) []string {
|
||||||
|
reg := regexp.MustCompile(pattern)
|
||||||
|
indexes := reg.FindAllStringIndex(subject, -1)
|
||||||
|
|
||||||
|
laststart := 0
|
||||||
|
result := make([]string, len(indexes)+1)
|
||||||
|
|
||||||
|
for i, element := range indexes {
|
||||||
|
result[i] = subject[laststart:element[0]]
|
||||||
|
laststart = element[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
result[len(indexes)] = subject[laststart:len(subject)]
|
||||||
|
return result
|
||||||
|
}
|
|
@ -0,0 +1,154 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var anyConstraints = map[string][]*Constraint{
|
||||||
|
"*": []*Constraint{},
|
||||||
|
"*.*": []*Constraint{},
|
||||||
|
"*.x.*": []*Constraint{},
|
||||||
|
"x.x.x.*": []*Constraint{},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseAnyConstraints(t *testing.T) {
|
||||||
|
for in, out := range anyConstraints {
|
||||||
|
constraint := NewConstrainGroupFromString(in)
|
||||||
|
if x := constraint.GetConstraints(); len(x) != 0 {
|
||||||
|
t.Errorf("FAIL: fromString(%v) = {%s}: want {%s}", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var simpleConstraints = map[string][]*Constraint{
|
||||||
|
"<>1.0.0": []*Constraint{{"<>", "1.0.0.0"}},
|
||||||
|
"!=1.0.0": []*Constraint{{"!=", "1.0.0.0"}},
|
||||||
|
">1.0.0": []*Constraint{{">", "1.0.0.0"}},
|
||||||
|
"<1.2.3.4": []*Constraint{{"<", "1.2.3.4-dev"}},
|
||||||
|
"<=1.2.3": []*Constraint{{"<=", "1.2.3.0"}},
|
||||||
|
">=1.2.3": []*Constraint{{">=", "1.2.3.0"}},
|
||||||
|
"=1.2.3": []*Constraint{{"=", "1.2.3.0"}},
|
||||||
|
"==1.2.3": []*Constraint{{"==", "1.2.3.0"}},
|
||||||
|
"1.2.3": []*Constraint{{"=", "1.2.3.0"}},
|
||||||
|
"=1.0": []*Constraint{{"=", "1.0.0.0"}},
|
||||||
|
"1.2.3b5": []*Constraint{{"=", "1.2.3.0-beta5"}},
|
||||||
|
">= 1.2.3": []*Constraint{{">=", "1.2.3.0"}},
|
||||||
|
">=dev-master": []*Constraint{{">=", "9999999-dev"}},
|
||||||
|
"dev-master": []*Constraint{{"=", "9999999-dev"}},
|
||||||
|
"dev-feature-a": []*Constraint{{"=", "dev-feature-a"}},
|
||||||
|
"dev-some-fix": []*Constraint{{"=", "dev-some-fix"}},
|
||||||
|
"dev-CAPS": []*Constraint{{"=", "dev-CAPS"}},
|
||||||
|
"dev-master as 1.0.0": []*Constraint{{"=", "9999999-dev"}},
|
||||||
|
"<1.2.3.4-stable": []*Constraint{{"<", "1.2.3.4"}},
|
||||||
|
|
||||||
|
"<=3.0@dev": []*Constraint{{"<=", "3.0.0.0"}},
|
||||||
|
"1.0@dev": []*Constraint{{"=", "1.0.0.0"}}, //IgnoresStabilityFlag
|
||||||
|
"1.0.x-dev#abcd123": []*Constraint{{"=", "1.0.9999999.9999999-dev"}}, //IgnoresReferenceOnDevVersion
|
||||||
|
"1.0.x-dev#trunk/@123": []*Constraint{{"=", "1.0.9999999.9999999-dev"}}, //IgnoresReferenceOnDevVersion
|
||||||
|
//"1.0#abcd123": []string{"=", "1.0.0.0"}, //FailsOnBadReference
|
||||||
|
//"1.0#trunk/@123": []string{"=", "1.0.0.0"}, //FailsOnBadReference
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseConstraints(t *testing.T) {
|
||||||
|
for in, out := range simpleConstraints {
|
||||||
|
constraint := NewConstrainGroupFromString(in)
|
||||||
|
if x := constraint.GetConstraints(); x[0].String() != out[0].String() {
|
||||||
|
t.Errorf("FAIL: parseConstraints(%v) = {%s}: want {%s}", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var wildcardConstraints = map[string][]*Constraint{
|
||||||
|
"2.*": []*Constraint{{">", "1.9999999.9999999.9999999"}, {"<", "2.9999999.9999999.9999999"}},
|
||||||
|
"20.*": []*Constraint{{">", "19.9999999.9999999.9999999"}, {"<", "20.9999999.9999999.9999999"}},
|
||||||
|
"2.0.*": []*Constraint{{">", "1.9999999.9999999.9999999"}, {"<", "2.0.9999999.9999999"}},
|
||||||
|
"2.2.x": []*Constraint{{">", "2.1.9999999.9999999"}, {"<", "2.2.9999999.9999999"}},
|
||||||
|
"2.10.x": []*Constraint{{">", "2.9.9999999.9999999"}, {"<", "2.10.9999999.9999999"}},
|
||||||
|
"2.1.3.*": []*Constraint{{">", "2.1.2.9999999"}, {"<", "2.1.3.9999999"}},
|
||||||
|
"0.*": []*Constraint{{"<", "0.9999999.9999999.9999999"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseConstraintsWildcardConstraints(t *testing.T) {
|
||||||
|
for in, out := range wildcardConstraints {
|
||||||
|
constraint := NewConstrainGroupFromString(in)
|
||||||
|
if x := constraint.GetConstraints(); x[0].String() != out[0].String() && x[1].String() != out[1].String() {
|
||||||
|
t.Errorf("FAIL: parseConstraints(%v) = {%s}: want {%s}", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var tildeConstraints = map[string][]*Constraint{
|
||||||
|
"~1": []*Constraint{{">=", "1.0.0.0"}, {"<", "2.0.0.0-dev"}},
|
||||||
|
"~1.2": []*Constraint{{">=", "1.2.0.0"}, {"<", "2.0.0.0-dev"}},
|
||||||
|
"~1.2.3": []*Constraint{{">=", "1.2.3.0"}, {"<", "1.3.0.0-dev"}},
|
||||||
|
"~1.2.3.4": []*Constraint{{">=", "1.2.3.4"}, {"<", "1.2.4.0-dev"}},
|
||||||
|
"~1.2-beta": []*Constraint{{">=", "1.2.0.0-beta"}, {"<", "2.0.0.0-dev"}},
|
||||||
|
"~1.2-b2": []*Constraint{{">=", "1.2.0.0-beta2"}, {"<", "2.0.0.0-dev"}},
|
||||||
|
"~1.2-BETA2": []*Constraint{{">=", "1.2.0.0-beta2"}, {"<", "2.0.0.0-dev"}},
|
||||||
|
"~1.2.2-dev": []*Constraint{{">=", "1.2.2.0-dev"}, {"<", "1.3.0.0-dev"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseConstraintsTildeConstraints(t *testing.T) {
|
||||||
|
for in, out := range tildeConstraints {
|
||||||
|
constraint := NewConstrainGroupFromString(in)
|
||||||
|
if x := constraint.GetConstraints(); x[0].String() != out[0].String() && x[1].String() != out[1].String() {
|
||||||
|
t.Errorf("FAIL: parseConstraints(%v) = {%s}: want {%s}", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var multiConstraints = map[string][]*Constraint{
|
||||||
|
">2.0,<=3.0": []*Constraint{{">", "2.0.0.0"}, {"<=", "3.0.0.0"}},
|
||||||
|
">2.0@stable,<=3.0@dev": []*Constraint{{">", "2.0.0.0"}, {"<=", "3.0.0.0-dev"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseConstraintsMultiConstraints(t *testing.T) {
|
||||||
|
for in, out := range multiConstraints {
|
||||||
|
constraint := NewConstrainGroupFromString(in)
|
||||||
|
if x := constraint.GetConstraints(); x[0].String() != out[0].String() && x[1].String() != out[1].String() {
|
||||||
|
t.Errorf("FAIL: parseConstraints(%v) = {%s}: want {%s}", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var miscConstraints = map[string]bool{
|
||||||
|
"*|1.0": true,
|
||||||
|
">2.0,<=3.0|2.5.0beta": true,
|
||||||
|
">2.0,<=3.0|3.5.0beta": false,
|
||||||
|
">=2.2.3,<2.4-dev|2.3.3": true,
|
||||||
|
"~1.2.3|1.2.3.5": true,
|
||||||
|
"~1.2.3|1.4.3.5": false,
|
||||||
|
"2.0.*|2.0.5": true,
|
||||||
|
"2.0.*|2.1.5": false,
|
||||||
|
"2.0.5|2.0.5": true,
|
||||||
|
"2.0.5|2.0.9": false,
|
||||||
|
">2.0.5|2.0.9": true,
|
||||||
|
"<2.0.5|2.0.9": false,
|
||||||
|
">=dev-master|dev-master": true,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMatch(t *testing.T) {
|
||||||
|
for in, out := range miscConstraints {
|
||||||
|
tmp := strings.Split(in, "|")
|
||||||
|
|
||||||
|
constraint := NewConstrainGroupFromString(tmp[0])
|
||||||
|
if x := constraint.Match(tmp[1]); x != out {
|
||||||
|
t.Errorf("FAIL: Match(%v) = {%v}: want {%v}", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddConstraint(t *testing.T) {
|
||||||
|
group := NewConstrainGroup()
|
||||||
|
group.AddConstraint(NewConstrain("=", "1.0.0"))
|
||||||
|
|
||||||
|
constraints := group.GetConstraints()
|
||||||
|
if x := constraints[0].GetOperator(); x != "=" {
|
||||||
|
t.Errorf("FAIL: AddConstraintOperator() = {%s}: want {%s}", x, "=")
|
||||||
|
}
|
||||||
|
|
||||||
|
if x := constraints[0].GetVersion(); x != "1.0.0" {
|
||||||
|
t.Errorf("FAIL: AddConstraintVersion() = {%s}: want {%s}", x, "1.0.0")
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var modifierRegex = `[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?`
|
||||||
|
|
||||||
|
var regexpMasterLikeBranches = regexp.MustCompile(`^(?:dev-)?(?:master|trunk|default)$`)
|
||||||
|
var regexpBranchNormalize = regexp.MustCompile(`(?i)^v?(\d+)(\.(?:\d+|[x*]))?(\.(?:\d+|[x*]))?(\.(?:\d+|[x*]))?$`)
|
||||||
|
|
||||||
|
// Normalizes a version string to be able to perform comparisons on it
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// version.Normalize("10.4.13-b")
|
||||||
|
// Returns: 10.4.13.0-beta
|
||||||
|
//
|
||||||
|
func Normalize(version string) string {
|
||||||
|
|
||||||
|
// ignore aliases and just assume the alias is required instead of the source
|
||||||
|
result := RegFind(`^([^,\s]+) +as +([^,\s]+)$`, version)
|
||||||
|
if result != nil {
|
||||||
|
version = result[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// match master-like branches
|
||||||
|
if regexpMasterLikeBranches.MatchString(strings.ToLower(version)) {
|
||||||
|
return "9999999-dev"
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(strings.ToLower(version), "dev-") {
|
||||||
|
return "dev-" + version[4:len(version)]
|
||||||
|
}
|
||||||
|
|
||||||
|
index := 0
|
||||||
|
|
||||||
|
// match classical versioning
|
||||||
|
result = RegFind(`(?i)^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?`+modifierRegex+`$`, version)
|
||||||
|
if result != nil {
|
||||||
|
version = ""
|
||||||
|
for _, val := range result[1:5] {
|
||||||
|
if val != "" {
|
||||||
|
version = version + val
|
||||||
|
} else {
|
||||||
|
version = version + ".0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
index = 5
|
||||||
|
} else {
|
||||||
|
// match date-based versioning
|
||||||
|
result = RegFind(`(?i)^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)`+modifierRegex+`$`, version)
|
||||||
|
if result != nil {
|
||||||
|
version = regexp.MustCompile(`\D`).ReplaceAllString(result[1], "-")
|
||||||
|
index = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if index != 0 {
|
||||||
|
if result[index] != "" {
|
||||||
|
if result[index] == "stable" {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
version = version + "-" + expandStability(result[index])
|
||||||
|
if result[index+1] != "" {
|
||||||
|
version = version + result[index+1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if result[index+2] != "" {
|
||||||
|
version = version + "-dev"
|
||||||
|
}
|
||||||
|
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
result = RegFind(`(?i)(.*?)[.-]?dev$`, version)
|
||||||
|
if result != nil {
|
||||||
|
return normalizeBranch(result[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeBranch(name string) string {
|
||||||
|
name = strings.Trim(name, " ")
|
||||||
|
|
||||||
|
if name == "master" || name == "trunk" || name == "default" {
|
||||||
|
return Normalize(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
replace := strings.NewReplacer("*", "9999999", "x", "9999999")
|
||||||
|
|
||||||
|
matched := regexpBranchNormalize.FindAllStringSubmatch(name, -1)
|
||||||
|
if matched != nil {
|
||||||
|
name = ""
|
||||||
|
for _, val := range matched[0][1:5] {
|
||||||
|
if val != "" {
|
||||||
|
name = name + replace.Replace(val)
|
||||||
|
} else {
|
||||||
|
name = name + ".9999999"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return name + "-dev"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(strings.ToLower(name), "-dev") {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
return "dev-" + name
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var versions = map[string]string{
|
||||||
|
"1-stable": "1.0.0.0",
|
||||||
|
"1.0.0": "1.0.0.0",
|
||||||
|
"1.2.3.4": "1.2.3.4",
|
||||||
|
"1.0.0RC1dev": "1.0.0.0-RC1-dev",
|
||||||
|
"1.0.0-rC15-dev": "1.0.0.0-RC15-dev",
|
||||||
|
"1.0.0.RC.15-dev": "1.0.0.0-RC15-dev",
|
||||||
|
"1.0.0-rc1": "1.0.0.0-RC1",
|
||||||
|
"1.0.0.pl3-dev": "1.0.0.0-patch3-dev",
|
||||||
|
"1.0-dev": "1.0.0.0-dev",
|
||||||
|
"0": "0.0.0.0",
|
||||||
|
"10.4.13-beta": "10.4.13.0-beta",
|
||||||
|
"10.4.13-b": "10.4.13.0-beta",
|
||||||
|
"10.4.13-b5": "10.4.13.0-beta5",
|
||||||
|
"v1.0.0": "1.0.0.0",
|
||||||
|
"v20100102": "20100102",
|
||||||
|
"2010.01": "2010-01",
|
||||||
|
"2010.01.02": "2010-01-02",
|
||||||
|
"2010-01-02": "2010-01-02",
|
||||||
|
"2010-01-02.5": "2010-01-02-5",
|
||||||
|
"20100102-203040": "20100102-203040",
|
||||||
|
"20100102203040-10": "20100102203040-10",
|
||||||
|
"20100102-203040-p1": "20100102-203040-patch1",
|
||||||
|
"dev-master": "9999999-dev",
|
||||||
|
"dev-trunk": "9999999-dev",
|
||||||
|
"1.x-dev": "1.9999999.9999999.9999999-dev",
|
||||||
|
"dev-feature-foo": "dev-feature-foo",
|
||||||
|
"DEV-FOOBAR": "dev-FOOBAR",
|
||||||
|
"dev-feature/foo": "dev-feature/foo",
|
||||||
|
"dev-master as 1.0.0": "9999999-dev",
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNormalize(t *testing.T) {
|
||||||
|
for in, out := range versions {
|
||||||
|
if x := Normalize(in); x != out {
|
||||||
|
t.Errorf("FAIL: Normalize(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var branches = map[string]string{
|
||||||
|
"v1.x": "1.9999999.9999999.9999999-dev",
|
||||||
|
"v1.*": "1.9999999.9999999.9999999-dev",
|
||||||
|
"v1.0": "1.0.9999999.9999999-dev",
|
||||||
|
"2.0": "2.0.9999999.9999999-dev",
|
||||||
|
"v1.0.x": "1.0.9999999.9999999-dev",
|
||||||
|
"v1.0.3.*": "1.0.3.9999999-dev",
|
||||||
|
"v2.4.0": "2.4.0.9999999-dev",
|
||||||
|
"2.4.4": "2.4.4.9999999-dev",
|
||||||
|
"master": "9999999-dev",
|
||||||
|
"trunk": "9999999-dev",
|
||||||
|
"feature-a": "dev-feature-a",
|
||||||
|
"FOOBAR": "dev-FOOBAR",
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNormalizeBranch(t *testing.T) {
|
||||||
|
for in, out := range branches {
|
||||||
|
if x := normalizeBranch(in); x != out {
|
||||||
|
t.Errorf("FAIL: normalizeBranch(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Sorts a string slice of version number strings using version.CompareSimple()
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
// version.Sort([]string{"1.10-dev", "1.0rc1", "1.0", "1.0-dev"})
|
||||||
|
// Returns []string{"1.0-dev", "1.0rc1", "1.0", "1.10-dev"}
|
||||||
|
//
|
||||||
|
func Sort(versionStrings []string) {
|
||||||
|
versions := versionSlice(versionStrings)
|
||||||
|
sort.Sort(versions)
|
||||||
|
}
|
||||||
|
|
||||||
|
type versionSlice []string
|
||||||
|
|
||||||
|
func (s versionSlice) Len() int {
|
||||||
|
return len(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s versionSlice) Less(i, j int) bool {
|
||||||
|
cmp := CompareSimple(Normalize(s[i]), Normalize(s[j]))
|
||||||
|
if cmp == 0 {
|
||||||
|
return s[i] < s[j]
|
||||||
|
}
|
||||||
|
return cmp < 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s versionSlice) Swap(i, j int) {
|
||||||
|
tmp := s[j]
|
||||||
|
s[j] = s[i]
|
||||||
|
s[i] = tmp
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSort(t *testing.T) {
|
||||||
|
testcases := []struct {
|
||||||
|
input []string
|
||||||
|
output []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: []string{
|
||||||
|
"Package-0.4.tar.gz",
|
||||||
|
"Package-0.1.tar.gz",
|
||||||
|
"Package-0.10.1.tar.gz",
|
||||||
|
"Package-0.10.tar.gz",
|
||||||
|
"Package-0.2.tar.gz",
|
||||||
|
"Package-0.3.1.tar.gz",
|
||||||
|
"Package-0.3.2.tar.gz",
|
||||||
|
"Package-0.3.tar.gz",
|
||||||
|
},
|
||||||
|
output: []string{
|
||||||
|
"Package-0.1.tar.gz",
|
||||||
|
"Package-0.2.tar.gz",
|
||||||
|
"Package-0.3.tar.gz",
|
||||||
|
"Package-0.3.1.tar.gz",
|
||||||
|
"Package-0.3.2.tar.gz",
|
||||||
|
"Package-0.4.tar.gz",
|
||||||
|
"Package-0.10.tar.gz",
|
||||||
|
"Package-0.10.1.tar.gz",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: []string{
|
||||||
|
"1.0-dev",
|
||||||
|
"1.0a1",
|
||||||
|
"1.0b1",
|
||||||
|
"1.0RC1",
|
||||||
|
"1.0rc1",
|
||||||
|
"1.0",
|
||||||
|
"1.0pl1",
|
||||||
|
"1.1-dev",
|
||||||
|
"1.2",
|
||||||
|
"1.10",
|
||||||
|
},
|
||||||
|
output: []string{
|
||||||
|
"1.0pl1",
|
||||||
|
"1.0-dev",
|
||||||
|
"1.0a1",
|
||||||
|
"1.0b1",
|
||||||
|
"1.0RC1",
|
||||||
|
"1.0rc1",
|
||||||
|
"1.0",
|
||||||
|
"1.1-dev",
|
||||||
|
"1.2",
|
||||||
|
"1.10",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: []string{
|
||||||
|
"v1.0",
|
||||||
|
"1.0.1",
|
||||||
|
"dev-master",
|
||||||
|
},
|
||||||
|
output: []string{
|
||||||
|
"v1.0",
|
||||||
|
"1.0.1",
|
||||||
|
"dev-master",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testcase := range testcases {
|
||||||
|
Sort(testcase.input)
|
||||||
|
if !reflect.DeepEqual(testcase.input, testcase.output) {
|
||||||
|
t.Errorf("Expected output %+v did not match actual %+v", testcase.output, testcase.input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
Development = iota
|
||||||
|
Alpha
|
||||||
|
Beta
|
||||||
|
RC
|
||||||
|
Stable
|
||||||
|
)
|
||||||
|
|
||||||
|
func expandStability(stability string) string {
|
||||||
|
stability = strings.ToLower(stability)
|
||||||
|
|
||||||
|
switch stability {
|
||||||
|
case "a":
|
||||||
|
return "alpha"
|
||||||
|
case "b":
|
||||||
|
return "beta"
|
||||||
|
case "p":
|
||||||
|
return "patch"
|
||||||
|
case "pl":
|
||||||
|
return "patch"
|
||||||
|
case "rc":
|
||||||
|
return "RC"
|
||||||
|
}
|
||||||
|
|
||||||
|
return stability
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseStability(version string) string {
|
||||||
|
version = regexp.MustCompile(`(?i)#.+$`).ReplaceAllString(version, " ")
|
||||||
|
version = strings.ToLower(version)
|
||||||
|
|
||||||
|
if strings.HasPrefix(version, "dev-") || strings.HasSuffix(version, "-dev") {
|
||||||
|
return "dev"
|
||||||
|
}
|
||||||
|
|
||||||
|
result := RegFind(`(?i)^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?`+modifierRegex+`$`, version)
|
||||||
|
if result != nil {
|
||||||
|
if len(result) > 3 {
|
||||||
|
return "dev"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if result[1] != "" {
|
||||||
|
if "beta" == result[1] || "b" == result[1] {
|
||||||
|
return "beta"
|
||||||
|
}
|
||||||
|
if "alpha" == result[1] || "a" == result[1] {
|
||||||
|
return "alpha"
|
||||||
|
}
|
||||||
|
if "rc" == result[1] {
|
||||||
|
return "RC"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "stable"
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStability(version string) int {
|
||||||
|
result := RegFind(`(?i)(stable|RC|beta|alpha|dev)`, Normalize(version))
|
||||||
|
if len(result) == 0 {
|
||||||
|
return Stable
|
||||||
|
}
|
||||||
|
|
||||||
|
switch result[1] {
|
||||||
|
case "dev":
|
||||||
|
return Development
|
||||||
|
case "alpha":
|
||||||
|
return Alpha
|
||||||
|
case "beta":
|
||||||
|
return Beta
|
||||||
|
case "RC":
|
||||||
|
return RC
|
||||||
|
}
|
||||||
|
|
||||||
|
return Stable
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var stabilityValues = map[string]int{
|
||||||
|
"1.0": Stable,
|
||||||
|
"1.0-dev": Development,
|
||||||
|
"1.0-alpha": Alpha,
|
||||||
|
"1.0b1": Beta,
|
||||||
|
"1.0rc1": RC,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetStability(t *testing.T) {
|
||||||
|
for in, out := range stabilityValues {
|
||||||
|
if x := GetStability(in); x != out {
|
||||||
|
t.Errorf("FAIL: GetStability(%v) = %v: want %v", in, x, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
version "github.com/mcuadros/go-version"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Version string
|
||||||
|
|
||||||
|
type Release struct {
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
Assets []Asset `json:"assets"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Asset struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLatestRelease() (*Release, error) {
|
||||||
|
|
||||||
|
body, err := downloadFile("https://api.github.com/repos/liamg/aminal/releases/latest")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
release := Release{}
|
||||||
|
if err := json.Unmarshal(body, &release); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &release, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNewerRelease() (*Release, error) {
|
||||||
|
|
||||||
|
release, err := getLatestRelease()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if version.Compare(Version, release.TagName, "<") {
|
||||||
|
return release, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadFile(url string) ([]byte, error) {
|
||||||
|
|
||||||
|
spaceClient := http.Client{
|
||||||
|
Timeout: time.Second * 2, // Maximum of 2 secs
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := spaceClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ioutil.ReadAll(res.Body)
|
||||||
|
}
|
Loading…
Reference in New Issue