github.com/v2fly/tools@v0.100.0/internal/lsp/cmd/test/implementation.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 cmdtest
     6  
     7  import (
     8  	"fmt"
     9  	"sort"
    10  	"testing"
    11  
    12  	"github.com/v2fly/tools/internal/span"
    13  )
    14  
    15  func (r *runner) Implementation(t *testing.T, spn span.Span, imps []span.Span) {
    16  	var itemStrings []string
    17  	for _, i := range imps {
    18  		itemStrings = append(itemStrings, fmt.Sprint(i))
    19  	}
    20  	sort.Strings(itemStrings)
    21  	var expect string
    22  	for _, i := range itemStrings {
    23  		expect += i + "\n"
    24  	}
    25  	expect = r.Normalize(expect)
    26  
    27  	uri := spn.URI()
    28  	filename := uri.Filename()
    29  	target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column())
    30  
    31  	got, stderr := r.NormalizeGoplsCmd(t, "implementation", target)
    32  	if stderr != "" {
    33  		t.Errorf("implementation failed for %s: %s", target, stderr)
    34  	} else if expect != got {
    35  		t.Errorf("implementation failed for %s expected:\n%s\ngot:\n%s", target, expect, got)
    36  	}
    37  }