forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
54 lines (44 loc) · 1.1 KB
/
parser_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
49
50
51
52
53
54
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package version
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewDefaultParser(t *testing.T) {
p := NewDefaultParser()
v, err := p.Parse("ava/1.2.3")
assert.NoError(t, err)
assert.NotNil(t, v)
assert.Equal(t, "ava/1.2.3", v.String())
assert.Equal(t, "ava", v.App())
assert.Equal(t, 1, v.Major())
assert.Equal(t, 2, v.Minor())
assert.Equal(t, 3, v.Patch())
assert.NoError(t, v.Compatible(v))
assert.False(t, v.Before(v))
badVersions := []string{
"",
"ava/",
"ava/z.0.0",
"ava/0.z.0",
"ava/0.0.z",
}
for _, badVersion := range badVersions {
_, err := p.Parse(badVersion)
assert.Error(t, err)
}
}
func TestNewParser(t *testing.T) {
p := NewParser(":", ",")
v, err := p.Parse("ava:1,2,3")
assert.NoError(t, err)
assert.NotNil(t, v)
assert.Equal(t, "ava:1,2,3", v.String())
assert.Equal(t, "ava", v.App())
assert.Equal(t, 1, v.Major())
assert.Equal(t, 2, v.Minor())
assert.Equal(t, 3, v.Patch())
assert.NoError(t, v.Compatible(v))
assert.False(t, v.Before(v))
}