-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for null comparisons to conformance
- Loading branch information
Showing
4 changed files
with
542 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package conformance | ||
|
||
import "fmt" | ||
|
||
type NullValue struct { | ||
raw string | ||
} | ||
|
||
func NewNullValue(raw string) *NullValue { | ||
return &NullValue{raw: raw} | ||
} | ||
|
||
func (fv NullValue) ASCIIDocString() string { | ||
return fv.raw | ||
} | ||
|
||
func (fv NullValue) Description() string { | ||
return fv.raw | ||
} | ||
|
||
func (fv *NullValue) Compare(context Context, other ComparisonValue, op ComparisonOperator) (bool, error) { | ||
switch op { | ||
case ComparisonOperatorEqual: | ||
switch other.(type) { | ||
case nil, *NullValue: | ||
return true, nil | ||
default: | ||
return false, nil | ||
} | ||
case ComparisonOperatorNotEqual: | ||
switch other.(type) { | ||
case nil, *NullValue: | ||
return false, nil | ||
default: | ||
return true, nil | ||
} | ||
default: | ||
return false, fmt.Errorf("invalid operator with null value: %s", op.String()) | ||
} | ||
} | ||
|
||
func (fv NullValue) Value(context Context) (any, error) { | ||
return nil, nil | ||
} | ||
|
||
func (fv *NullValue) Equal(ofv ComparisonValue) bool { | ||
if ofv == nil { | ||
return fv == nil | ||
} else if fv == nil { | ||
return false | ||
} | ||
_, ok := ofv.(*NullValue) | ||
return !ok | ||
} | ||
|
||
func (fv NullValue) Clone() ComparisonValue { | ||
return &NullValue{raw: fv.raw} | ||
} |
Oops, something went wrong.