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

View as plain text