mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/types2: enable TestSelection API test
This test was never fully ported from go/types. Implement a conversion function from syntax.Pos to string index so that the test can be enabled again. Also renamed the local variable syntax to segment to avoid confusion with the syntax package. Change-Id: I1b34e50ec138403798efb14c828545780f565507 Reviewed-on: https://go-review.googlesource.com/c/go/+/344253 Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
parent
5d5e50c3db
commit
8fcc614360
1 changed files with 24 additions and 22 deletions
|
|
@ -17,10 +17,6 @@ import (
|
||||||
. "cmd/compile/internal/types2"
|
. "cmd/compile/internal/types2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func unimplemented() {
|
|
||||||
panic("unimplemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
// genericPkg is a source prefix for packages that contain generic code.
|
// genericPkg is a source prefix for packages that contain generic code.
|
||||||
const genericPkg = "package generic_"
|
const genericPkg = "package generic_"
|
||||||
|
|
||||||
|
|
@ -1168,8 +1164,6 @@ func (m testImporter) Import(path string) (*Package, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSelection(t *testing.T) {
|
func TestSelection(t *testing.T) {
|
||||||
t.Skip("requires fixes around source positions")
|
|
||||||
|
|
||||||
selections := make(map[*syntax.SelectorExpr]*Selection)
|
selections := make(map[*syntax.SelectorExpr]*Selection)
|
||||||
|
|
||||||
imports := make(testImporter)
|
imports := make(testImporter)
|
||||||
|
|
@ -1293,11 +1287,9 @@ func main() {
|
||||||
for e, sel := range selections {
|
for e, sel := range selections {
|
||||||
_ = sel.String() // assertion: must not panic
|
_ = sel.String() // assertion: must not panic
|
||||||
|
|
||||||
unimplemented()
|
start := indexFor(mainSrc, syntax.StartPos(e))
|
||||||
_ = e
|
end := indexFor(mainSrc, syntax.EndPos(e))
|
||||||
// start := fset.Position(e.Pos()).Offset
|
segment := mainSrc[start:end] // (all SelectorExprs are in main, not lib)
|
||||||
// end := fset.Position(e.End()).Offset
|
|
||||||
// syntax := mainSrc[start:end] // (all SelectorExprs are in main, not lib)
|
|
||||||
|
|
||||||
direct := "."
|
direct := "."
|
||||||
if sel.Indirect() {
|
if sel.Indirect() {
|
||||||
|
|
@ -1307,13 +1299,11 @@ func main() {
|
||||||
sel.String(),
|
sel.String(),
|
||||||
fmt.Sprintf("%s%v", direct, sel.Index()),
|
fmt.Sprintf("%s%v", direct, sel.Index()),
|
||||||
}
|
}
|
||||||
unimplemented()
|
want := wantOut[segment]
|
||||||
_ = got
|
if want != got {
|
||||||
// want := wantOut[syntax]
|
t.Errorf("%s: got %q; want %q", segment, got, want)
|
||||||
// if want != got {
|
}
|
||||||
// t.Errorf("%s: got %q; want %q", syntax, got, want)
|
delete(wantOut, segment)
|
||||||
// }
|
|
||||||
// delete(wantOut, syntax)
|
|
||||||
|
|
||||||
// We must explicitly assert properties of the
|
// We must explicitly assert properties of the
|
||||||
// Signature's receiver since it doesn't participate
|
// Signature's receiver since it doesn't participate
|
||||||
|
|
@ -1323,19 +1313,31 @@ func main() {
|
||||||
got := sig.Recv().Type()
|
got := sig.Recv().Type()
|
||||||
want := sel.Recv()
|
want := sel.Recv()
|
||||||
if !Identical(got, want) {
|
if !Identical(got, want) {
|
||||||
unimplemented()
|
t.Errorf("%s: Recv() = %s, want %s", segment, got, want)
|
||||||
// t.Errorf("%s: Recv() = %s, want %s", syntax, got, want)
|
|
||||||
}
|
}
|
||||||
} else if sig != nil && sig.Recv() != nil {
|
} else if sig != nil && sig.Recv() != nil {
|
||||||
t.Errorf("%s: signature has receiver %s", sig, sig.Recv().Type())
|
t.Errorf("%s: signature has receiver %s", sig, sig.Recv().Type())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Assert that all wantOut entries were used exactly once.
|
// Assert that all wantOut entries were used exactly once.
|
||||||
for syntax := range wantOut {
|
for segment := range wantOut {
|
||||||
t.Errorf("no syntax.Selection found with syntax %q", syntax)
|
t.Errorf("no syntax.Selection found with syntax %q", segment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// indexFor returns the index into s corresponding to the position pos.
|
||||||
|
func indexFor(s string, pos syntax.Pos) int {
|
||||||
|
i, line := 0, 1 // string index and corresponding line
|
||||||
|
target := int(pos.Line())
|
||||||
|
for line < target && i < len(s) {
|
||||||
|
if s[i] == '\n' {
|
||||||
|
line++
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return i + int(pos.Col()-1) // columns are 1-based
|
||||||
|
}
|
||||||
|
|
||||||
func TestIssue8518(t *testing.T) {
|
func TestIssue8518(t *testing.T) {
|
||||||
imports := make(testImporter)
|
imports := make(testImporter)
|
||||||
conf := Config{
|
conf := Config{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue