expect_json/expect/ops/expect_integer/
expect_integer.rs

1use crate::expect::ops::expect_integer::ExpectIntegerSubOp;
2use crate::expect_core::expect_op;
3use crate::expect_core::Context;
4use crate::expect_core::ExpectOp;
5use crate::expect_core::ExpectOpResult;
6use crate::JsonInteger;
7use crate::JsonType;
8use core::ops::RangeBounds;
9
10#[expect_op(internal, name = "integer")]
11#[derive(Debug, Clone, Default, PartialEq)]
12pub struct ExpectInteger {
13    sub_ops: Vec<ExpectIntegerSubOp>,
14}
15
16impl ExpectInteger {
17    pub(crate) fn new() -> Self {
18        Self { sub_ops: vec![] }
19    }
20
21    pub fn greater_than<N>(mut self, expected: N) -> Self
22    where
23        N: Into<JsonInteger>,
24    {
25        self.sub_ops.push(ExpectIntegerSubOp::GreaterThan {
26            expected: expected.into(),
27        });
28        self
29    }
30
31    pub fn greater_than_equal<N>(mut self, expected: N) -> Self
32    where
33        N: Into<JsonInteger>,
34    {
35        self.sub_ops.push(ExpectIntegerSubOp::GreaterThanEqual {
36            expected: expected.into(),
37        });
38        self
39    }
40
41    pub fn less_than<N>(mut self, expected: N) -> Self
42    where
43        N: Into<JsonInteger>,
44    {
45        self.sub_ops.push(ExpectIntegerSubOp::LessThan {
46            expected: expected.into(),
47        });
48        self
49    }
50
51    pub fn less_than_equal<N>(mut self, expected: N) -> Self
52    where
53        N: Into<JsonInteger>,
54    {
55        self.sub_ops.push(ExpectIntegerSubOp::LessThanEqual {
56            expected: expected.into(),
57        });
58        self
59    }
60
61    ///
62    /// Expect an integer within the given range.
63    ///
64    /// ```rust
65    /// # async fn test() -> Result<(), Box<dyn ::std::error::Error>> {
66    /// #
67    /// # use axum::Router;
68    /// # use axum::extract::Json;
69    /// # use axum::routing::get;
70    /// # use axum_test::TestServer;
71    /// # use serde_json::json;
72    /// #
73    /// # let server = TestServer::new(Router::new())?;
74    /// #
75    /// use axum_test::expect_json;
76    ///
77    /// let server = TestServer::new(Router::new())?;
78    ///
79    /// server.get(&"/user/barrington")
80    ///     .await
81    ///     .assert_json(&json!({
82    ///         "name": "Barrington",
83    ///         "age": expect_json::integer().in_range(18..=110),
84    ///     }));
85    /// #
86    /// # Ok(()) }
87    /// ```
88    pub fn in_range<R>(mut self, range: R) -> Self
89    where
90        R: RangeBounds<i64>,
91    {
92        let min = range.start_bound().cloned();
93        let max = range.end_bound().cloned();
94
95        self.sub_ops.push(ExpectIntegerSubOp::InRange {
96            min: min.into(),
97            max: max.into(),
98        });
99
100        self
101    }
102
103    pub fn outside_range<R>(mut self, range: R) -> Self
104    where
105        R: RangeBounds<i64>,
106    {
107        let min = range.start_bound().cloned();
108        let max = range.end_bound().cloned();
109
110        self.sub_ops.push(ExpectIntegerSubOp::OutsideRange {
111            min: min.into(),
112            max: max.into(),
113        });
114
115        self
116    }
117
118    pub fn zero(mut self) -> Self {
119        self.sub_ops.push(ExpectIntegerSubOp::Zero);
120        self
121    }
122
123    pub fn not_zero(mut self) -> Self {
124        self.sub_ops.push(ExpectIntegerSubOp::NotZero);
125        self
126    }
127
128    pub fn positive(mut self) -> Self {
129        self.sub_ops.push(ExpectIntegerSubOp::Positive);
130        self
131    }
132
133    pub fn negative(mut self) -> Self {
134        self.sub_ops.push(ExpectIntegerSubOp::Negative);
135        self
136    }
137}
138
139impl ExpectOp for ExpectInteger {
140    fn on_i64(&self, context: &mut Context, received: i64) -> ExpectOpResult<()> {
141        for sub_op in &self.sub_ops {
142            sub_op.on_i64(self, context, received)?;
143        }
144
145        Ok(())
146    }
147
148    fn on_u64(&self, context: &mut Context, received: u64) -> ExpectOpResult<()> {
149        for sub_op in &self.sub_ops {
150            sub_op.on_u64(self, context, received)?;
151        }
152
153        Ok(())
154    }
155
156    fn debug_supported_types(&self) -> &'static [JsonType] {
157        &[JsonType::Integer]
158    }
159}
160
161#[cfg(test)]
162mod test_in_range {
163    use crate::expect;
164    use crate::expect_json_eq;
165    use pretty_assertions::assert_eq;
166    use serde_json::json;
167
168    #[test]
169    fn it_should_be_true_for_all_values_in_total_range() {
170        let left = json!(1);
171        let right = json!(expect::integer().in_range(..));
172        let output = expect_json_eq(&left, &right);
173        assert!(output.is_ok());
174
175        let left = json!(i64::MIN);
176        let right = json!(expect::integer().in_range(..));
177        let output = expect_json_eq(&left, &right);
178        assert!(output.is_ok());
179
180        let left = json!(u64::MAX);
181        let right = json!(expect::integer().in_range(..));
182        let output = expect_json_eq(&left, &right);
183        assert!(output.is_ok());
184    }
185
186    #[test]
187    fn it_should_be_true_for_all_values_in_partial_range() {
188        let left = json!(0);
189        let right = json!(expect::integer().in_range(-10..10));
190        let output = expect_json_eq(&left, &right);
191        assert!(output.is_ok());
192
193        let left = json!(-10);
194        let right = json!(expect::integer().in_range(-10..10));
195        let output = expect_json_eq(&left, &right);
196        assert!(output.is_ok());
197
198        let left = json!(5);
199        let right = json!(expect::integer().in_range(-10..10));
200        let output = expect_json_eq(&left, &right);
201        assert!(output.is_ok());
202    }
203
204    #[test]
205    fn it_should_be_false_for_all_values_out_of_range() {
206        let left = json!(1);
207        let right = json!(expect::integer().in_range(0..1));
208
209        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
210        assert_eq!(
211            output,
212            r#"Json expect::integer() error at root:
213    integer is not in range
214    expected 0..1
215    received 1"#
216        );
217
218        let left = json!(-11);
219        let right = json!(expect::integer().in_range(0..1));
220
221        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
222        assert_eq!(
223            output,
224            r#"Json expect::integer() error at root:
225    integer is not in range
226    expected 0..1
227    received -11"#
228        );
229    }
230
231    #[test]
232    fn it_should_be_true_for_value_in_inclusive_range() {
233        let left = json!(1);
234        let right = json!(expect::integer().in_range(0..=1));
235
236        let output = expect_json_eq(&left, &right);
237        assert!(output.is_ok());
238    }
239
240    #[test]
241    fn it_should_be_true_for_positive_value_with_negative_min() {
242        let left = json!(5);
243        let right = json!(expect::integer().in_range(-10..10));
244
245        let output = expect_json_eq(&left, &right);
246        assert!(output.is_ok());
247    }
248
249    #[test]
250    fn it_should_be_false_for_positive_value_outside_range_with_negative_min() {
251        let left = json!(11);
252        let right = json!(expect::integer().in_range(-10..10));
253
254        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
255        assert_eq!(
256            output,
257            r#"Json expect::integer() error at root:
258    integer is not in range
259    expected -10..10
260    received 11"#
261        );
262    }
263
264    #[test]
265    fn it_should_be_false_for_positive_value_outside_range_with_negative_range() {
266        let left = json!(11);
267        let right = json!(expect::integer().in_range(-10..-1));
268
269        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
270        assert_eq!(
271            output,
272            r#"Json expect::integer() error at root:
273    integer is not in range
274    expected -10..-1
275    received 11"#
276        );
277    }
278}
279
280#[cfg(test)]
281mod test_outside_range {
282    use crate::expect;
283    use crate::expect_json_eq;
284    use pretty_assertions::assert_eq;
285    use serde_json::json;
286
287    #[test]
288    fn it_should_be_false_for_all_values_in_total_range() {
289        let left = json!(1);
290        let right = json!(expect::integer().outside_range(..));
291        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
292        assert_eq!(
293            output,
294            r#"Json expect::integer() error at root:
295    integer is in range
296    expected ..
297    received 1"#
298        );
299
300        let left = json!(i64::MIN);
301        let right = json!(expect::integer().outside_range(..));
302        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
303        assert_eq!(
304            output,
305            r#"Json expect::integer() error at root:
306    integer is in range
307    expected ..
308    received -9223372036854775808"#
309        );
310
311        let left = json!(u64::MAX);
312        let right = json!(expect::integer().outside_range(..));
313        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
314        assert_eq!(
315            output,
316            r#"Json expect::integer() error at root:
317    integer is in range
318    expected ..
319    received 18446744073709551615"#
320        );
321    }
322
323    #[test]
324    fn it_should_be_false_for_all_values_overlapping_partial_ranges() {
325        let left = json!(0);
326        let right = json!(expect::integer().outside_range(-10..10));
327        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
328        assert_eq!(
329            output,
330            r#"Json expect::integer() error at root:
331    integer is in range
332    expected -10..10
333    received 0"#
334        );
335
336        let left = json!(-10);
337        let right = json!(expect::integer().outside_range(-10..10));
338        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
339        assert_eq!(
340            output,
341            r#"Json expect::integer() error at root:
342    integer is in range
343    expected -10..10
344    received -10"#
345        );
346
347        let left = json!(5);
348        let right = json!(expect::integer().outside_range(-10..10));
349        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
350        assert_eq!(
351            output,
352            r#"Json expect::integer() error at root:
353    integer is in range
354    expected -10..10
355    received 5"#
356        );
357    }
358
359    #[test]
360    fn it_should_be_true_for_all_values_out_of_range() {
361        let left = json!(1);
362        let right = json!(expect::integer().outside_range(0..1));
363
364        let output = expect_json_eq(&left, &right);
365        assert!(output.is_ok());
366
367        let left = json!(-11);
368        let right = json!(expect::integer().outside_range(0..1));
369
370        let output = expect_json_eq(&left, &right);
371        assert!(output.is_ok());
372    }
373
374    #[test]
375    fn it_should_be_false_for_value_in_inclusive_range() {
376        let left = json!(1);
377        let right = json!(expect::integer().outside_range(0..=1));
378
379        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
380        assert_eq!(
381            output,
382            r#"Json expect::integer() error at root:
383    integer is in range
384    expected 0..=1
385    received 1"#
386        );
387    }
388
389    #[test]
390    fn it_should_be_false_for_positive_value_with_negative_min() {
391        let left = json!(5);
392        let right = json!(expect::integer().outside_range(-10..10));
393
394        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
395        assert_eq!(
396            output,
397            r#"Json expect::integer() error at root:
398    integer is in range
399    expected -10..10
400    received 5"#
401        );
402    }
403
404    #[test]
405    fn it_should_be_true_for_positive_value_outside_range_with_negative_min() {
406        let left = json!(11);
407        let right = json!(expect::integer().outside_range(-10..10));
408
409        let output = expect_json_eq(&left, &right);
410        assert!(output.is_ok());
411    }
412
413    #[test]
414    fn it_should_be_true_for_positive_value_outside_range_with_negative_range() {
415        let left = json!(11);
416        let right = json!(expect::integer().outside_range(-10..-1));
417
418        let output = expect_json_eq(&left, &right);
419        assert!(output.is_ok());
420    }
421}
422
423#[cfg(test)]
424mod test_zero {
425    use crate::expect;
426    use crate::expect_json_eq;
427    use pretty_assertions::assert_eq;
428    use serde_json::json;
429
430    #[test]
431    fn it_should_be_true_for_zero() {
432        let left = json!(0);
433        let right = json!(expect::integer().zero());
434
435        let output = expect_json_eq(&left, &right);
436        assert!(output.is_ok());
437    }
438
439    #[test]
440    fn it_should_be_false_for_negative_value() {
441        let left = json!(-1);
442        let right = json!(expect::integer().zero());
443
444        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
445        assert_eq!(
446            output,
447            r#"Json expect::integer() error at root, is not zero:
448    expected 0
449    received -1"#
450        );
451    }
452
453    #[test]
454    fn it_should_be_false_for_negative_max() {
455        let left = json!(i64::MIN);
456        let right = json!(expect::integer().zero());
457
458        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
459        assert_eq!(
460            output,
461            r#"Json expect::integer() error at root, is not zero:
462    expected 0
463    received -9223372036854775808"#
464        );
465    }
466
467    #[test]
468    fn it_should_be_false_for_positive_value() {
469        let left = json!(1);
470        let right = json!(expect::integer().zero());
471
472        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
473        assert_eq!(
474            output,
475            r#"Json expect::integer() error at root, is not zero:
476    expected 0
477    received 1"#
478        );
479    }
480
481    #[test]
482    fn it_should_be_false_for_i64_max() {
483        let left = json!(i64::MAX);
484        let right = json!(expect::integer().zero());
485
486        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
487        assert_eq!(
488            output,
489            r#"Json expect::integer() error at root, is not zero:
490    expected 0
491    received 9223372036854775807"#
492        );
493    }
494
495    #[test]
496    fn it_should_be_false_for_u64_max() {
497        let left = json!(u64::MAX);
498        let right = json!(expect::integer().zero());
499
500        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
501        assert_eq!(
502            output,
503            r#"Json expect::integer() error at root, is not zero:
504    expected 0
505    received 18446744073709551615"#
506        );
507    }
508}
509
510#[cfg(test)]
511mod test_not_zero {
512    use crate::expect;
513    use crate::expect_json_eq;
514    use pretty_assertions::assert_eq;
515    use serde_json::json;
516
517    #[test]
518    fn it_should_be_false_for_zero() {
519        let left = json!(0);
520        let right = json!(expect::integer().not_zero());
521
522        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
523        assert_eq!(
524            output,
525            r#"Json expect::integer() error at root, is zero:
526    expected non-zero integer
527    received 0"#
528        );
529    }
530
531    #[test]
532    fn it_should_be_true_for_negative_value() {
533        let left = json!(-1);
534        let right = json!(expect::integer().not_zero());
535
536        let output = expect_json_eq(&left, &right);
537        assert!(output.is_ok());
538    }
539
540    #[test]
541    fn it_should_be_true_for_negative_max() {
542        let left = json!(i64::MIN);
543        let right = json!(expect::integer().not_zero());
544
545        let output = expect_json_eq(&left, &right);
546        assert!(output.is_ok());
547    }
548
549    #[test]
550    fn it_should_be_true_for_positive_value() {
551        let left = json!(1);
552        let right = json!(expect::integer().not_zero());
553
554        let output = expect_json_eq(&left, &right);
555        assert!(output.is_ok());
556    }
557
558    #[test]
559    fn it_should_be_true_for_i64_max() {
560        let left = json!(i64::MAX);
561        let right = json!(expect::integer().not_zero());
562
563        let output = expect_json_eq(&left, &right);
564        assert!(output.is_ok());
565    }
566
567    #[test]
568    fn it_should_be_true_for_u64_max() {
569        let left = json!(u64::MAX);
570        let right = json!(expect::integer().not_zero());
571
572        let output = expect_json_eq(&left, &right);
573        assert!(output.is_ok());
574    }
575}
576
577#[cfg(test)]
578mod test_positive {
579    use crate::expect;
580    use crate::expect_json_eq;
581    use pretty_assertions::assert_eq;
582    use serde_json::json;
583
584    #[test]
585    fn it_should_be_true_for_zero() {
586        let left = json!(0);
587        let right = json!(expect::integer().positive());
588
589        let output = expect_json_eq(&left, &right);
590        assert!(output.is_ok());
591    }
592
593    #[test]
594    fn it_should_be_false_for_negative_i64() {
595        let left = json!(-1);
596        let right = json!(expect::integer().positive());
597
598        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
599        assert_eq!(
600            output,
601            r#"Json expect::integer() error at root:
602    integer is not positive
603    received -1"#
604        );
605    }
606
607    #[test]
608    fn it_should_be_true_for_positive_i64() {
609        let left = json!(123_i64);
610        let right = json!(expect::integer().positive());
611
612        let output = expect_json_eq(&left, &right);
613        assert!(output.is_ok());
614    }
615
616    #[test]
617    fn it_should_be_true_for_positive_u64() {
618        let left = json!(123_u64);
619        let right = json!(expect::integer().positive());
620
621        let output = expect_json_eq(&left, &right);
622        assert!(output.is_ok());
623    }
624}
625
626#[cfg(test)]
627mod test_negative {
628    use crate::expect;
629    use crate::expect_json_eq;
630    use pretty_assertions::assert_eq;
631    use serde_json::json;
632
633    #[test]
634    fn it_should_be_false_for_zero() {
635        let left = json!(0);
636        let right = json!(expect::integer().negative());
637
638        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
639        assert_eq!(
640            output,
641            r#"Json expect::integer() error at root:
642    integer is not negative
643    received 0"#
644        );
645    }
646
647    #[test]
648    fn it_should_be_true_for_negative_i64() {
649        let left = json!(-1);
650        let right = json!(expect::integer().negative());
651
652        let output = expect_json_eq(&left, &right);
653        assert!(output.is_ok());
654    }
655
656    #[test]
657    fn it_should_be_false_for_positive_i64() {
658        let left = json!(123_i64);
659        let right = json!(expect::integer().negative());
660
661        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
662        assert_eq!(
663            output,
664            r#"Json expect::integer() error at root:
665    integer is not negative
666    received 123"#
667        );
668    }
669
670    #[test]
671    fn it_should_be_false_for_positive_u64() {
672        let left = json!(123_u64);
673        let right = json!(expect::integer().negative());
674
675        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
676        assert_eq!(
677            output,
678            r#"Json expect::integer() error at root:
679    integer is not negative
680    received 123"#
681        );
682    }
683}
684
685#[cfg(test)]
686mod test_less_than {
687    use crate::expect;
688    use crate::expect_json_eq;
689    use pretty_assertions::assert_eq;
690    use serde_json::json;
691
692    #[test]
693    fn it_should_be_true_for_correct_positive_comparison() {
694        let left = json!(100_u64);
695        let right = json!(expect::integer().less_than(101));
696        let output = expect_json_eq(&left, &right);
697        assert!(output.is_ok(), "{output:#?}");
698    }
699
700    #[test]
701    fn it_should_be_false_for_equal_values() {
702        let left = json!(100_u64);
703        let right = json!(expect::integer().less_than(100));
704        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
705        assert_eq!(
706            output,
707            "Json expect::integer() error at root:
708    integer is out of bounds,
709    expected less than 100
710    received 100"
711        );
712    }
713
714    #[test]
715    fn it_should_be_false_for_incorrect_positive_comparison() {
716        let left = json!(101_u64);
717        let right = json!(expect::integer().less_than(100));
718        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
719        assert_eq!(
720            output,
721            "Json expect::integer() error at root:
722    integer is out of bounds,
723    expected less than 100
724    received 101"
725        );
726    }
727
728    #[test]
729    fn it_should_be_true_for_correct_negative_positive_mix() {
730        let left = json!(-1);
731        let right = json!(expect::integer().less_than(0));
732        let output = expect_json_eq(&left, &right);
733        assert!(output.is_ok(), "{output:#?}");
734    }
735
736    #[test]
737    fn it_should_be_true_for_correct_negative_comparison() {
738        let left = json!(-100);
739        let right = json!(expect::integer().less_than(-99));
740        let output = expect_json_eq(&left, &right);
741        assert!(output.is_ok(), "{output:#?}");
742    }
743}
744
745#[cfg(test)]
746mod test_less_than_equal {
747    use crate::expect;
748    use crate::expect_json_eq;
749    use pretty_assertions::assert_eq;
750    use serde_json::json;
751
752    #[test]
753    fn it_should_be_true_for_correct_positive_comparison() {
754        let left = json!(100_u64);
755        let right = json!(expect::integer().less_than_equal(101));
756        let output = expect_json_eq(&left, &right);
757        assert!(output.is_ok(), "{output:#?}");
758    }
759
760    #[test]
761    fn it_should_be_true_for_equal_values() {
762        let left = json!(100_u64);
763        let right = json!(expect::integer().less_than_equal(100));
764        let output = expect_json_eq(&left, &right);
765        assert!(output.is_ok(), "{output:#?}");
766    }
767
768    #[test]
769    fn it_should_be_false_for_incorrect_positive_comparison() {
770        let left = json!(101_u64);
771        let right = json!(expect::integer().less_than_equal(100));
772        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
773        assert_eq!(
774            output,
775            "Json expect::integer() error at root:
776    integer is out of bounds,
777    expected less than equal 100
778    received 101"
779        );
780    }
781
782    #[test]
783    fn it_should_be_true_for_correct_negative_positive_mix() {
784        let left = json!(-1);
785        let right = json!(expect::integer().less_than_equal(0));
786        let output = expect_json_eq(&left, &right);
787        assert!(output.is_ok(), "{output:#?}");
788    }
789
790    #[test]
791    fn it_should_be_true_for_correct_negative_comparison() {
792        let left = json!(-100);
793        let right = json!(expect::integer().less_than_equal(-99));
794        let output = expect_json_eq(&left, &right);
795        assert!(output.is_ok(), "{output:#?}");
796    }
797}
798
799#[cfg(test)]
800mod test_greater_than {
801    use crate::expect;
802    use crate::expect_json_eq;
803    use pretty_assertions::assert_eq;
804    use serde_json::json;
805
806    #[test]
807    fn it_should_be_true_for_correct_positive_comparison() {
808        let left = json!(101_u64);
809        let right = json!(expect::integer().greater_than(100));
810        let output = expect_json_eq(&left, &right);
811        assert!(output.is_ok(), "{output:#?}");
812    }
813
814    #[test]
815    fn it_should_be_false_for_equal_values() {
816        let left = json!(100_u64);
817        let right = json!(expect::integer().greater_than(100));
818        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
819        assert_eq!(
820            output,
821            "Json expect::integer() error at root:
822    integer is out of bounds,
823    expected greater than 100
824    received 100"
825        );
826    }
827
828    #[test]
829    fn it_should_be_false_for_incorrect_positive_comparison() {
830        let left = json!(100_u64);
831        let right = json!(expect::integer().greater_than(101));
832        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
833        assert_eq!(
834            output,
835            "Json expect::integer() error at root:
836    integer is out of bounds,
837    expected greater than 101
838    received 100"
839        );
840    }
841
842    #[test]
843    fn it_should_be_true_for_correct_negative_positive_mix() {
844        let left = json!(0);
845        let right = json!(expect::integer().greater_than(-1));
846        let output = expect_json_eq(&left, &right);
847        assert!(output.is_ok(), "{output:#?}");
848    }
849
850    #[test]
851    fn it_should_be_true_for_correct_negative_comparison() {
852        let left = json!(-99);
853        let right = json!(expect::integer().greater_than(-100));
854        let output = expect_json_eq(&left, &right);
855        assert!(output.is_ok(), "{output:#?}");
856    }
857}
858
859#[cfg(test)]
860mod test_greater_than_equal {
861    use crate::expect;
862    use crate::expect_json_eq;
863    use pretty_assertions::assert_eq;
864    use serde_json::json;
865
866    #[test]
867    fn it_should_be_true_for_correct_positive_comparison() {
868        let left = json!(101_u64);
869        let right = json!(expect::integer().greater_than_equal(100));
870        let output = expect_json_eq(&left, &right);
871        assert!(output.is_ok(), "{output:#?}");
872    }
873
874    #[test]
875    fn it_should_be_true_for_equal_values() {
876        let left = json!(100_u64);
877        let right = json!(expect::integer().greater_than_equal(100));
878        let output = expect_json_eq(&left, &right);
879        assert!(output.is_ok(), "{output:#?}");
880    }
881
882    #[test]
883    fn it_should_be_false_for_incorrect_positive_comparison() {
884        let left = json!(100_u64);
885        let right = json!(expect::integer().greater_than_equal(101));
886        let output = expect_json_eq(&left, &right).unwrap_err().to_string();
887        assert_eq!(
888            output,
889            "Json expect::integer() error at root:
890    integer is out of bounds,
891    expected greater than equal 101
892    received 100"
893        );
894    }
895
896    #[test]
897    fn it_should_be_true_for_correct_negative_positive_mix() {
898        let left = json!(0);
899        let right = json!(expect::integer().greater_than_equal(-1));
900        let output = expect_json_eq(&left, &right);
901        assert!(output.is_ok(), "{output:#?}");
902    }
903
904    #[test]
905    fn it_should_be_true_for_correct_negative_comparison() {
906        let left = json!(-99);
907        let right = json!(expect::integer().greater_than_equal(-100));
908        let output = expect_json_eq(&left, &right);
909        assert!(output.is_ok(), "{output:#?}");
910    }
911}