diff --git a/yaormfilter/tools_test.go b/yaormfilter/tools_test.go index 2acb8b2..2a9b0e4 100644 --- a/yaormfilter/tools_test.go +++ b/yaormfilter/tools_test.go @@ -16,6 +16,15 @@ func TestEquals(t *testing.T) { assert.IsType(t, &yaormfilter.BoolFilter{}, yaormfilter.Equals(false)) } +func TestEquality(t *testing.T) { + f := yaormfilter.Equals("abdef") + assert.True(t, f.IsEquality()) + assert.Equal(t, "abdef", f.GetEquality()) + + f = yaormfilter.NotEquals("bdef") + assert.False(t, f.IsEquality()) +} + func TestNotEquals(t *testing.T) { assert.IsType(t, &yaormfilter.StringFilter{}, yaormfilter.NotEquals("abcdef")) assert.IsType(t, &yaormfilter.Int64Filter{}, yaormfilter.NotEquals(int64(12))) diff --git a/yaormfilter/valuefilter.go b/yaormfilter/valuefilter.go index 68b41d0..aa9be4b 100644 --- a/yaormfilter/valuefilter.go +++ b/yaormfilter/valuefilter.go @@ -21,10 +21,22 @@ type ValueFilter interface { In(v ...interface{}) ValueFilter NotIn(v ...interface{}) ValueFilter Raw(fn RawFilterFunc) ValueFilter + IsEquality() bool + GetEquality() interface{} } type valuefilterimpl struct { - filterFn RawFilterFunc + filterFn RawFilterFunc + shouldEqual bool + equals_ interface{} +} + +func (f valuefilterimpl) IsEquality() bool { + return f.shouldEqual +} + +func (f valuefilterimpl) GetEquality() interface{} { + return f.equals_ } func (f *valuefilterimpl) nil(v bool) *valuefilterimpl { @@ -38,6 +50,8 @@ func (f *valuefilterimpl) nil(v bool) *valuefilterimpl { } func (f *valuefilterimpl) equals(e interface{}) *valuefilterimpl { + f.shouldEqual = true + f.equals_ = e return f.raw(func(field string) interface{} { return squirrel.Eq{field: e} })