Debian Codegraph @

src/ext/cmp.rs

raw symbols SCIP
1 use num_cmprust-analyzer cargo num-cmp 0.1.0 crate/::NumCmprust-analyzer cargo num-cmp 0.1.0 NumCmp#;
2 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::{Maprust-analyzer cargo serde_json 1.0.145 map/Map#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#};
3
4 macro_rules! num_cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/num_cmp! {
5 ($left:expr, $right:expr) => {
6 if let Some(b) = $right.as_u64() {
7 NumCmp::num_eq($left, b)
8 } else if let Some(b) = $right.as_i64() {
9 NumCmp::num_eq($left, b)
10 } else {
11 #[cfg(feature = "arbitrary-precision")]
12 {
13 use crate::ext::numeric::bignum;
14 use fraction::BigFraction;
15
16 let left_frac = BigFraction::from($left);
17
18 // Check BigInt/BigFraction BEFORE f64 to avoid precision loss
19 if let Some(right_bigint) = bignum::try_parse_bigint($right) {
20 let right_frac = BigFraction::from(right_bigint);
21 left_frac == right_frac
22 } else if let Some(right_frac) = bignum::try_parse_bigfraction($right) {
23 left_frac == right_frac
24 } else if let Some(b) = $right.as_f64() {
25 // Fallback to f64 for scientific notation or other cases
26 left_frac == BigFraction::from(b)
27 } else {
28 // Can't parse right - not equal
29 false
30 }
31 }
32 #[cfg(not(feature = "arbitrary-precision"))]
33 {
34 if let Some(b) = $right.as_f64() {
35 NumCmp::num_eq($left, b)
36 } else {
37 unreachable!("Numbers always fit in u64/i64/f64 without arbitrary-precision")
38 }
39 }
40 }
41 };
42 }
43
44 /// Compare two JSON numbers for equality with arbitrary precision support
45 #[inline]
46 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn equal_numbersrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal_numbers().(left: &serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Numberrust-analyzer cargo serde_json 1.0.145 number/Number#, right: &serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Numberrust-analyzer cargo serde_json 1.0.145 number/Number#) -> bool {
47 #[cfg(feature = "arbitrary-precision")]
48 {
49 use craterust-analyzer cargo jsonschema 0.37.4 crate/::extrust-analyzer cargo jsonschema 0.37.4 ext/::numericrust-analyzer cargo jsonschema 0.37.4 ext/numeric/::bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/;
50 use fractionrust-analyzer cargo fraction 0.15.3 crate/::BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#;
51
52 // Check BigInt/BigFraction first to avoid precision loss from f64 conversion
53 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(left_bigint) = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigint().(left) {
54 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(right_bigint) = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigint().(right) {
55 left_bigint rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq().==rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq(). rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq().right_bigint
56 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b) = right.as_u64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_u64().() {
57 left_bigint rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq().==rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq(). rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq().num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::fromrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][`From<u64>`]from().(b)
58 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b) = right.as_i64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_i64().() {
59 left_bigint rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq().==rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq(). rust-analyzer cargo num-bigint 0.4.6 bigint/impl#[BigInt][`PartialEq<Self>`]eq().num_bigintrust-analyzer cargo num-bigint 0.4.6 crate/::BigIntrust-analyzer cargo num-bigint 0.4.6 bigint/BigInt#::fromrust-analyzer cargo num-bigint 0.4.6 bigint/convert/impl#[BigInt][`From<i64>`]from().(b)
60 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(right_frac) = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigfractionrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigfraction().(right) {
61 BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<BigInt>`]from().(left_bigint) rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().right_frac
62 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b) = right.as_f64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_f64().() {
63 BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<BigInt>`]from().(left_bigint) rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<f64>`]from().(b)
64 } else {
65 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("Right is not parseable as any numeric type - should not happen for valid JSON numbers")
66 }
67 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(left_frac) = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigfractionrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigfraction().(left) {
68 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(right_frac) = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigfractionrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigfraction().(right) {
69 left_frac rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().right_frac
70 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(right_bigint) = bignumrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/::try_parse_bigintrust-analyzer cargo jsonschema 0.37.4 ext/numeric/bignum/try_parse_bigint().(right) {
71 left_frac rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<BigInt>`]from().(right_bigint)
72 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b) = right.as_u64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_u64().() {
73 left_frac rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<u64>`]from().(b)
74 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b) = right.as_i64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_i64().() {
75 left_frac rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<i64>`]from().(b)
76 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b) = right.as_f64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_f64().() {
77 left_frac rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`PartialEq<Self>`]eq().BigFractionrust-analyzer cargo fraction 0.15.3 prelude/BigFraction#::fromrust-analyzer cargo fraction 0.15.3 fraction/generic_fraction/impl#[`GenericFraction<T>`][`From<f64>`]from().(b)
78 } else {
79 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("Right is not parseable as any numeric type - should not happen for valid JSON numbers")
80 }
81 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a) = left.as_u64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_u64().() {
82 num_cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/num_cmp!!(a, right)
83 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a) = left.as_i64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_i64().() {
84 num_cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/num_cmp!!(a, right)
85 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a) = left.as_f64rust-analyzer cargo serde_json 1.0.145 number/impl#[Number]as_f64().() {
86 num_cmprust-analyzer cargo jsonschema 0.37.4 ext/cmp/num_cmp!!(a, right)
87 } else {
88 // Left is a number in scientific notation that doesn't fit in f64
89 // (e.g., 1e309, 1e400). With arbitrary-precision, these are stored as
90 // strings but can't be converted to any numeric type we support.
91 // Return false as we can't reliably compare them.
92 false
93 }
94 }
95 #[cfg(not(feature = "arbitrary-precision"))]
96 {
97 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a) = left.as_u64() {
98 num_cmprust-analyzer cargo num-cmp 0.1.0 crate/!(a, right)
99 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a) = left.as_i64() {
100 num_cmprust-analyzer cargo num-cmp 0.1.0 crate/!(a, right)
101 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a) = left.as_f64() {
102 num_cmprust-analyzer cargo num-cmp 0.1.0 crate/!(a, right)
103 } else {
104 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("Numbers always fit in u64/i64/f64 without arbitrary-precision")
105 }
106 }
107 }
108
109 /// Tests for two JSON values to be equal using the JSON Schema semantic.
110 #[must_use]
111 #[allow(clippy::missing_panics_doc)]
112 pub fn equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(left: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, right: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) -> bool {
113 match (left, right) {
114 (Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(left), Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Stringrust-analyzer cargo serde_json 1.0.145 value/Value#String#(right)) => left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().right,
115 (Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Boolrust-analyzer cargo serde_json 1.0.145 value/Value#Bool#(left), Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Boolrust-analyzer cargo serde_json 1.0.145 value/Value#Bool#(right)) => left rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().right,
116 (Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Nullrust-analyzer cargo serde_json 1.0.145 value/Value#Null#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Nullrust-analyzer cargo serde_json 1.0.145 value/Value#Null#) => true,
117 (Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Numberrust-analyzer cargo serde_json 1.0.145 value/Value#Number#(left), Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Numberrust-analyzer cargo serde_json 1.0.145 value/Value#Number#(right)) => equal_numbersrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal_numbers().(left, right),
118 (Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Arrayrust-analyzer cargo serde_json 1.0.145 value/Value#Array#(left), Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Arrayrust-analyzer cargo serde_json 1.0.145 value/Value#Array#(right)) => equal_arraysrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal_arrays().(left, right),
119 (Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(left), Valuerust-analyzer cargo serde_json 1.0.145 value/Value#::Objectrust-analyzer cargo serde_json 1.0.145 value/Value#Object#(right)) => equal_objectsrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal_objects().(left, right),
120 (_, _) => false,
121 }
122 }
123
124 #[inline]
125 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn equal_arraysrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal_arrays().(left: &[Valuerust-analyzer cargo serde_json 1.0.145 value/Value#], right: &[Valuerust-analyzer cargo serde_json 1.0.145 value/Value#]) -> bool {
126 left.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().right.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() && {
127 let mut idx = 0_usize;
128 while idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().left.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() {
129 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(&left[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &right[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().idx]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) {
130 return false;
131 }
132 idx rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
133 }
134 true
135 }
136 }
137
138 #[inline]
139 pub(craterust-analyzer cargo jsonschema 0.37.4 crate/) fn equal_objectsrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal_objects().(left: &Maprust-analyzer cargo serde_json 1.0.145 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>, right: &Maprust-analyzer cargo serde_json 1.0.145 map/Map#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#>) -> bool {
140 left.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().right.lenrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]len().()
141 && left
142 .iterrust-analyzer cargo serde_json 1.0.145 map/impl#[`Map<String, Value>`]iter().()
143 .ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(right)
144 .allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|((ka, va), (kb, vb))| ka rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().kb && equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(va, vb))
145 }
146
147 #[cfg(test)]
148 mod testsrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/ {
149 use superrust-analyzer cargo jsonschema 0.37.4 ext/cmp/::equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().;
150 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::{jsonrust-analyzer cargo serde_json 1.0.145 macros/json!, Valuerust-analyzer cargo serde_json 1.0.145 value/Value#};
151 use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:;
152
153 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1.0))]
154 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([2]), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([2.0]))]
155 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().3]), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().3.0]))]
156 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1.0}))]
157 fn are_equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/are_equal().(left: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, right: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) {
158 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(left, right));
159 }
160
161 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(1), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(2.0))]
162 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([]), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!(["foo"]))]
163 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().3]), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!([-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().4.0]))]
164 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(&jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1}), &jsonrust-analyzer cargo serde_json 1.0.145 macros/json!!({"a": 1.0, "b": 2}))]
165 fn are_not_equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/are_not_equal().(left: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#, right: &Valuerust-analyzer cargo serde_json 1.0.145 value/Value#) {
166 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(left, right));
167 }
168
169 #[cfg(feature = "arbitrary-precision")]
170 mod arbitrary_precisionrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/arbitrary_precision/ {
171 use superrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/::equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().;
172 use serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::Valuerust-analyzer cargo serde_json 1.0.145 value/Value#;
173 use test_caserust-analyzer cargo test-case 3.3.1 crate/::test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:;
174
175 fn parse_jsonrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/arbitrary_precision/parse_json().(s: &str) -> Valuerust-analyzer cargo serde_json 1.0.145 value/Value# {
176 serde_jsonrust-analyzer cargo serde_json 1.0.145 crate/::from_strrust-analyzer cargo serde_json 1.0.145 de/from_str().(s).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
177 }
178 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.1", "0.1", true; "exact decimal match")]
179 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.1", "0.10", true; "decimal with trailing zero")]
180 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.1", "0.100000", true; "decimal with many trailing zeros")]
181 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.1", "0.2", false; "different decimals")]
182 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.3", "0.30", true; "another trailing zero case")]
183 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1.0", "1", true; "decimal vs integer")]
184 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1.00", "1.0", true; "decimals with different trailing zeros")]
185 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(
186 "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.5",
187 "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.5",
188 true;
189 "huge decimal self equality"
190 )]
191 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(
192 "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.5",
193 "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.6",
194 false;
195 "huge decimals different"
196 )]
197 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(
198 "99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.5",
199 "100",
200 false;
201 "huge decimal vs small integer"
202 )]
203 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("18446744073709551616", "18446744073709551616", true; "large integer self equality")]
204 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("18446744073709551616", "18446744073709551617", false; "large integers different")]
205 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("99999999999999999999999999999999999999", "99999999999999999999999999999999999999", true; "very large integer equality")]
206 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("99999999999999999999999999999999999999", "100", false; "very large vs small integer")]
207 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("100", "100.0", true; "small integer vs decimal")]
208 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.1", "1", false; "small decimal vs integer")]
209 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1.0", "1", true; "decimal one vs integer one")]
210 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("18446744073709551616", "100.5", false; "large int vs decimal")]
211 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("18446744073709551616.0", "18446744073709551616", true; "large int as decimal vs large int")]
212 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-0.1", "-0.1", true; "negative decimal equality")]
213 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-0.1", "-0.10", true; "negative decimal trailing zero")]
214 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-18446744073709551616", "-18446744073709551616", true; "negative large int")]
215 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-18446744073709551616", "18446744073709551616", false; "negative vs positive large")]
216 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-100.5", "-100.5", true; "negative decimal match")]
217 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-100.5", "100.5", false; "negative vs positive decimal")]
218 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0", "0.0", true; "zero integer vs decimal")]
219 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.0", "0.00", true; "zero decimals with different precision")]
220 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-0.0", "0.0", true; "negative zero vs positive zero")]
221 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1e10", "10000000000", true; "scientific notation vs integer")]
222 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1e19", "10000000000000000000", true; "scientific integer beyond i64")]
223 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1e19", "10000000000000000001", false; "scientific integer mismatch")]
224 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1.5e2", "150", true; "decimal scientific vs integer")]
225 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1.5e2", "150.0", true; "decimal scientific vs decimal")]
226 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r"[0.1, 0.2, 0.3]", r"[0.1, 0.2, 0.3]", true; "array exact match")]
227 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r"[0.1, 0.2]", r"[0.10, 0.20]", true; "array with trailing zeros")]
228 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r"[18446744073709551616]", r"[18446744073709551616]", true; "array with large integer")]
229 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r"[0.1, 0.2]", r"[0.1, 0.3]", false; "array different values")]
230 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"value": 0.1}"#, r#"{"value": 0.1}"#, true; "object exact match")]
231 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"value": 0.1}"#, r#"{"value": 0.10}"#, true; "object with trailing zero")]
232 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"id": 18446744073709551616}"#, r#"{"id": 18446744073709551616}"#, true; "object with large integer")]
233 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:(r#"{"value": 0.1}"#, r#"{"value": 0.2}"#, false; "object different values")]
234 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("18446744073709551616", "-1", false; "large positive bigint vs negative i64")]
235 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("18446744073709551616", "-100", false; "large positive bigint vs negative i64 small")]
236 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-18446744073709551616", "-1", false; "large negative bigint vs small negative i64")]
237 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("18446744073709551616", "1e10", false; "large bigint vs scientific notation f64")]
238 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("10000000000", "1e10", true; "bigint vs scientific notation equal")]
239 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("-18446744073709551616", "-1.5e3", false; "negative bigint vs scientific notation")]
240 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.5", "5e-1", true; "bigfraction vs scientific notation equal")]
241 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.3", "3e-1", true; "bigfraction vs scientific equal exact")]
242 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("123.456", "1.23456e2", true; "bigfraction vs scientific notation")]
243 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("0.1", "1e-2", false; "bigfraction vs scientific not equal")]
244 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1e309", "1e309", true; "huge scientific notation now handled")]
245 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1e400", "1e400", true; "extreme scientific notation now handled")]
246 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1e-400", "1e-400", true; "extreme small scientific notation self equality")]
247 #[test_caserust-analyzer cargo test-case-macros 3.3.1 test_case:("1e309", "1", false; "huge scientific notation vs integer")]
248 fn arbitrary_precision_equalityrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/arbitrary_precision/arbitrary_precision_equality().(left_str: &str, right_str: &str, should_equal: bool) {
249 let left = parse_jsonrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/arbitrary_precision/parse_json().(left_str);
250 let right = parse_jsonrust-analyzer cargo jsonschema 0.37.4 ext/cmp/tests/arbitrary_precision/parse_json().(right_str);
251 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(equalrust-analyzer cargo jsonschema 0.37.4 ext/cmp/equal().(&left, &right), should_equal);
252 }
253 }
254 }