...

Source file src/google.golang.org/protobuf/reflect/protoreflect/source_test.go

Documentation: google.golang.org/protobuf/reflect/protoreflect

     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 protoreflect
     6  
     7  import "testing"
     8  
     9  func TestSourcePathString(t *testing.T) {
    10  	tests := []struct {
    11  		in   SourcePath
    12  		want string
    13  	}{
    14  		{nil, ""},
    15  		{SourcePath{}, ""},
    16  		{SourcePath{0}, ".0"},
    17  		{SourcePath{1}, ".name"},
    18  		{SourcePath{1, 1}, ".name.1"},
    19  		{SourcePath{1, 1, -2, 3}, ".name.1.-2.3"},
    20  		{SourcePath{3}, ".dependency"},
    21  		{SourcePath{3, 0}, ".dependency[0]"},
    22  		{SourcePath{3, -1}, ".dependency.-1"},
    23  		{SourcePath{3, 1, 2}, ".dependency[1].2"},
    24  		{SourcePath{4}, ".message_type"},
    25  		{SourcePath{4, 0}, ".message_type[0]"},
    26  		{SourcePath{4, -1}, ".message_type.-1"},
    27  		{SourcePath{4, 1, 0}, ".message_type[1].0"},
    28  		{SourcePath{4, 1, 1}, ".message_type[1].name"},
    29  	}
    30  	for _, tt := range tests {
    31  		if got := tt.in.String(); got != tt.want {
    32  			t.Errorf("SourcePath(%d).String() = %v, want %v", tt.in, got, tt.want)
    33  		}
    34  	}
    35  }
    36  

View as plain text