...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package astutil
16
17 import (
18 "path"
19 "testing"
20
21 "cuelang.org/go/cue/ast"
22 "github.com/google/go-cmp/cmp"
23 )
24
25 func TestImportInfo(t *testing.T) {
26 testCases := []struct {
27 name string
28 path string
29 want ImportInfo
30 }{
31 {"", "a.b/bar", ImportInfo{
32 Ident: "bar",
33 PkgName: "bar",
34 ID: "a.b/bar",
35 Dir: "a.b/bar",
36 }},
37 {"foo", "a.b/bar", ImportInfo{
38 Ident: "foo",
39 PkgName: "bar",
40 ID: "a.b/bar",
41 Dir: "a.b/bar",
42 }},
43 {"", "a.b/bar:foo", ImportInfo{
44 Ident: "foo",
45 PkgName: "foo",
46 ID: "a.b/bar:foo",
47 Dir: "a.b/bar",
48 }},
49 {"", "strings", ImportInfo{
50 Ident: "strings",
51 PkgName: "strings",
52 ID: "strings",
53 Dir: "strings",
54 }},
55 }
56 for _, tc := range testCases {
57 t.Run(path.Join(tc.name, tc.path), func(t *testing.T) {
58 var ident *ast.Ident
59 if tc.name != "" {
60 ident = ast.NewIdent(tc.name)
61 }
62 got, err := ParseImportSpec(&ast.ImportSpec{
63 Name: ident,
64 Path: ast.NewString(tc.path),
65 })
66 if err != nil {
67 t.Fatal(err)
68 }
69 if diff := cmp.Diff(got, tc.want); diff != "" {
70 t.Error(diff)
71 }
72 })
73 }
74 }
75
View as plain text