-
Notifications
You must be signed in to change notification settings - Fork 6
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
Equal operator typed helpers #62
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,51 @@ | ||
package filter | ||
|
||
import "time" | ||
|
||
// EqInt64 composes 'equal' operation from int64 value. | ||
// Result is equivalent to: field == value | ||
func EqInt64(field string, value int64) expr { | ||
return expr{field: comparison{Eq: value}} | ||
} | ||
|
||
// EqInt32 composes 'equal' operation from int32 value. | ||
// Result is equivalent to: field == value | ||
func EqInt32(field string, value int32) expr { | ||
return expr{field: comparison{Eq: value}} | ||
} | ||
|
||
// EqInt composes 'equal' operation from int value. | ||
// Result is equivalent to: field == value | ||
func EqInt(field string, value int) expr { | ||
return expr{field: comparison{Eq: value}} | ||
} | ||
|
||
// EqString composes 'equal' operation from string value. | ||
// Result is equivalent to: field == value | ||
func EqString(field string, value string) expr { | ||
return expr{field: comparison{Eq: value}} | ||
} | ||
|
||
// EqBytes composes 'equal' operation from []byte value. | ||
// Result is equivalent to: field == value | ||
func EqBytes(field string, value []byte) expr { | ||
return expr{field: comparison{Eq: value}} | ||
} | ||
|
||
// EqFloat32 composes 'equal' operation from float32 value. | ||
// Result is equivalent to: field == value | ||
func EqFloat32(field string, value float32) expr { | ||
return expr{field: comparison{Eq: value}} | ||
} | ||
|
||
// EqFloat64 composes 'equal' operation from float64 value. | ||
// Result is equivalent to: field == value | ||
func EqFloat64(field string, value float64) expr { | ||
return expr{field: comparison{Eq: value}} | ||
} | ||
|
||
// EqTime composes 'equal' operation. from time.Time value. | ||
// Result is equivalent to: field == value | ||
func EqTime(field string, value *time.Time) expr { | ||
return expr{field: comparison{Eq: value}} | ||
} |
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,33 @@ | ||
package filter | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEq(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
expr expr | ||
exp string | ||
}{ | ||
{"int", EqInt("f", 12345), `{"f":{"$eq":12345}}`}, | ||
{"int32", EqInt32("f", 12345), `{"f":{"$eq":12345}}`}, | ||
{"int64", EqInt64("f", 123456789012), `{"f":{"$eq":123456789012}}`}, | ||
{"float32", EqFloat32("f", 12345.67), `{"f":{"$eq":12345.67}}`}, | ||
{"float64", EqFloat64("f", 123456789012.34), `{"f":{"$eq":123456789012.34}}`}, | ||
{"string", EqString("f", "1234"), `{"f":{"$eq":"1234"}}`}, | ||
{"bytes", EqBytes("f", []byte("123")), `{"f":{"$eq":"MTIz"}}`}, | ||
{"time", EqTime("f", &time.Time{}), `{"f":{"$eq":"0001-01-01T00:00:00Z"}}`}, | ||
} | ||
|
||
for _, v := range cases { | ||
t.Run(v.name, func(t *testing.T) { | ||
act, err := v.expr.Build() | ||
require.NoError(t, err) | ||
require.Equal(t, v.exp, string(act)) | ||
}) | ||
} | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
better restrict to our supported types.