Arch Linux helpers and parsers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

96 lines
2.2 KiB

package version
import "testing"
func TestOperatorStrict(t *testing.T) {
var tests = []struct {
String string
Operator
}{
{"", None},
{"<", LessThan},
{"<=", LessThenOrEqualTo},
{"=", EqualTo},
{">=", MoreThanOrEqualTo},
{">", MoreThan},
}
for _, test := range tests {
op, err := ParseOperator(test.String)
if err != nil {
t.Fatal(err)
}
if op != test.Operator {
t.Fatalf(`expected operator %q, got %q`, test.Operator, op)
}
}
}
func TestOperatorStrictError(t *testing.T) {
var tests = []string{
"foo",
"foo<",
"<>",
"=>",
}
for _, test := range tests {
if _, err := ParseOperator(test); err == nil {
t.Fatalf(`invalid operator %q passed`, test)
}
}
}
func TestDependency(t *testing.T) {
var tests = []struct {
String string
Name string
Dependency
Output string
}{
{"perl", "perl", Dependency{}, ""},
{"perl<5.27", "perl", Dependency{LessThan, Version{Version: "5.27"}}, "<5.27"},
{"perl>=5.26", "perl", Dependency{MoreThanOrEqualTo, Version{Version: "5.26"}}, ">=5.26"},
{"python>3.4: perl is no good", "python", Dependency{MoreThan, Version{Version: "3.4"}}, ">3.4"},
}
for _, test := range tests {
t.Run(test.String, func(t *testing.T) {
name, dep, err := ParseDependency(test.String)
if err != nil {
t.Fatal(err)
}
if name != test.Name {
t.Fatalf(`expected name %q, got %q`, test.Name, name)
}
if cmp := Compare(test.Version, dep.Version); cmp != 0 {
t.Fatalf(`expected version %q, got %q (%d)`, test.Version, dep.Version, cmp)
}
if s := dep.String(); s != test.Output {
t.Fatalf(`expected string %q, got %q`, test.Output, s)
}
})
}
}
func TestDependencyMatch(t *testing.T) {
_, dep, err := ParseDependency(">=1.2")
if err != nil {
t.Fatal(err)
}
var (
testsa = []string{"1.2", "1.2.1", "2"}
testsb = []string{"1.1", "1.0", "0", "1.alpha"}
)
for _, test := range testsa {
t.Run(test+dep.String(), func(t *testing.T) {
if !dep.Match(Parse(test)) {
t.Fatalf(`expected %q to match >=1.2`, test)
}
})
}
for _, test := range testsb {
t.Run("!"+test+dep.String(), func(t *testing.T) {
if dep.Match(Parse(test)) {
t.Fatalf(`expected %q to not match >=1.2`, test)
}
})
}
}