Skip to content

Commit

Permalink
Renaming nul known value check (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Jan 15, 2024
1 parent 66f9b5c commit 6c773cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
18 changes: 8 additions & 10 deletions knownvalue/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@ import (
"fmt"
)

var _ Check = NullValue{}
var _ Check = nullExact{}

// NullValue is a Check for asserting equality between the value supplied
// to NullValueExact and the value passed to the CheckValue method.
type NullValue struct{}
type nullExact struct{}

// CheckValue determines whether the passed value is of nil.
func (v NullValue) CheckValue(other any) error {
func (v nullExact) CheckValue(other any) error {
if other != nil {
return fmt.Errorf("expected value nil for NullValue check, got: %T", other)
return fmt.Errorf("expected value nil for NullExact check, got: %T", other)
}

return nil
}

// String returns the string representation of nil.
func (v NullValue) String() string {
func (v nullExact) String() string {
return "nil"
}

// NullValueExact returns a Check for asserting equality nil
// NullExact returns a Check for asserting equality nil
// and the value passed to the CheckValue method.
func NullValueExact() NullValue {
return NullValue{}
func NullExact() nullExact {
return nullExact{}
}
15 changes: 9 additions & 6 deletions knownvalue/null_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ func TestNullValue_CheckValue(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
self knownvalue.NullValue
self knownvalue.Check
other any
expectedError error
}{
"zero-nil": {},
"zero-nil": {
self: knownvalue.NullExact(),
},
"zero-other": {
self: knownvalue.NullExact(),
other: nil, // checking against the underlying value field zero-value
},
"not-nil": {
self: knownvalue.NullValueExact(),
self: knownvalue.NullExact(),
other: false,
expectedError: fmt.Errorf("expected value nil for NullValue check, got: bool"),
expectedError: fmt.Errorf("expected value nil for NullExact check, got: bool"),
},
"equal": {
self: knownvalue.NullValueExact(),
self: knownvalue.NullExact(),
other: nil,
},
}
Expand All @@ -53,7 +56,7 @@ func TestNullValue_CheckValue(t *testing.T) {
func TestNullValue_String(t *testing.T) {
t.Parallel()

got := knownvalue.NullValueExact().String()
got := knownvalue.NullExact().String()

if diff := cmp.Diff(got, "nil"); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down

0 comments on commit 6c773cc

Please sign in to comment.