Source file src/go/types/errors_test.go

     1  // Copyright 2020 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 types
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestError(t *testing.T) {
    12  	var err error_
    13  	want := "no error"
    14  	if got := err.String(); got != want {
    15  		t.Errorf("empty error: got %q, want %q", got, want)
    16  	}
    17  
    18  	want = "0: foo 42"
    19  	err.errorf(nopos, "foo %d", 42)
    20  	if got := err.String(); got != want {
    21  		t.Errorf("simple error: got %q, want %q", got, want)
    22  	}
    23  
    24  	want = "0: foo 42\n\tbar 43"
    25  	err.errorf(nopos, "bar %d", 43)
    26  	if got := err.String(); got != want {
    27  		t.Errorf("simple error: got %q, want %q", got, want)
    28  	}
    29  }
    30  
    31  func TestStripAnnotations(t *testing.T) {
    32  	for _, test := range []struct {
    33  		in, want string
    34  	}{
    35  		{"", ""},
    36  		{"   ", "   "},
    37  		{"foo", "foo"},
    38  		{"foo₀", "foo"},
    39  		{"foo(T₀)", "foo(T)"},
    40  	} {
    41  		got := stripAnnotations(test.in)
    42  		if got != test.want {
    43  			t.Errorf("%q: got %q; want %q", test.in, got, test.want)
    44  		}
    45  	}
    46  }
    47  

View as plain text