mirror of
https://github.com/golang/go
synced 2024-11-19 02:04:42 -07:00
e88138204b
We panic if the uri was not a valid file uri instead They always are a valid file URI, and we would fail miserably to cope if they were not anyway, and there are lots of places where we need to be able to get the filename and don't want to cope with an error that cannot occur. If we ever have not file uri's, you will have to check if it is a file before calling .Filename, which seems reasonable anyway. Change-Id: Ifb26a165bd43c2d310378314550b5749b09e2ebd Reviewed-on: https://go-review.googlesource.com/c/tools/+/181017 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
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 source
|
|
|
|
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 := parseDiagnosticMessage(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())
|
|
}
|
|
})
|
|
}
|
|
}
|