@@ -113,19 +113,61 @@ func TestParse_FilterString(t *testing.T) {
113113 })
114114
115115 t .Run ("exists" , func (t * testing.T ) {
116+ var f testFilter
117+ require .NoError (t , Parse (url.Values {"filter[field][exists]" : {"true" }}, & f ))
118+ require .NotNil (t , f .Field )
119+ assert .Equal (t , lo .ToPtr (true ), f .Field .Exists )
120+ })
121+
122+ t .Run ("exists false" , func (t * testing.T ) {
123+ var f testFilter
124+ require .NoError (t , Parse (url.Values {"filter[field][exists]" : {"false" }}, & f ))
125+ require .NotNil (t , f .Field )
126+ assert .Equal (t , lo .ToPtr (false ), f .Field .Exists )
127+ })
128+
129+ t .Run ("exists without value" , func (t * testing.T ) {
116130 var f testFilter
117131 require .NoError (t , Parse (url.Values {"filter[field][exists]" : {"" }}, & f ))
118132 require .NotNil (t , f .Field )
119133 assert .Equal (t , lo .ToPtr (true ), f .Field .Exists )
120134 })
121135
136+ t .Run ("exists invalid boolean" , func (t * testing.T ) {
137+ var f testFilter
138+ err := Parse (url.Values {"filter[field][exists]" : {"anything" }}, & f )
139+ require .Error (t , err )
140+ assert .Contains (t , err .Error (), `invalid boolean "anything"` )
141+ })
142+
122143 t .Run ("nexists" , func (t * testing.T ) {
144+ var f testFilter
145+ require .NoError (t , Parse (url.Values {"filter[field][nexists]" : {"true" }}, & f ))
146+ require .NotNil (t , f .Field )
147+ assert .Equal (t , lo .ToPtr (false ), f .Field .Exists )
148+ })
149+
150+ t .Run ("nexists false" , func (t * testing.T ) {
151+ var f testFilter
152+ require .NoError (t , Parse (url.Values {"filter[field][nexists]" : {"false" }}, & f ))
153+ require .NotNil (t , f .Field )
154+ assert .Equal (t , lo .ToPtr (true ), f .Field .Exists )
155+ })
156+
157+ t .Run ("nexists without value" , func (t * testing.T ) {
123158 var f testFilter
124159 require .NoError (t , Parse (url.Values {"filter[field][nexists]" : {"" }}, & f ))
125160 require .NotNil (t , f .Field )
126161 assert .Equal (t , lo .ToPtr (false ), f .Field .Exists )
127162 })
128163
164+ t .Run ("nexists invalid boolean" , func (t * testing.T ) {
165+ var f testFilter
166+ err := Parse (url.Values {"filter[field][nexists]" : {"anything" }}, & f )
167+ require .Error (t , err )
168+ assert .Contains (t , err .Error (), `invalid boolean "anything"` )
169+ })
170+
129171 t .Run ("bare key existence" , func (t * testing.T ) {
130172 var f testFilter
131173 require .NoError (t , Parse (url.Values {"filter[field]" : {"" }}, & f ))
0 commit comments