feat: add __network/html-crawl-parse, __wasm/wasmtime-serde-demo

This commit is contained in:
2024-03-24 13:15:59 +08:00
parent 8adc5a58bc
commit f5a41fdb02
30 changed files with 3574 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
#[cfg(test)]
mod test {
use wasmtime_serde_host::*;
const GUEST_DATA: &[u8] = include_bytes!("guest.wasm");
#[test]
fn load_runtime() {
assert!(Runtime::new(GUEST_DATA, &[]).is_ok())
}
#[test]
fn get_func() {
let runtime = Runtime::new(GUEST_DATA, &[]).unwrap();
assert!(runtime.get_func::<(i32, i32), i32>("add").is_ok())
}
#[test]
fn call() {
let runtime = Runtime::new(GUEST_DATA, &[]).unwrap();
let add_fn = runtime.get_func::<(i32, i32), i32>("add").unwrap();
let result = add_fn.call(&(10, 10));
assert_eq!(result, 20)
}
#[test]
fn checked_call() {
let runtime = Runtime::new(GUEST_DATA, &[]).unwrap();
let panic_fn = runtime.get_func::<(), ()>("panic").unwrap();
let result = panic_fn.checked_call(&());
assert!(result.is_err())
}
}