32 lines
880 B
Rust
32 lines
880 B
Rust
use rhttpd::js_engine::{JsEngineError, JsRuntime};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), JsEngineError> {
|
|
println!("Testing JavaScript runtime...");
|
|
|
|
// 创建运行时
|
|
let runtime = JsRuntime::new().await?;
|
|
println!("Runtime created successfully");
|
|
|
|
// 测试简单表达式
|
|
let result: i32 = runtime.evaluate("1 + 2").await?;
|
|
println!("1 + 2 = {}", result);
|
|
|
|
// 测试字符串
|
|
let message: String = runtime.evaluate("'Hello, World!'").await?;
|
|
println!("Message: {}", message);
|
|
|
|
// 测试布尔值
|
|
let is_true: bool = runtime.evaluate("5 > 3").await?;
|
|
println!("5 > 3 is {}", is_true);
|
|
|
|
// 测试函数调用
|
|
let func_result: i32 = runtime.call_function("return 42;").await?;
|
|
println!("Function returned: {}", func_result);
|
|
|
|
// 清理
|
|
println!("Runtime test completed successfully");
|
|
|
|
Ok(())
|
|
}
|