-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadpath_test.go
41 lines (35 loc) · 972 Bytes
/
loadpath_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
package goref_test
import (
"fmt"
"go/ast"
"testing"
"github.com/korfuri/goref"
"github.com/stretchr/testify/assert"
)
func TestCleanImportSpec(t *testing.T) {
assert.Equal(t, "foo/bar/baz", goref.CleanImportSpec(&ast.ImportSpec{Path: &ast.BasicLit{Value: "foo/bar/baz"}}))
assert.Equal(t, "foo/bar/baz", goref.CleanImportSpec(&ast.ImportSpec{Path: &ast.BasicLit{Value: "\"foo/bar/baz\""}}))
}
func ExampleCleanImportSpec() {
fmt.Println(goref.CleanImportSpec(&ast.ImportSpec{Path: &ast.BasicLit{Value: "\"foo/bar/baz\""}}))
// Output: foo/bar/baz
}
func TestCandidatePaths(t *testing.T) {
r := []string{
"a/b/vendor/c/d",
"a/vendor/c/d",
"vendor/c/d",
"c/d",
}
assert.Equal(t, r, goref.CandidatePaths("c/d", "a/b"))
}
func ExampleCandidatePaths() {
for _, p := range goref.CandidatePaths("lib/util", "program/bin") {
fmt.Println(p)
}
// Output:
// program/bin/vendor/lib/util
// program/vendor/lib/util
// vendor/lib/util
// lib/util
}