This repository has been archived by the owner on May 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
parser_test.go
73 lines (63 loc) · 1.66 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package module_test
import (
"reflect"
"testing"
module "github.com/uudashr/go-module"
)
func TestParse(t *testing.T) {
in := `
module my/thing
require other/thing v1.0.2
require (
new/thing v2.3.4
other/new/thing v1.2.3
)
exclude old/thing v1.2.3
exclude (
bad/thing v1.0.0
new/bad/thing v2.2.3
)
replace bad/thing v1.4.5 => good/thing v1.4.5
replace (
bad/thing v1.0.0 => good/thing v1.0.0
new/bad/thing v2.2.3 => new/good/thing v2.2.3
)
`
expectReqs := []module.Package{
{Path: "other/thing", Version: "v1.0.2"},
{Path: "new/thing", Version: "v2.3.4"},
{Path: "other/new/thing", Version: "v1.2.3"},
}
expectExcl := []module.Package{
{Path: "old/thing", Version: "v1.2.3"},
{Path: "bad/thing", Version: "v1.0.0"},
{Path: "new/bad/thing", Version: "v2.2.3"},
}
expectRepl := []module.PackageMap{
{
From: module.Package{Path: "bad/thing", Version: "v1.4.5"},
To: module.Package{Path: "good/thing", Version: "v1.4.5"},
},
{
From: module.Package{Path: "bad/thing", Version: "v1.0.0"},
To: module.Package{Path: "good/thing", Version: "v1.0.0"},
},
{
From: module.Package{Path: "new/bad/thing", Version: "v2.2.3"},
To: module.Package{Path: "new/good/thing", Version: "v2.2.3"},
},
}
m, err := module.ParseInString(in)
if err != nil {
t.Fatal(err)
}
if got, want := m.Requires, expectReqs; !reflect.DeepEqual(got, want) {
t.Error("got:", got, "want:", want)
}
if got, want := m.Excludes, expectExcl; !reflect.DeepEqual(got, want) {
t.Error("got:", got, "want:", want)
}
if got, want := m.Replaces, expectRepl; !reflect.DeepEqual(got, want) {
t.Error("got:", got, "want:", want)
}
}