-
Notifications
You must be signed in to change notification settings - Fork 16
support "is nil" and "is not nil" and make "is empty" safer #129
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,6 +59,8 @@ const ( | |||||||||||||||||||||||||
| MatchIsNotEmpty | ||||||||||||||||||||||||||
| MatchMatches | ||||||||||||||||||||||||||
| MatchNotMatches | ||||||||||||||||||||||||||
| MatchIsNil | ||||||||||||||||||||||||||
| MatchIsNotNil | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| func (op MatchOperator) String() string { | ||||||||||||||||||||||||||
|
|
@@ -79,6 +81,10 @@ func (op MatchOperator) String() string { | |||||||||||||||||||||||||
| return "Matches" | ||||||||||||||||||||||||||
| case MatchNotMatches: | ||||||||||||||||||||||||||
| return "Not Matches" | ||||||||||||||||||||||||||
| case MatchIsNil: | ||||||||||||||||||||||||||
| return "Is Nil" | ||||||||||||||||||||||||||
| case MatchIsNotNil: | ||||||||||||||||||||||||||
| return "Not Nil" | ||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||
| return "UNKNOWN" | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
@@ -113,6 +119,12 @@ func (op MatchOperator) NotPresentDisposition() bool { | |||||||||||||||||||||||||
| case MatchNotMatches: | ||||||||||||||||||||||||||
| // M["x"] not matches <anything> is true. Nothing matches a missing key | ||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||
| case MatchIsNil: | ||||||||||||||||||||||||||
| // M["x"] is nil is true. Missing keys have no value. | ||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||
| case MatchIsNotNil: | ||||||||||||||||||||||||||
| // M["x"] is not nil is false. Missing keys have no value. | ||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||
|
Comment on lines
+122
to
+127
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Up front, I won't lose any sleep on this, but for pedantic conversation, I see this But a shrug isn't a bool, and I imagine that people holding this new expression will get the results they expect with these values as they are, so as I said, I won't lose sleep over it. With that, I do think the comment on
Suggested change
right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There are other cases where it the value could be nil, like a map where the values are other non-primitive types that are pointers under the hood, like maps or slices (i.e. I kind of think a lot of the existing behavior of this function is bogus. Ex. Definitely right on the comment though. 👍
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment fixed in 8a4f137 |
||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||
| // Should never be reached as every operator should explicitly define its | ||||||||||||||||||||||||||
| // behavior. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewers: not sure which version of
pigeonfixed this bug. We don't have the version pinned in this repo, but that's out of scope for this PR.