use javascript::{Value, evaluate_script};
#[test]
fn bigint_arithmetic_and_mixing_should_behave_per_spec() {
let r1 = evaluate_script("1n + 2n", None::<&std::path::Path>);
match r1 {
Ok(Value::BigInt(h)) => assert!(h.to_string() == "3"),
_ => panic!("expected BigInt result for 1n + 2n, got {:?}", r1),
}
let r2 = evaluate_script("1n + 1", None::<&std::path::Path>);
assert!(r2.is_err(), "Expected TypeError when mixing BigInt and Number");
let r3 = evaluate_script("5n - 2", None::<&std::path::Path>);
assert!(r3.is_err(), "Expected TypeError for 5n - 2");
let r4 = evaluate_script("1n == 1", None::<&std::path::Path>);
match r4 {
Ok(Value::Boolean(b)) => assert!(b, "1n == 1 should be true"),
Ok(Value::Number(n)) => assert_eq!(n, 1.0), other => panic!("unexpected result for 1n == 1: {:?}", other),
}
let r5 = evaluate_script("1n === 1", None::<&std::path::Path>);
match r5 {
Ok(Value::Boolean(b)) => assert!(!b, "1n === 1 should be false"),
Ok(Value::Number(n)) => assert_eq!(n, 0.0), other => panic!("unexpected result for 1n === 1: {:?}", other),
}
let r6 = evaluate_script("2n > 1", None::<&std::path::Path>);
match r6 {
Ok(Value::Boolean(b)) => assert!(b, "2n > 1 should be true"),
Ok(Value::Number(n)) => assert_eq!(n, 1.0),
other => panic!("unexpected result for 2n > 1: {:?}", other),
}
let r7 = evaluate_script("1n < 1.5", None::<&std::path::Path>);
match r7 {
Ok(Value::Boolean(b)) => assert!(b, "1n < 1.5 should be true"),
Ok(Value::Number(n)) => assert_eq!(n, 1.0),
other => panic!("unexpected result for 1n < 1.5: {:?}", other),
}
let r8 = evaluate_script("'x' + 1n", None::<&std::path::Path>);
match r8 {
Ok(Value::String(s)) => assert_eq!(String::from_utf16_lossy(&s), "x1"),
other => panic!("expected string 'x1', got {:?}", other),
}
}