-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
105 additions
and
11 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
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,45 @@ | ||
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}} | ||
} | ||
|
||
// 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,32 @@ | ||
package filter | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestEq(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
expr expr | ||
exp string | ||
}{ | ||
{"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