fix #1056, extract: replace the code for get package name.

fix #1056
This commit is contained in:
エガオノキミヘ
2021-03-23 17:30:04 +08:00
committed by GitHub
parent ec5392d566
commit 84ad46751a
5 changed files with 24 additions and 3 deletions

View File

@@ -16,7 +16,6 @@ import (
"io"
"math/big"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
@@ -167,8 +166,8 @@ func (e *Extractor) genContent(importPath string, p *types.Package) ([]byte, err
continue
}
pname := path.Base(importPath) + "." + name
if rname := path.Base(importPath) + name; restricted[rname] {
pname := p.Name() + "." + name
if rname := p.Name() + name; restricted[rname] {
// Restricted symbol, locally provided by stdlib wrapper.
pname = rname
}

View File

@@ -78,6 +78,13 @@ func TestPackages(t *testing.T) {
importPath: "guthib.com/baz",
expected: expectedOutput,
},
{
desc: "using relative path, package name is not same as import path",
wd: "./testdata/6/src/guthib.com/bar",
arg: "../baz-baz",
importPath: "guthib.com/baz",
expected: expectedOutput,
},
}
for _, test := range testCases {

View File

@@ -0,0 +1,9 @@
package main
import (
"guthib.com/baz"
)
func main() {
baz.Hello()
}

View File

@@ -0,0 +1,5 @@
package baz
func Hello() {
println("HELLO")
}

View File

@@ -0,0 +1 @@
module guthib.com/baz-baz