diff --git a/src/bin.rs b/src/bin.rs index afcf538..659faf5 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -166,7 +166,52 @@ impl CompareContextElement for serde_json::Value { None => (), Some(other_json_value) => { return match (self, other_json_value) { - // TODO: Implement + ( + serde_json::Value::Bool(self_boolean), + serde_json::Value::Bool(other_boolean), + ) => self_boolean.partial_cmp(other_boolean), + ( + serde_json::Value::Number(self_number), + serde_json::Value::Number(other_number), + ) => match ( + self_number.as_f64(), + other_number.as_f64(), + self_number.as_u64(), + other_number.as_u64(), + self_number.as_i64(), + other_number.as_i64(), + ) { + (_, _, _, _, Some(self_int), Some(other_int)) => { + self_int.partial_cmp(&other_int) + } + (_, _, Some(self_uint), Some(other_uint), _, _) => { + self_uint.partial_cmp(&other_uint) + } + (_, _, Some(_self_uint), _, _, Some(_other_int)) => { + // If the previous matches did not catch + // it, then other must be negative and + // self must be larger than can be + // represented with an i64, therefore self + // is greater than other. + Some(Ordering::Greater) + } + (_, _, _, Some(_other_uint), Some(_self_int), _) => { + // If the previous matches did not catch + // it, then self must be negative and + // other must be larger than can be + // represented with an i64, therefore + // other is greater than self. + Some(Ordering::Less) + } + (Some(self_float), Some(other_float), _, _, _, _) => { + self_float.partial_cmp(&other_float) + } + _ => panic!("This should be impossible since u64 and i64 can both be converted to floats"), + }, + ( + serde_json::Value::String(self_string), + serde_json::Value::String(other_string), + ) => self_string.partial_cmp(other_string), _ => None, }; }