Debian Codegraph @

query_test.go

raw symbols SCIP
1 package gojsonq
2
3 import (
4 "testing"
5 )
6
7 func Test_eq(t *testing.T) {
8 testCases := []struct {
9 x interface{}
10 y interface{}
11 expected bool
12 }{
13 {
14 // our expectation for json unmarshaller is little bit different. here 9 provided by user will be equal to float64 9
15 x: 9.0,
16 y: 9,
17 expected: true,
18 },
19 {
20 x: 110,
21 y: 120,
22 expected: false,
23 },
24 {
25 x: 10.09,
26 y: 10.09,
27 expected: true,
28 },
29 {
30 x: 10.09,
31 y: 10.89,
32 expected: false,
33 },
34 {
35 x: "john",
36 y: "john",
37 expected: true,
38 },
39 {
40 x: "tom",
41 y: "jane",
42 expected: false,
43 },
44 {
45 x: "",
46 y: "",
47 expected: true,
48 },
49 {
50 x: nil,
51 y: nil,
52 expected: true,
53 },
54 }
55
56 for _, tc := range testCases {
57 if o, _ := eq(tc.x, tc.y); o != tc.expected {
58 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
59 }
60 }
61 }
62
63 func Test_neq(t *testing.T) {
64 testCases := []struct {
65 x interface{}
66 y interface{}
67 expected bool
68 }{
69 {
70 x: 9.0, // as x is out json unmarshal value which is float64
71 y: 9, // our expectation for json unmarshalar is little bit different. here 9 provided by user will be equal to float64 9
72 expected: false,
73 },
74 {
75 x: 110,
76 y: 120,
77 expected: true,
78 },
79 {
80 x: 10.09,
81 y: 10.09,
82 expected: false,
83 },
84 {
85 x: 10.09,
86 y: 10.89,
87 expected: true,
88 },
89 {
90 x: "john",
91 y: "john",
92 expected: false,
93 },
94 {
95 x: "tom",
96 y: "jane",
97 expected: true,
98 },
99 {
100 x: "",
101 y: "",
102 expected: false,
103 },
104 {
105 x: nil,
106 y: nil,
107 expected: false,
108 },
109 }
110
111 for _, tc := range testCases {
112 if o, _ := neq(tc.x, tc.y); o != tc.expected {
113 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
114 }
115 }
116 }
117
118 func Test_gt(t *testing.T) {
119 testCases := []struct {
120 x interface{}
121 y interface{}
122 expected bool
123 }{
124 {
125 x: float64(10),
126 y: 5,
127 expected: true,
128 },
129 {
130 x: float64(10),
131 y: 15,
132 expected: false,
133 },
134 {
135 x: float64(10),
136 y: "10",
137 expected: false,
138 },
139 {
140 x: "101",
141 y: "101",
142 expected: false,
143 },
144 }
145
146 for _, tc := range testCases {
147 if o, _ := gt(tc.x, tc.y); o != tc.expected {
148 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
149 }
150 }
151 }
152
153 func Test_lt(t *testing.T) {
154 testCases := []struct {
155 x interface{}
156 y interface{}
157 expected bool
158 }{
159 {
160 x: float64(10),
161 y: 5,
162 expected: false,
163 },
164 {
165 x: float64(10),
166 y: 15,
167 expected: true,
168 },
169 {
170 x: float64(10),
171 y: "10",
172 expected: false,
173 },
174 {
175 x: "101",
176 y: "101",
177 expected: false,
178 },
179 }
180
181 for _, tc := range testCases {
182 if o, _ := lt(tc.x, tc.y); o != tc.expected {
183 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
184 }
185 }
186 }
187
188 func Test_gte(t *testing.T) {
189 testCases := []struct {
190 x interface{}
191 y interface{}
192 expected bool
193 }{
194 {
195 x: float64(10),
196 y: 5,
197 expected: true,
198 },
199 {
200 x: float64(10),
201 y: 15,
202 expected: false,
203 },
204 {
205 x: float64(18),
206 y: 18,
207 expected: true,
208 },
209 {
210 x: float64(30.9),
211 y: 30.9,
212 expected: true,
213 },
214 {
215 x: float64(10),
216 y: "10",
217 expected: false,
218 },
219 {
220 x: "101",
221 y: "101",
222 expected: false,
223 },
224 }
225
226 for _, tc := range testCases {
227 if o, _ := gte(tc.x, tc.y); o != tc.expected {
228 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
229 }
230 }
231 }
232
233 func Test_lte(t *testing.T) {
234 testCases := []struct {
235 x interface{}
236 y interface{}
237 expected bool
238 }{
239 {
240 x: float64(10),
241 y: 5,
242 expected: false,
243 },
244 {
245 x: float64(10),
246 y: 15,
247 expected: true,
248 },
249 {
250 x: float64(18),
251 y: 18,
252 expected: true,
253 },
254 {
255 x: float64(30.9),
256 y: 30.9,
257 expected: true,
258 },
259 {
260 x: float64(40.9),
261 y: 30.9,
262 expected: false,
263 },
264 {
265 x: float64(10),
266 y: "10",
267 expected: false,
268 },
269 {
270 x: "101",
271 y: "101",
272 expected: false,
273 },
274 }
275
276 for _, tc := range testCases {
277 if o, _ := lte(tc.x, tc.y); o != tc.expected {
278 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
279 }
280 }
281 }
282
283 func Test_strStrictContains(t *testing.T) {
284 testCases := []struct {
285 x interface{}
286 y interface{}
287 expected bool
288 }{
289 {
290 x: float64(10),
291 y: "10",
292 expected: false,
293 },
294 {
295 x: float64(11),
296 y: float64(11),
297 expected: false,
298 },
299 {
300 x: "131",
301 y: float64(131),
302 expected: false,
303 },
304 {
305 x: "458",
306 y: "458",
307 expected: true,
308 },
309 {
310 x: "arch",
311 y: "arch",
312 expected: true,
313 },
314 {
315 x: "Arch",
316 y: "arch",
317 expected: false,
318 },
319 }
320
321 for _, tc := range testCases {
322 if o, _ := strStrictContains(tc.x, tc.y); o != tc.expected {
323 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
324 }
325 }
326 }
327
328 func Test_strContains(t *testing.T) {
329 testCases := []struct {
330 x interface{}
331 y interface{}
332 expected bool
333 }{
334 {
335 x: float64(10),
336 y: "10",
337 expected: false,
338 },
339 {
340 x: float64(11),
341 y: float64(11),
342 expected: false,
343 },
344 {
345 x: "131",
346 y: float64(131),
347 expected: false,
348 },
349 {
350 x: "458",
351 y: "458",
352 expected: true,
353 },
354 {
355 x: "arch",
356 y: "arch",
357 expected: true,
358 },
359 {
360 x: "Arch",
361 y: "arcH",
362 expected: true,
363 },
364 }
365
366 for _, tc := range testCases {
367 if o, _ := strContains(tc.x, tc.y); o != tc.expected {
368 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
369 }
370 }
371 }
372
373 func Test_strStartsWith(t *testing.T) {
374 testCases := []struct {
375 x interface{}
376 y interface{}
377 expected bool
378 }{
379 {
380 x: float64(10),
381 y: "10",
382 expected: false,
383 },
384 {
385 x: float64(11),
386 y: float64(11),
387 expected: false,
388 },
389 {
390 x: "131",
391 y: float64(131),
392 expected: false,
393 },
394 {
395 x: "458",
396 y: "458",
397 expected: true,
398 },
399 {
400 x: "arch",
401 y: "arch",
402 expected: true,
403 },
404 {
405 x: "erik",
406 y: "er",
407 expected: true,
408 },
409 }
410
411 for _, tc := range testCases {
412 if o, _ := strStartsWith(tc.x, tc.y); o != tc.expected {
413 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
414 }
415 }
416 }
417
418 func Test_strEndsWith(t *testing.T) {
419 testCases := []struct {
420 x interface{}
421 y interface{}
422 expected bool
423 }{
424 {
425 x: float64(10),
426 y: "10",
427 expected: false,
428 },
429 {
430 x: float64(11),
431 y: float64(11),
432 expected: false,
433 },
434 {
435 x: "131",
436 y: float64(131),
437 expected: false,
438 },
439 {
440 x: "458",
441 y: "458",
442 expected: true,
443 },
444 {
445 x: "arch",
446 y: "arch",
447 expected: true,
448 },
449 {
450 x: "sky",
451 y: "ky",
452 expected: true,
453 },
454 }
455
456 for _, tc := range testCases {
457 if o, _ := strEndsWith(tc.x, tc.y); o != tc.expected {
458 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
459 }
460 }
461 }
462
463 func Test_in(t *testing.T) {
464 testCases := []struct {
465 x interface{}
466 y interface{}
467 expected bool
468 }{
469 {
470 x: "sky",
471 y: []string{"river", "sun", "moon"},
472 expected: false,
473 },
474 {
475 x: "sun",
476 y: []string{"river", "sun", "moon"},
477 expected: true,
478 },
479 {
480 x: float64(10), // ass json numeric value will be treat as float64
481 y: []int{11, 12, 14, 18},
482 expected: false,
483 },
484 {
485 x: float64(14), // ass json numeric value will be treat as float64
486 y: []int{11, 12, 14, 18},
487 expected: true,
488 },
489 {
490 x: float64(10),
491 y: []float64{11, 12, 14, 18},
492 expected: false,
493 },
494 {
495 x: float64(14),
496 y: []float64{11, 12, 14, 18},
497 expected: true,
498 },
499 }
500
501 for _, tc := range testCases {
502 if o, _ := in(tc.x, tc.y); o != tc.expected {
503 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
504 }
505 }
506 }
507
508 func Test_notIn(t *testing.T) {
509 testCases := []struct {
510 x interface{}
511 y interface{}
512 expected bool
513 }{
514 {
515 x: "sky",
516 y: []string{"river", "sun", "moon"},
517 expected: true,
518 },
519 {
520 x: "sun",
521 y: []string{"river", "sun", "moon"},
522 expected: false,
523 },
524 {
525 x: float64(10), // ass json numeric value will be treat as float64
526 y: []int{11, 12, 14, 18},
527 expected: true,
528 },
529 {
530 x: float64(14), // ass json numeric value will be treat as float64
531 y: []int{11, 12, 14, 18},
532 expected: false,
533 },
534 {
535 x: float64(10),
536 y: []float64{11, 12, 14, 18},
537 expected: true,
538 },
539 {
540 x: float64(14),
541 y: []float64{11, 12, 14, 18},
542 expected: false,
543 },
544 }
545
546 for _, tc := range testCases {
547 if o, _ := notIn(tc.x, tc.y); o != tc.expected {
548 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
549 }
550 }
551 }
552
553 func Test_lenEq(t *testing.T) {
554 testCases := []struct {
555 x interface{}
556 y interface{}
557 expected bool
558 }{
559 {
560 x: []interface{}{"river", "sun", "moon"},
561 y: 3,
562 expected: true,
563 },
564 {
565 x: "sun",
566 y: 3,
567 expected: true,
568 },
569 {
570 x: 100,
571 y: 3,
572 expected: false,
573 },
574 {
575 x: 100,
576 y: 3,
577 expected: false,
578 },
579 {
580 x: "moon",
581 y: 4.0,
582 expected: false,
583 },
584 }
585
586 for _, tc := range testCases {
587 if o, _ := lenEq(tc.x, tc.y); o != tc.expected {
588 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
589 }
590 }
591 }
592
593 func Test_lenNotEq(t *testing.T) {
594 testCases := []struct {
595 x interface{}
596 y interface{}
597 expected bool
598 }{
599 {
600 x: []interface{}{"river", "sun", "moon"},
601 y: 6,
602 expected: true,
603 },
604 {
605 x: "sun",
606 y: 8,
607 expected: true,
608 },
609 {
610 x: "moon",
611 y: 4,
612 expected: false,
613 },
614 {
615 x: 100.6,
616 y: 4,
617 expected: false,
618 },
619 {
620 x: "moon",
621 y: 4.0,
622 expected: false,
623 },
624 }
625
626 for _, tc := range testCases {
627 if o, _ := lenNotEq(tc.x, tc.y); o != tc.expected {
628 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
629 }
630 }
631 }
632
633 func Test_lenGt(t *testing.T) {
634 testCases := []struct {
635 x interface{}
636 y interface{}
637 expected bool
638 }{
639 {
640 x: []interface{}{"river", "sun", "moon"},
641 y: 6,
642 expected: false,
643 },
644 {
645 x: "sun",
646 y: 2,
647 expected: true,
648 },
649 {
650 x: "moon",
651 y: 2,
652 expected: true,
653 },
654 {
655 x: 100.6,
656 y: 4,
657 expected: false,
658 },
659 {
660 x: "moon",
661 y: 4.0,
662 expected: false,
663 },
664 }
665
666 for _, tc := range testCases {
667 if o, _ := lenGt(tc.x, tc.y); o != tc.expected {
668 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
669 }
670 }
671 }
672
673 func Test_lenLt(t *testing.T) {
674 testCases := []struct {
675 x interface{}
676 y interface{}
677 expected bool
678 }{
679 {
680 x: []interface{}{"river", "sun", "moon"},
681 y: 6,
682 expected: true,
683 },
684 {
685 x: "sun",
686 y: 20,
687 expected: true,
688 },
689 {
690 x: "moon",
691 y: 3,
692 expected: false,
693 },
694 {
695 x: 100.6,
696 y: 4,
697 expected: false,
698 },
699 {
700 x: "john",
701 y: 4.0,
702 expected: false,
703 },
704 }
705
706 for _, tc := range testCases {
707 if o, _ := lenLt(tc.x, tc.y); o != tc.expected {
708 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
709 }
710 }
711 }
712
713 func Test_lenGte(t *testing.T) {
714 testCases := []struct {
715 x interface{}
716 y interface{}
717 expected bool
718 }{
719 {
720 x: []interface{}{"river", "sun", "moon"},
721 y: 3,
722 expected: true,
723 },
724 {
725 x: "sun",
726 y: 2,
727 expected: true,
728 },
729 {
730 x: "jane",
731 y: 5,
732 expected: false,
733 },
734 {
735 x: 100.6,
736 y: 4,
737 expected: false,
738 },
739 {
740 x: "moon",
741 y: 4.0,
742 expected: false,
743 },
744 }
745
746 for _, tc := range testCases {
747 if o, _ := lenGte(tc.x, tc.y); o != tc.expected {
748 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
749 }
750 }
751 }
752
753 func Test_lenLte(t *testing.T) {
754 testCases := []struct {
755 x interface{}
756 y interface{}
757 expected bool
758 }{
759 {
760 x: []interface{}{"river", "sun", "moon"},
761 y: 3,
762 expected: true,
763 },
764 {
765 x: "sun",
766 y: 12,
767 expected: true,
768 },
769 {
770 x: "jane",
771 y: 2,
772 expected: false,
773 },
774 {
775 x: 100.6,
776 y: 4,
777 expected: false,
778 },
779 {
780 x: "moon",
781 y: 4.0,
782 expected: false,
783 },
784 }
785
786 for _, tc := range testCases {
787 if o, _ := lenLte(tc.x, tc.y); o != tc.expected {
788 t.Errorf("for %v expected: %v got: %v", tc.x, tc.expected, o)
789 }
790 }
791 }
792
793 func Test_loadDefaultQueryMap(t *testing.T) {
794 if len(defaultQueries()) != 25 {
795 t.Error("mismatched default query map size")
796 }
797 }