-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpn_test.go
48 lines (38 loc) · 898 Bytes
/
cpn_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package pkgcraft_test
import (
"testing"
"github.com/stretchr/testify/assert"
. "github.com/pkgcraft/pkgcraft-go"
)
func TestNewCpn(t *testing.T) {
var cpn *Cpn
var err error
// valid
cpn, err = NewCpn("cat/pkg")
assert.Nil(t, err)
assert.Equal(t, cpn.Category(), "cat")
assert.Equal(t, cpn.Package(), "pkg")
cpn, err = NewCpn("cat/pkg-1-a")
assert.Nil(t, err)
assert.Equal(t, cpn.Category(), "cat")
assert.Equal(t, cpn.Package(), "pkg-1-a")
// invalid
_, err = NewCpn("cat/pkg-1")
assert.NotNil(t, err)
_, err = NewCpn("=cat/pkg-1-r2")
assert.NotNil(t, err)
}
func TestCpnCmp(t *testing.T) {
// c1 < c2
c1, _ := NewCpn("a/b")
c2, _ := NewCpn("a/c")
assert.Equal(t, c1.Cmp(c2), -1)
// c1 == c2
c1, _ = NewCpn("a/b")
c2, _ = NewCpn("a/b")
assert.Equal(t, c1.Cmp(c2), 0)
// c1 > c2
c1, _ = NewCpn("b/a")
c2, _ = NewCpn("a/b")
assert.Equal(t, c1.Cmp(c2), 1)
}