1
2
3
4
5 package ir
6
7 import (
8 "testing"
9 )
10
11 func TestSplitPkg(t *testing.T) {
12 tests := []struct {
13 in string
14 pkg string
15 sym string
16 }{
17 {
18 in: "foo.Bar",
19 pkg: "foo",
20 sym: "Bar",
21 },
22 {
23 in: "foo/bar.Baz",
24 pkg: "foo/bar",
25 sym: "Baz",
26 },
27 {
28 in: "memeqbody",
29 pkg: "",
30 sym: "memeqbody",
31 },
32 {
33 in: `example%2ecom.Bar`,
34 pkg: `example%2ecom`,
35 sym: "Bar",
36 },
37 {
38
39 in: `foo.Bar[sync/atomic.Uint64]`,
40 pkg: `foo`,
41 sym: "Bar[sync/atomic.Uint64]",
42 },
43 {
44 in: `example%2ecom.Bar[sync/atomic.Uint64]`,
45 pkg: `example%2ecom`,
46 sym: "Bar[sync/atomic.Uint64]",
47 },
48 {
49 in: `gopkg.in/yaml%2ev3.Bar[sync/atomic.Uint64]`,
50 pkg: `gopkg.in/yaml%2ev3`,
51 sym: "Bar[sync/atomic.Uint64]",
52 },
53 {
54
55 in: `foo.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`,
56 pkg: `foo`,
57 sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]",
58 },
59 {
60 in: `example%2ecom.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`,
61 pkg: `example%2ecom`,
62 sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]",
63 },
64 {
65 in: `gopkg.in/yaml%2ev3.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`,
66 pkg: `gopkg.in/yaml%2ev3`,
67 sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]",
68 },
69 }
70
71 for _, tc := range tests {
72 t.Run(tc.in, func(t *testing.T) {
73 pkg, sym := splitPkg(tc.in)
74 if pkg != tc.pkg {
75 t.Errorf("splitPkg(%q) got pkg %q want %q", tc.in, pkg, tc.pkg)
76 }
77 if sym != tc.sym {
78 t.Errorf("splitPkg(%q) got sym %q want %q", tc.in, sym, tc.sym)
79 }
80 })
81 }
82 }
83
View as plain text