github.com/whiteCcinn/protobuf-go@v1.0.9/testing/prototest/enum.go (about)

     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  	"github.com/whiteCcinn/protobuf-go/reflect/protoreflect"
    11  )
    12  
    13  // Enum tests an 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  }