...

Source file src/google.golang.org/protobuf/testing/prototest/enum.go

Documentation: google.golang.org/protobuf/testing/prototest

     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 prototest
     6  
     7  import (
     8  	"testing"
     9  
    10  	"google.golang.org/protobuf/reflect/protoreflect"
    11  )
    12  
    13  // Enum tests an [protoreflect.EnumType] implementation.
    14  type Enum struct{}
    15  
    16  func (test Enum) Test(t testing.TB, et protoreflect.EnumType) {
    17  	ed := et.Descriptor()
    18  	values := ed.Values()
    19  	for i := 0; i < values.Len(); i++ {
    20  		evd := values.Get(i)
    21  		num := evd.Number()
    22  		e := et.New(num)
    23  		if e.Descriptor() != ed {
    24  			t.Errorf("enumType.New(%v).Descriptor() != enumType.Descriptor(), should match", num)
    25  		}
    26  		if e.Type() != et {
    27  			t.Errorf("enumType.New(%v).Type() != enumType, should match", num)
    28  		}
    29  		if got, want := e.Number(), num; got != want {
    30  			t.Errorf("enumType.New(%v).Number() = %v, want %v", num, got, want)
    31  		}
    32  	}
    33  }
    34  

View as plain text