This repository has been archived by the owner on Jul 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_test.go
87 lines (75 loc) · 2.19 KB
/
import_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package humanize
import (
"reflect"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
var imprt1 = `
package test
// Doc
import (
"testing"
onn "github.com/fzerorubigd/onion"
_ "github.com/lib/pq"
// Other
. "github.com/smartystreets/goconvey/convey"
"github.com/fzerorubigd/annotate"
)
`
func TestImport(t *testing.T) {
Convey("Import test ", t, func() {
var p = &Package{}
f, err := ParseFile(imprt1, p)
So(err, ShouldBeNil)
p.Files = append(p.Files, f)
Convey("Import testing", func() {
i, err := p.FindImport("testing")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, "testing")
So(i.Path, ShouldEqual, "testing")
So(len(i.Docs), ShouldEqual, 1)
So(i.Docs[0], ShouldEqual, "// Doc")
})
Convey("Import onion", func() {
i, err := p.FindImport("onn")
So(err, ShouldBeNil)
i2, err := p.FindImport("github.com/fzerorubigd/onion")
So(err, ShouldBeNil)
So(reflect.DeepEqual(i, i2), ShouldBeTrue)
So(i.Name, ShouldEqual, "onn")
So(i.Path, ShouldEqual, "github.com/fzerorubigd/onion")
So(len(i.Docs), ShouldEqual, 1)
So(i.Docs[0], ShouldEqual, "// Doc")
})
Convey("Import pq", func() {
i, err := p.FindImport("github.com/lib/pq")
So(err, ShouldBeNil)
_, err = p.FindImport("_")
So(err, ShouldNotBeNil)
So(i.Name, ShouldEqual, "_")
So(i.Path, ShouldEqual, "github.com/lib/pq")
So(len(i.Docs), ShouldEqual, 1)
So(i.Docs[0], ShouldEqual, "// Doc")
})
Convey("Import convey", func() {
i, err := p.FindImport("github.com/smartystreets/goconvey/convey")
So(err, ShouldBeNil)
So(i.Name, ShouldEqual, ".")
So(i.Path, ShouldEqual, "github.com/smartystreets/goconvey/convey")
So(len(i.Docs), ShouldEqual, 2)
So(i.Docs[0], ShouldEqual, "// Doc")
So(i.Docs[1], ShouldEqual, "// Other")
})
Convey("Import annotate", func() {
i, err := p.FindImport("annotate")
So(err, ShouldBeNil)
i2, err := p.FindImport("github.com/fzerorubigd/annotate")
So(err, ShouldBeNil)
So(reflect.DeepEqual(i, i2), ShouldBeTrue)
So(i.Name, ShouldEqual, "annotate")
So(i.Path, ShouldEqual, "github.com/fzerorubigd/annotate")
So(len(i.Docs), ShouldEqual, 1)
So(i.Docs[0], ShouldEqual, "// Doc")
})
})
}