github.com/april1989/origin-go-tools@v0.0.32/internal/lsp/cache/error_test.go (about) 1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package cache 6 7 import ( 8 "strings" 9 "testing" 10 ) 11 12 func TestParseErrorMessage(t *testing.T) { 13 tests := []struct { 14 name string 15 in string 16 expectedFileName string 17 expectedLine int 18 expectedColumn int 19 }{ 20 { 21 name: "from go list output", 22 in: "\nattributes.go:13:1: expected 'package', found 'type'", 23 expectedFileName: "attributes.go", 24 expectedLine: 13, 25 expectedColumn: 1, 26 }, 27 } 28 29 for _, tt := range tests { 30 t.Run(tt.name, func(t *testing.T) { 31 spn := parseGoListError(tt.in) 32 fn := spn.URI().Filename() 33 34 if !strings.HasSuffix(fn, tt.expectedFileName) { 35 t.Errorf("expected filename with suffix %v but got %v", tt.expectedFileName, fn) 36 } 37 38 if !spn.HasPosition() { 39 t.Fatalf("expected span to have position") 40 } 41 42 pos := spn.Start() 43 if pos.Line() != tt.expectedLine { 44 t.Errorf("expected line %v but got %v", tt.expectedLine, pos.Line()) 45 } 46 47 if pos.Column() != tt.expectedColumn { 48 t.Errorf("expected line %v but got %v", tt.expectedLine, pos.Line()) 49 } 50 }) 51 } 52 }