mirror of
https://github.com/golang/go
synced 2024-11-05 17:06:13 -07:00
747b8b11d4
This change adds a source.Error type which is used to collect the error information that comes out of the loading, parsing, and type checking stages. We also add specific sources per-error, rather than having them all be labeled as "LSP". This change will enable follow-ups that do a better job of extracting error ranges. Change-Id: I3fbb5e42d66aa2c5bb1b2f41d1eadfc45f3a749b Reviewed-on: https://go-review.googlesource.com/c/tools/+/202298 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
// Copyright 2019 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 cache
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseErrorMessage(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
in string
|
|
expectedFileName string
|
|
expectedLine int
|
|
expectedColumn int
|
|
}{
|
|
{
|
|
name: "from go list output",
|
|
in: "\nattributes.go:13:1: expected 'package', found 'type'",
|
|
expectedFileName: "attributes.go",
|
|
expectedLine: 13,
|
|
expectedColumn: 1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
spn := parseGoListError(tt.in)
|
|
fn := spn.URI().Filename()
|
|
|
|
if !strings.HasSuffix(fn, tt.expectedFileName) {
|
|
t.Errorf("expected filename with suffix %v but got %v", tt.expectedFileName, fn)
|
|
}
|
|
|
|
if !spn.HasPosition() {
|
|
t.Fatalf("expected span to have position")
|
|
}
|
|
|
|
pos := spn.Start()
|
|
if pos.Line() != tt.expectedLine {
|
|
t.Errorf("expected line %v but got %v", tt.expectedLine, pos.Line())
|
|
}
|
|
|
|
if pos.Column() != tt.expectedColumn {
|
|
t.Errorf("expected line %v but got %v", tt.expectedLine, pos.Line())
|
|
}
|
|
})
|
|
}
|
|
}
|