use dist_agent_lang::lexer::Lexer;
use dist_agent_lang::parser::Parser;
use dist_agent_lang::runtime::values::Value;
use dist_agent_lang::{execute_source, Runtime};
#[test]
fn test_evaluate_expression_equal_operator() {
let code = "let x = 5 == 5;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute equality comparison");
let var_result = runtime.get_variable("x");
if let Ok(Value::Bool(b)) = var_result {
assert!(b, "x should be true (5 == 5)");
}
}
#[test]
fn test_evaluate_expression_not_equal_operator() {
let code = "let x = 5 != 10;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute not-equal comparison");
}
#[test]
fn test_evaluate_expression_arithmetic_plus() {
let code = "let x = 5 + 3;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute addition");
let var_result = runtime.get_variable("x");
if let Ok(Value::Int(val)) = var_result {
assert_eq!(val, 8, "5 + 3 should be 8, not 2 (5-3) or 15 (5*3)");
}
}
#[test]
fn test_evaluate_expression_arithmetic_minus() {
let code = "let x = 5 - 3;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute subtraction");
let var_result = runtime.get_variable("x");
if let Ok(Value::Int(val)) = var_result {
assert_eq!(val, 2, "5 - 3 should be 2, not 8 (5+3) or 15 (5*3)");
}
}
#[test]
fn test_evaluate_expression_arithmetic_multiply() {
let code = "let x = 5 * 3;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute multiplication");
let var_result = runtime.get_variable("x");
if let Ok(Value::Int(val)) = var_result {
assert_eq!(val, 15, "5 * 3 should be 15, not 8 (5+3) or 2 (5-3)");
}
}
#[test]
fn test_evaluate_expression_comparison_less() {
let code = "let x = 5 < 10;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute less-than comparison");
let var_result = runtime.get_variable("x");
if let Ok(Value::Bool(b)) = var_result {
assert!(b, "5 < 10 should be true");
}
}
#[test]
fn test_evaluate_expression_comparison_greater() {
let code = "let x = 10 > 5;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute greater-than comparison");
let var_result = runtime.get_variable("x");
if let Ok(Value::Bool(b)) = var_result {
assert!(b, "10 > 5 should be true");
}
}
#[test]
fn test_call_auth_function_has_role_with_array() {
use std::collections::HashMap;
let mut runtime = Runtime::new();
let mut session_fields = HashMap::new();
session_fields.insert("user_id".to_string(), Value::String("user123".to_string()));
session_fields.insert(
"roles".to_string(),
Value::Array(vec![
Value::String("admin".to_string()),
Value::String("editor".to_string()),
]),
);
session_fields.insert(
"permissions".to_string(),
Value::Array(vec![
Value::String("read".to_string()),
Value::String("write".to_string()),
]),
);
session_fields.insert("created_at".to_string(), Value::Int(1000));
session_fields.insert("expires_at".to_string(), Value::Int(2000));
let session_value = Value::Struct("Session".to_string(), session_fields);
runtime.set_variable("session".to_string(), session_value);
let args = vec![
Value::String("session".to_string()),
Value::String("admin".to_string()),
];
let result = runtime.call_function("auth::has_role", &args);
assert!(result.is_ok(), "auth::has_role should succeed with array roles - if Array match arm is deleted, this fails");
if let Ok(Value::Bool(_)) = result {
} else {
panic!("auth::has_role should return a boolean when roles array is provided");
}
}
#[test]
fn test_call_auth_function_has_permission_with_array() {
use std::collections::HashMap;
let mut runtime = Runtime::new();
let mut session_fields = HashMap::new();
session_fields.insert("user_id".to_string(), Value::String("user123".to_string()));
session_fields.insert(
"roles".to_string(),
Value::Array(vec![Value::String("admin".to_string())]),
);
session_fields.insert(
"permissions".to_string(),
Value::Array(vec![
Value::String("read".to_string()),
Value::String("write".to_string()),
Value::String("delete".to_string()),
]),
);
session_fields.insert("created_at".to_string(), Value::Int(1000));
session_fields.insert("expires_at".to_string(), Value::Int(2000));
let session_value = Value::Struct("Session".to_string(), session_fields);
runtime.set_variable("session".to_string(), session_value);
let args = vec![
Value::String("session".to_string()),
Value::String("write".to_string()),
];
let result = runtime.call_function("auth::has_permission", &args);
assert!(result.is_ok(), "auth::has_permission should succeed with array permissions - if Array match arm is deleted, this fails");
if let Ok(Value::Bool(_)) = result {
} else {
panic!("auth::has_permission should return a boolean when permissions array is provided");
}
}
#[test]
fn test_call_log_function_info_exact_args() {
let code = r#"
log::info("test", "message");
"#;
let tokens = Lexer::new(code).tokenize_immutable();
if let Ok(tokens) = tokens {
let mut parser = Parser::new(tokens);
if let Ok(program) = parser.parse() {
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "log::info with 2 args should succeed");
}
}
}
#[test]
fn test_call_log_function_info_wrong_args() {
let code = r#"
log::info("test");
"#;
let tokens = Lexer::new(code).tokenize_immutable();
if let Ok(tokens) = tokens {
let mut parser = Parser::new(tokens);
if let Ok(program) = parser.parse() {
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(
result.is_ok() || result.is_err(),
"Should handle wrong arg count"
);
}
}
}
#[test]
fn test_call_log_function_audit_exact_args() {
let code = r#"
log::audit("event", "details");
"#;
let tokens = Lexer::new(code).tokenize_immutable();
if let Ok(tokens) = tokens {
let mut parser = Parser::new(tokens);
if let Ok(program) = parser.parse() {
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "log::audit with 2 args should succeed");
}
}
}
#[test]
fn test_call_crypto_function_hash() {
let code = r#"
let result = crypto::hash("data", "sha256");
"#;
let tokens = Lexer::new(code).tokenize_immutable();
if let Ok(tokens) = tokens {
let mut parser = Parser::new(tokens);
if let Ok(program) = parser.parse() {
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "crypto::hash should be callable");
}
}
}
#[test]
fn test_call_crypto_function_sign() {
let code = r#"
let result = crypto::sign("data", "key");
"#;
let tokens = Lexer::new(code).tokenize_immutable();
if let Ok(tokens) = tokens {
let mut parser = Parser::new(tokens);
if let Ok(program) = parser.parse() {
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "crypto::sign should be callable");
}
}
}
#[test]
fn test_call_crypto_function_verify() {
let code = r#"
let result = crypto::verify("data", "signature", "key");
"#;
let tokens = Lexer::new(code).tokenize_immutable();
if let Ok(tokens) = tokens {
let mut parser = Parser::new(tokens);
if let Ok(program) = parser.parse() {
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "crypto::verify with 3 args should succeed");
}
}
}
#[test]
fn test_call_crypto_function_verify_wrong_args() {
let code = r#"
let result = crypto::verify("data", "signature");
"#;
let tokens = Lexer::new(code).tokenize_immutable();
if let Ok(tokens) = tokens {
let mut parser = Parser::new(tokens);
if let Ok(program) = parser.parse() {
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(
result.is_ok() || result.is_err(),
"Should handle wrong arg count"
);
}
}
}
#[test]
fn test_value_addition_exact() {
let code = "let x = 10 + 20;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute addition");
let var_result = runtime.get_variable("x");
if let Ok(Value::Int(val)) = var_result {
assert_eq!(
val, 30,
"10 + 20 should be 30, not -10 (10-20) or 200 (10*20)"
);
}
}
#[test]
fn test_value_subtraction_exact() {
let code = "let x = 20 - 10;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute subtraction");
let var_result = runtime.get_variable("x");
if let Ok(Value::Int(val)) = var_result {
assert_eq!(
val, 10,
"20 - 10 should be 10, not 30 (20+10) or 200 (20*10)"
);
}
}
#[test]
fn test_value_multiplication_exact() {
let code = "let x = 5 * 4;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute multiplication");
let var_result = runtime.get_variable("x");
if let Ok(Value::Int(val)) = var_result {
assert_eq!(val, 20, "5 * 4 should be 20, not 9 (5+4) or 1 (5-4)");
}
}
#[test]
fn test_comparison_less_equal_boundary() {
let code = "let x = 10 <= 10;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute less-equal comparison");
let var_result = runtime.get_variable("x");
if let Ok(Value::Bool(b)) = var_result {
assert!(b, "10 <= 10 should be true");
}
}
#[test]
fn test_comparison_greater_equal_boundary() {
let code = "let x = 10 >= 10;";
let tokens = Lexer::new(code).tokenize_immutable().unwrap();
let mut parser = Parser::new(tokens);
let program = parser.parse().unwrap();
let mut runtime = Runtime::new();
let result = runtime.execute_program(program);
assert!(result.is_ok(), "Should execute greater-equal comparison");
let var_result = runtime.get_variable("x");
if let Ok(Value::Bool(b)) = var_result {
assert!(b, "10 >= 10 should be true");
}
}
#[test]
fn test_builtin_add_correct() {
let mut runtime = Runtime::new();
let result = runtime.call_function("add", &[Value::Int(10), Value::Int(20)]);
assert!(result.is_ok(), "add(10, 20) should succeed");
assert_eq!(result.unwrap(), Value::Int(30), "10 + 20 should be 30");
}
#[test]
fn test_builtin_add_wrong_count_0() {
let mut runtime = Runtime::new();
let result = runtime.call_function("add", &[]);
assert!(
result.is_err(),
"add() with 0 args should fail - if != mutated to ==, this incorrectly succeeds"
);
}
#[test]
fn test_builtin_add_wrong_count_1() {
let mut runtime = Runtime::new();
let result = runtime.call_function("add", &[Value::Int(10)]);
assert!(result.is_err(), "add() with 1 arg should fail");
}
#[test]
fn test_builtin_add_wrong_count_3() {
let mut runtime = Runtime::new();
let result = runtime.call_function("add", &[Value::Int(10), Value::Int(20), Value::Int(30)]);
assert!(result.is_err(), "add() with 3 args should fail");
}
#[test]
fn test_builtin_add_wrong_types() {
let mut runtime = Runtime::new();
let result = runtime.call_function("add", &[Value::String("10".to_string()), Value::Int(20)]);
assert!(
result.is_err(),
"add() with string should fail - if Int match arm deleted, this may incorrectly succeed"
);
}
#[test]
fn test_builtin_len_correct() {
let mut runtime = Runtime::new();
let result = runtime.call_function("len", &[Value::String("hello".to_string())]);
assert!(result.is_ok(), "len(\"hello\") should succeed");
assert_eq!(
result.unwrap(),
Value::Int(5),
"\"hello\" length should be 5"
);
}
#[test]
fn test_builtin_len_empty_string() {
let mut runtime = Runtime::new();
let result = runtime.call_function("len", &[Value::String("".to_string())]);
assert!(result.is_ok(), "len(\"\") should succeed");
assert_eq!(
result.unwrap(),
Value::Int(0),
"empty string length must be 0"
);
}
#[test]
fn test_json_parse_empty_text_value() {
use dist_agent_lang::ffi::interface::json_to_value;
let json = serde_json::json!({"text": ""});
let body = json_to_value(&json).expect("json_to_value must succeed");
let text = if let Value::Map(m) = &body {
m.get("text").cloned().unwrap_or(Value::Null)
} else {
panic!("body must be Map")
};
assert_eq!(
text,
Value::String("".to_string()),
"body[\"text\"] must be empty string"
);
}
#[test]
fn test_len_empty_string_via_dal() {
let code = r#"
fn check() {
let body = json::parse("{\"text\":\"\"}");
let text = body["text"];
return len(text) == 0;
}
return check();
"#;
let result = execute_source(code);
assert!(result.is_ok(), "DAL should execute: {:?}", result);
let val = result.unwrap();
assert_eq!(
val,
Value::Bool(true),
"len(text) == 0 must be true when text is \"\", got {:?}",
val
);
}
#[test]
fn test_len_empty_string_via_request_like_map() {
let code = r#"
fn create_request(body_str) {
return {"body": body_str};
}
fn check(req) {
let body = json::parse(req.body);
let text = body["text"];
return len(text) == 0;
}
let req = create_request("{\"text\":\"\"}");
return check(req);
"#;
let result = execute_source(code);
assert!(result.is_ok(), "DAL should execute: {:?}", result);
let val = result.unwrap();
assert_eq!(
val,
Value::Bool(true),
"len(text) == 0 must be true when body comes from request-like map, got {:?}",
val
);
}
#[test]
fn test_builtin_len_wrong_count_0() {
let mut runtime = Runtime::new();
let result = runtime.call_function("len", &[]);
assert!(result.is_err(), "len() with 0 args should fail");
}
#[test]
fn test_builtin_len_wrong_count_2() {
let mut runtime = Runtime::new();
let result = runtime.call_function(
"len",
&[
Value::String("hello".to_string()),
Value::String("world".to_string()),
],
);
assert!(result.is_err(), "len() with 2 args should fail");
}
#[test]
fn test_builtin_len_wrong_type() {
let mut runtime = Runtime::new();
let result = runtime.call_function("len", &[Value::Int(42)]);
assert!(
result.is_err(),
"len() with int should fail - if String match arm deleted, this may incorrectly succeed"
);
}
#[test]
fn test_builtin_print_correct() {
let mut runtime = Runtime::new();
let result = runtime.call_function("print", &[Value::String("test".to_string())]);
assert!(result.is_ok(), "print(\"test\") should succeed");
assert_eq!(result.unwrap(), Value::Null, "print should return Null");
}
#[test]
fn test_builtin_print_no_args() {
let mut runtime = Runtime::new();
let result = runtime.call_function("print", &[]);
assert!(result.is_err(), "print() with no args should fail");
}
#[test]
fn test_builtin_type_correct() {
let mut runtime = Runtime::new();
let result = runtime.call_function("type", &[Value::Int(42)]);
assert!(result.is_ok(), "type(42) should succeed");
if let Ok(Value::String(s)) = result {
assert_eq!(s, "int", "type(42) should return \"int\"");
}
}
#[test]
fn test_builtin_type_wrong_count() {
let mut runtime = Runtime::new();
let result = runtime.call_function("type", &[]);
assert!(result.is_err(), "type() with 0 args should fail");
}
#[test]
fn test_builtin_to_int_correct_int() {
let mut runtime = Runtime::new();
let result = runtime.call_function("to_int", &[Value::Int(42)]);
assert!(result.is_ok(), "to_int(42) should succeed");
assert_eq!(
result.unwrap(),
Value::Int(42),
"to_int(42) should return 42"
);
}
#[test]
fn test_builtin_to_int_correct_string() {
let mut runtime = Runtime::new();
let result = runtime.call_function("to_int", &[Value::String("123".to_string())]);
assert!(result.is_ok(), "to_int(\"123\") should succeed");
assert_eq!(
result.unwrap(),
Value::Int(123),
"to_int(\"123\") should return 123"
);
}
#[test]
fn test_builtin_to_int_wrong_type() {
let mut runtime = Runtime::new();
let result = runtime.call_function("to_int", &[Value::Bool(true)]);
assert!(
result.is_err(),
"to_int(true) should fail - if Int/String match arms deleted, this may incorrectly succeed"
);
}
#[test]
fn test_builtin_to_int_wrong_count() {
let mut runtime = Runtime::new();
let result = runtime.call_function("to_int", &[]);
assert!(result.is_err(), "to_int() with 0 args should fail");
}
#[test]
fn test_builtin_to_bool_correct() {
let mut runtime = Runtime::new();
let result = runtime.call_function("to_bool", &[Value::Bool(true)]);
assert!(result.is_ok(), "to_bool(true) should succeed");
assert_eq!(
result.unwrap(),
Value::Bool(true),
"to_bool(true) should return true"
);
let result = runtime.call_function("to_bool", &[Value::Int(42)]);
assert!(result.is_ok(), "to_bool(42) should succeed");
assert_eq!(
result.unwrap(),
Value::Bool(true),
"to_bool(42) should return true"
);
let result = runtime.call_function("to_bool", &[Value::Int(0)]);
assert!(result.is_ok(), "to_bool(0) should succeed");
assert_eq!(
result.unwrap(),
Value::Bool(false),
"to_bool(0) should return false"
);
let result = runtime.call_function("to_bool", &[Value::String("hello".to_string())]);
assert!(result.is_ok(), "to_bool(\"hello\") should succeed");
assert_eq!(
result.unwrap(),
Value::Bool(true),
"to_bool(\"hello\") should return true"
);
let result = runtime.call_function("to_bool", &[Value::String("".to_string())]);
assert!(result.is_ok(), "to_bool(\"\") should succeed");
assert_eq!(
result.unwrap(),
Value::Bool(false),
"to_bool(\"\") should return false"
);
}
#[test]
fn test_builtin_to_bool_wrong_count() {
let mut runtime = Runtime::new();
let result = runtime.call_function("to_bool", &[]);
assert!(result.is_err(), "to_bool() with 0 args should fail");
}
#[test]
fn test_builtin_to_string_correct() {
let mut runtime = Runtime::new();
let result = runtime.call_function("to_string", &[Value::Int(42)]);
assert!(result.is_ok(), "to_string(42) should succeed");
if let Ok(Value::String(s)) = result {
assert_eq!(s, "42", "to_string(42) should return \"42\"");
}
}
#[test]
fn test_builtin_to_string_wrong_count() {
let mut runtime = Runtime::new();
let result = runtime.call_function("to_string", &[]);
assert!(result.is_err(), "to_string() with 0 args should fail");
}
#[test]
fn test_value_to_string_all_types() {
let runtime = Runtime::new();
let result = runtime.value_to_string(&Value::Int(42));
assert!(result.is_ok(), "value_to_string(Int) should succeed");
assert_eq!(result.unwrap(), "42", "Int(42) should convert to \"42\"");
let result = runtime.value_to_string(&Value::Float(3.15));
assert!(result.is_ok(), "value_to_string(Float) should succeed");
assert!(
result.unwrap().contains("3.15"),
"Float(3.15) should convert to string containing \"3.15\""
);
let result = runtime.value_to_string(&Value::Bool(true));
assert!(result.is_ok(), "value_to_string(Bool) should succeed");
assert_eq!(
result.unwrap(),
"true",
"Bool(true) should convert to \"true\""
);
let result = runtime.value_to_string(&Value::Bool(false));
assert!(
result.is_ok(),
"value_to_string(Bool(false)) should succeed"
);
assert_eq!(
result.unwrap(),
"false",
"Bool(false) should convert to \"false\""
);
let result = runtime.value_to_string(&Value::Null);
assert!(result.is_ok(), "value_to_string(Null) should succeed");
assert_eq!(result.unwrap(), "null", "Null should convert to \"null\"");
let result = runtime.value_to_string(&Value::String("test".to_string()));
assert!(result.is_ok(), "value_to_string(String) should succeed");
assert_eq!(result.unwrap(), "test", "String should return as-is");
}
#[test]
fn test_value_to_string_invalid_type() {
let runtime = Runtime::new();
let result = runtime.value_to_string(&Value::Array(vec![Value::Int(1)]));
assert!(result.is_err(), "value_to_string(Array) should fail");
let result = runtime.value_to_string(&Value::Map(std::collections::HashMap::new()));
assert!(result.is_err(), "value_to_string(Map) should fail");
}
#[test]
fn test_value_to_int_all_types() {
let runtime = Runtime::new();
let result = runtime.value_to_int(&Value::Int(42));
assert!(result.is_ok(), "value_to_int(Int) should succeed");
assert_eq!(result.unwrap(), 42, "Int(42) should convert to 42");
let result = runtime.value_to_int(&Value::Float(3.15));
assert!(result.is_ok(), "value_to_int(Float) should succeed");
assert_eq!(result.unwrap(), 3, "Float(3.15) should convert to 3");
let result = runtime.value_to_int(&Value::String("123".to_string()));
assert!(
result.is_ok(),
"value_to_int(String(\"123\")) should succeed"
);
assert_eq!(
result.unwrap(),
123,
"String(\"123\") should convert to 123"
);
let result = runtime.value_to_int(&Value::Bool(true));
assert!(result.is_ok(), "value_to_int(Bool(true)) should succeed");
assert_eq!(result.unwrap(), 1, "Bool(true) should convert to 1");
let result = runtime.value_to_int(&Value::Bool(false));
assert!(result.is_ok(), "value_to_int(Bool(false)) should succeed");
assert_eq!(result.unwrap(), 0, "Bool(false) should convert to 0");
}
#[test]
fn test_value_to_int_invalid_string() {
let runtime = Runtime::new();
let result = runtime.value_to_int(&Value::String("not_a_number".to_string()));
assert!(
result.is_err(),
"value_to_int(String(\"not_a_number\")) should fail"
);
let result = runtime.value_to_int(&Value::String("".to_string()));
assert!(result.is_err(), "value_to_int(String(\"\")) should fail");
}
#[test]
fn test_value_to_int_invalid_type() {
let runtime = Runtime::new();
let result = runtime.value_to_int(&Value::Null);
assert!(result.is_err(), "value_to_int(Null) should fail");
let result = runtime.value_to_int(&Value::Array(vec![Value::Int(1)]));
assert!(result.is_err(), "value_to_int(Array) should fail");
let result = runtime.value_to_int(&Value::Map(std::collections::HashMap::new()));
assert!(result.is_err(), "value_to_int(Map) should fail");
}
#[test]
fn test_value_to_int_return_value_verification() {
let runtime = Runtime::new();
let result1 = runtime.value_to_int(&Value::Int(100));
let result2 = runtime.value_to_int(&Value::Int(200));
assert!(result1.is_ok() && result2.is_ok(), "Both should succeed");
assert_ne!(
result1.unwrap(),
result2.unwrap(),
"Different inputs should produce different outputs"
);
let result_pos = runtime.value_to_int(&Value::Int(42));
let result_neg = runtime.value_to_int(&Value::Int(-42));
assert!(
result_pos.is_ok() && result_neg.is_ok(),
"Both should succeed"
);
assert_ne!(
result_pos.unwrap(),
result_neg.unwrap(),
"Positive and negative should be different"
);
}