use super::content_hash;
use serde_json::json;
#[test]
fn hash_is_key_order_independent() {
let a = json!({ "alpha": 1, "beta": { "x": true, "y": [1, 2] } });
let b = json!({ "beta": { "y": [1, 2], "x": true }, "alpha": 1 });
assert_eq!(content_hash(&a).unwrap(), content_hash(&b).unwrap());
}
#[test]
fn hash_is_array_order_sensitive() {
let a = json!({ "items": [1, 2] });
let b = json!({ "items": [2, 1] });
assert_ne!(content_hash(&a).unwrap(), content_hash(&b).unwrap());
}
#[test]
fn hash_detects_value_change() {
let a = json!({ "threshold": 10 });
let b = json!({ "threshold": 11 });
assert_ne!(content_hash(&a).unwrap(), content_hash(&b).unwrap());
}
#[test]
fn typed_and_value_forms_hash_alike() {
let typed = ("threshold", [1.5_f64, 2.0]);
assert_eq!(
content_hash(&typed).unwrap(),
content_hash(&json!(["threshold", [1.5, 2.0]])).unwrap()
);
}
#[test]
fn a_non_finite_float_is_refused_not_hashed_as_null() {
assert!(content_hash(&f64::NAN).is_err());
assert_eq!(
serde_json::to_value(f64::NAN).unwrap(),
serde_json::Value::Null,
"if this stops holding, the reason in content_hash's docs is stale"
);
}