@@ -173,3 +173,163 @@ func Test_selectorOperator(t *testing.T) {
173173 }
174174 batchOperatorTests (t , tests )
175175}
176+
177+ func Test_inOperator (t * testing.T ) {
178+ currentDSelector , _ := newSelectorOperator ("@.d" , & ScriptEngine {}, nil )
179+
180+ tests := []* operatorTest {
181+ {
182+ input : operatorTestInput {
183+ operator : & inOperator {arg1 : nil , arg2 : nil },
184+ paramters : map [string ]interface {}{},
185+ },
186+ expected : operatorTestExpected {
187+ err : "invalid argument. is nil" ,
188+ },
189+ },
190+ {
191+ input : operatorTestInput {
192+ operator : & inOperator {arg1 : nil , arg2 : []interface {}{"one" }},
193+ paramters : map [string ]interface {}{},
194+ },
195+ expected : operatorTestExpected {
196+ value : false ,
197+ },
198+ },
199+ {
200+ input : operatorTestInput {
201+ operator : & inOperator {arg1 : "one" , arg2 : []interface {}{"one" }},
202+ paramters : map [string ]interface {}{},
203+ },
204+ expected : operatorTestExpected {
205+ value : true ,
206+ },
207+ },
208+ {
209+ input : operatorTestInput {
210+ operator : & inOperator {arg1 : "one" , arg2 : `["one","two"]` },
211+ paramters : map [string ]interface {}{},
212+ },
213+ expected : operatorTestExpected {
214+ value : true ,
215+ },
216+ },
217+ {
218+ input : operatorTestInput {
219+ operator : & inOperator {arg1 : "one" , arg2 : `{"1":"one","2":"two"}` },
220+ paramters : map [string ]interface {}{},
221+ },
222+ expected : operatorTestExpected {
223+ value : true ,
224+ },
225+ },
226+ {
227+ input : operatorTestInput {
228+ operator : & inOperator {arg1 : "1" , arg2 : `[1,2,3]` },
229+ paramters : map [string ]interface {}{},
230+ },
231+ expected : operatorTestExpected {
232+ value : true ,
233+ },
234+ },
235+ {
236+ input : operatorTestInput {
237+ operator : & inOperator {arg1 : "1" , arg2 : `["1","2","3"]` },
238+ paramters : map [string ]interface {}{},
239+ },
240+ expected : operatorTestExpected {
241+ value : false ,
242+ },
243+ },
244+ {
245+ input : operatorTestInput {
246+ operator : & inOperator {
247+ arg1 : "2" ,
248+ arg2 : currentDSelector ,
249+ },
250+ paramters : map [string ]interface {}{
251+ "@" : map [string ]interface {}{
252+ "d" : []interface {}{
253+ float64 (1 ),
254+ float64 (2 ),
255+ float64 (3 ),
256+ },
257+ },
258+ },
259+ },
260+ expected : operatorTestExpected {
261+ value : true ,
262+ },
263+ },
264+ }
265+ batchOperatorTests (t , tests )
266+ }
267+
268+ func Test_notInOperator (t * testing.T ) {
269+ tests := []* operatorTest {
270+ {
271+ input : operatorTestInput {
272+ operator : & notInOperator {arg1 : nil , arg2 : nil },
273+ paramters : map [string ]interface {}{},
274+ },
275+ expected : operatorTestExpected {
276+ err : "invalid argument. is nil" ,
277+ },
278+ },
279+ {
280+ input : operatorTestInput {
281+ operator : & notInOperator {arg1 : nil , arg2 : []interface {}{"one" }},
282+ paramters : map [string ]interface {}{},
283+ },
284+ expected : operatorTestExpected {
285+ value : true ,
286+ },
287+ },
288+ {
289+ input : operatorTestInput {
290+ operator : & notInOperator {arg1 : "one" , arg2 : []interface {}{"one" }},
291+ paramters : map [string ]interface {}{},
292+ },
293+ expected : operatorTestExpected {
294+ value : false ,
295+ },
296+ },
297+ {
298+ input : operatorTestInput {
299+ operator : & notInOperator {arg1 : "one" , arg2 : `["one","two"]` },
300+ paramters : map [string ]interface {}{},
301+ },
302+ expected : operatorTestExpected {
303+ value : false ,
304+ },
305+ },
306+ {
307+ input : operatorTestInput {
308+ operator : & notInOperator {arg1 : "one" , arg2 : `{"1":"one","2":"two"}` },
309+ paramters : map [string ]interface {}{},
310+ },
311+ expected : operatorTestExpected {
312+ value : false ,
313+ },
314+ },
315+ {
316+ input : operatorTestInput {
317+ operator : & notInOperator {arg1 : "1" , arg2 : `[1,2,3]` },
318+ paramters : map [string ]interface {}{},
319+ },
320+ expected : operatorTestExpected {
321+ value : false ,
322+ },
323+ },
324+ {
325+ input : operatorTestInput {
326+ operator : & notInOperator {arg1 : "1" , arg2 : `["1","2","3"]` },
327+ paramters : map [string ]interface {}{},
328+ },
329+ expected : operatorTestExpected {
330+ value : true ,
331+ },
332+ },
333+ }
334+ batchOperatorTests (t , tests )
335+ }
0 commit comments