File size: 2,217 Bytes
fc11197 | 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 | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ir
import (
"testing"
)
func TestSplitPkg(t *testing.T) {
tests := []struct {
in string
pkg string
sym string
}{
{
in: "foo.Bar",
pkg: "foo",
sym: "Bar",
},
{
in: "foo/bar.Baz",
pkg: "foo/bar",
sym: "Baz",
},
{
in: "memeqbody",
pkg: "",
sym: "memeqbody",
},
{
in: `example%2ecom.Bar`,
pkg: `example%2ecom`,
sym: "Bar",
},
{
// Not a real generated symbol name, but easier to catch the general parameter form.
in: `foo.Bar[sync/atomic.Uint64]`,
pkg: `foo`,
sym: "Bar[sync/atomic.Uint64]",
},
{
in: `example%2ecom.Bar[sync/atomic.Uint64]`,
pkg: `example%2ecom`,
sym: "Bar[sync/atomic.Uint64]",
},
{
in: `gopkg.in/yaml%2ev3.Bar[sync/atomic.Uint64]`,
pkg: `gopkg.in/yaml%2ev3`,
sym: "Bar[sync/atomic.Uint64]",
},
{
// This one is a real symbol name.
in: `foo.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`,
pkg: `foo`,
sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]",
},
{
in: `example%2ecom.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`,
pkg: `example%2ecom`,
sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]",
},
{
in: `gopkg.in/yaml%2ev3.Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]`,
pkg: `gopkg.in/yaml%2ev3`,
sym: "Bar[go.shape.struct { sync/atomic._ sync/atomic.noCopy; sync/atomic._ sync/atomic.align64; sync/atomic.v uint64 }]",
},
}
for _, tc := range tests {
t.Run(tc.in, func(t *testing.T) {
pkg, sym := splitPkg(tc.in)
if pkg != tc.pkg {
t.Errorf("splitPkg(%q) got pkg %q want %q", tc.in, pkg, tc.pkg)
}
if sym != tc.sym {
t.Errorf("splitPkg(%q) got sym %q want %q", tc.in, sym, tc.sym)
}
})
}
}
|