use rbatis_codegen::ops::PartialEq;
use rbs::Value;
#[test]
fn test_value_eq_value() {
let v1 = Value::I32(10);
let v2 = Value::I32(10);
let v3 = Value::I32(20);
let v4 = Value::String("10".to_string());
assert!(v1.op_eq(&v2));
assert!(!v1.op_eq(&v3));
assert!(!v1.op_eq(&v4));
}
#[test]
fn test_reference_variants() {
let v1 = Value::I32(10);
let v2 = Value::I32(10);
let v1_ref = &v1;
let v2_ref = &v2;
let v1_ref_ref = &v1_ref;
assert!(v1_ref.op_eq(&v2));
assert!(v1_ref.op_eq(&v2_ref));
assert!(v1_ref.op_eq(&v1_ref_ref));
assert!(v1_ref_ref.op_eq(&v1_ref_ref));
assert!(v1_ref_ref.op_eq(&v2));
assert!(v1.op_eq(&v2_ref));
assert!(v1.op_eq(&v1_ref_ref));
}
#[test]
fn test_primitive_eq_value() {
let v_i32 = Value::I32(10);
let v_f64 = Value::F64(10.0);
let v_bool = Value::Bool(true);
let v_str = Value::String("hello".to_string());
assert!(10i32.op_eq(&v_i32));
assert!(10i64.op_eq(&v_i32));
assert!(10u32.op_eq(&v_i32));
assert!(10u64.op_eq(&v_i32));
assert!(!20i32.op_eq(&v_i32));
assert!(10.0f64.op_eq(&v_f64));
assert!(10.0f32.op_eq(&v_f64));
assert!(!11.0f64.op_eq(&v_f64));
assert!(true.op_eq(&v_bool));
assert!(!false.op_eq(&v_bool));
assert!("hello".op_eq(&v_str));
assert!(!"world".op_eq(&v_str));
let hello_string = "hello".to_string();
assert!(hello_string.op_eq(&v_str));
}
#[test]
fn test_value_eq_primitive() {
let v_i32 = Value::I32(10);
let v_f64 = Value::F64(10.0);
let v_bool = Value::Bool(true);
let v_str = Value::String("hello".to_string());
assert!(v_i32.op_eq(&10i32));
assert!(v_i32.op_eq(&10i64));
assert!(v_i32.op_eq(&10u32));
assert!(v_i32.op_eq(&10u64));
assert!(!v_i32.op_eq(&20i32));
assert!(v_f64.op_eq(&10.0f64));
assert!(v_f64.op_eq(&10.0f32));
assert!(!v_f64.op_eq(&11.0f64));
assert!(v_bool.op_eq(&true));
assert!(!v_bool.op_eq(&false));
assert!(v_str.op_eq(&"hello"));
assert!(!v_str.op_eq(&"world"));
let hello_string = "hello".to_string();
assert!(v_str.op_eq(&hello_string));
}
#[test]
fn test_string_eq_number() {
let v_str_10 = Value::String("10".to_string());
let v_str_10_0 = Value::String("10.0".to_string());
let v_str_true = Value::String("true".to_string());
println!("\"10\".op_eq(&10i32): {}", v_str_10.op_eq(&10i32));
println!("\"10.0\".op_eq(&10.0f64): {}", v_str_10_0.op_eq(&10.0f64));
println!("\"true\".op_eq(&true): {}", v_str_true.op_eq(&true));
}
#[test]
fn test_cross_type_eq() {
let v_i32 = Value::I32(10);
let v_f64 = Value::F64(10.0);
let v_bool = Value::Bool(true);
let v_str = Value::String("hello".to_string());
println!("i32(10).op_eq(&f64(10.0)): {}", v_i32.op_eq(&v_f64));
println!("i32(10).op_eq(&bool(true)): {}", v_i32.op_eq(&v_bool));
println!("i32(10).op_eq(&str(\"hello\")): {}", v_i32.op_eq(&v_str));
println!("f64(10.0).op_eq(&bool(true)): {}", v_f64.op_eq(&v_bool));
println!("f64(10.0).op_eq(&str(\"hello\")): {}", v_f64.op_eq(&v_str));
println!("bool(true).op_eq(&str(\"hello\")): {}", v_bool.op_eq(&v_str));
}