...

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

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

     1  // Copyright 2018 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 TestNameIsValid(t *testing.T) {
    10  	tests := []struct {
    11  		in   Name
    12  		want bool
    13  	}{
    14  		{"", false},
    15  		{"a", true},
    16  		{".", false},
    17  		{"_", true}, // odd, but permitted by protoc
    18  		{".foo", false},
    19  		{"foo.", false},
    20  		{"foo", true},
    21  		{"one1_two2_three3", true},
    22  		{"1one", false},
    23  	}
    24  
    25  	for _, tt := range tests {
    26  		if got := tt.in.IsValid(); got != tt.want {
    27  			t.Errorf("Name(%q).IsValid() = %v, want %v", tt.in, got, tt.want)
    28  		}
    29  	}
    30  }
    31  
    32  func TestFullNameIsValid(t *testing.T) {
    33  	tests := []struct {
    34  		in   FullName
    35  		want bool
    36  	}{
    37  		{"", false},
    38  		{"a", true},
    39  		{"a.b", true},
    40  		{"a.b.c", true},
    41  		{".", false},
    42  		{"_._._", true}, // odd, but permitted by protoc
    43  		{".foo", false},
    44  		{"foo.", false},
    45  		{"foo", true},
    46  		{"one1_two2_three3", true},
    47  		{"one1.two2.three3", true},
    48  		{".one1.two2.three3", false},
    49  		{"one1.two2.three3.", false},
    50  		{"foo.1one", false},
    51  	}
    52  
    53  	for _, tt := range tests {
    54  		if got := tt.in.IsValid(); got != tt.want {
    55  			t.Errorf("Name(%q).IsValid() = %v, want %v", tt.in, got, tt.want)
    56  		}
    57  	}
    58  }
    59  
    60  func TestNameAppend(t *testing.T) {
    61  	tests := []FullName{
    62  		"",
    63  		"a",
    64  		"a.b",
    65  		"a.b.c",
    66  		"one1.two2.three3",
    67  	}
    68  
    69  	for _, tt := range tests {
    70  		if got := tt.Parent().Append(tt.Name()); got != tt {
    71  			t.Errorf("FullName.Parent().Append(FullName.Name()) = %q, want %q", got, tt)
    72  		}
    73  	}
    74  }
    75  
    76  var sink bool
    77  
    78  func BenchmarkFullNameIsValid(b *testing.B) {
    79  	for i := 0; i < b.N; i++ {
    80  		sink = FullName("google.protobuf.Any").IsValid()
    81  	}
    82  }
    83  

View as plain text