Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename to AllDefined and AllSpecified #1

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func (e *Enum[T]) ShortName() string {
return ret
}

// AllValues returns all declared values of the enum type.
// AllDefined returns all defined values of the enum type.
// It includes the zero (_UNSPECIFIED) value.
func (e *Enum[T]) AllValues() []T {
func (e *Enum[T]) AllDefined() []T {
typ := e.inner.Type()
values := typ.Descriptor().Values()
ret := make([]T, 0, values.Len())
Expand All @@ -58,9 +58,9 @@ func (e *Enum[T]) AllValues() []T {
return ret
}

// SpecifiedValues returns all specified values of the enum type.
// AllSpecified returns all specified values of the enum type.
// It excludes the zero (_UNSPECIFIED) value.
func (e *Enum[T]) SpecifiedValues() []T {
func (e *Enum[T]) AllSpecified() []T {
typ := e.inner.Type()
values := typ.Descriptor().Values()
ret := make([]T, 0, values.Len()-1)
Expand Down
16 changes: 8 additions & 8 deletions enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ func TestEnum_ShortName(t *testing.T) {
})
}

func TestEnum_AllValues(t *testing.T) {
func TestEnum_AllDefined(t *testing.T) {
t.Run("TestEnumType", func(t *testing.T) {
values := NewEnum[dummyv1.TestEnumType]().AllValues()
values := NewEnum[dummyv1.TestEnumType]().AllDefined()
assert.Len(t, values, 7)
})
t.Run("TestEnum2Type", func(t *testing.T) {
values := NewEnum[dummyv1.TestEnumType2]().AllValues()
values := NewEnum[dummyv1.TestEnumType2]().AllDefined()
assert.Len(t, values, 3)
})
t.Run("TestUnorderedEnumType", func(t *testing.T) {
values := NewEnum[dummyv1.TestUnorderedEnumType]().AllValues()
values := NewEnum[dummyv1.TestUnorderedEnumType]().AllDefined()
assert.Equal(t, []dummyv1.TestUnorderedEnumType{
dummyv1.TestUnorderedEnumType_TEST_UNORDERED_ENUM_TYPE_UNSPECIFIED,
dummyv1.TestUnorderedEnumType_TEST_UNORDERED_ENUM_TYPE_BAR,
Expand All @@ -122,17 +122,17 @@ func TestEnum_AllValues(t *testing.T) {
})
}

func TestEnum_SpecifiedValues(t *testing.T) {
func TestEnum_AllSpecified(t *testing.T) {
t.Run("TestEnumType", func(t *testing.T) {
values := NewEnum[dummyv1.TestEnumType]().SpecifiedValues()
values := NewEnum[dummyv1.TestEnumType]().AllSpecified()
assert.Len(t, values, 6)
})
t.Run("TestEnum2Type", func(t *testing.T) {
values := NewEnum[dummyv1.TestEnumType2]().SpecifiedValues()
values := NewEnum[dummyv1.TestEnumType2]().AllSpecified()
assert.Len(t, values, 2)
})
t.Run("TestUnorderedEnumType", func(t *testing.T) {
values := NewEnum[dummyv1.TestUnorderedEnumType]().SpecifiedValues()
values := NewEnum[dummyv1.TestUnorderedEnumType]().AllSpecified()
assert.Equal(t, []dummyv1.TestUnorderedEnumType{
dummyv1.TestUnorderedEnumType_TEST_UNORDERED_ENUM_TYPE_BAR,
dummyv1.TestUnorderedEnumType_TEST_UNORDERED_ENUM_TYPE_FOO,
Expand Down
Loading