Add functions with multiple arguments to import macro, add test cases
This commit is contained in:
parent
28f071e50d
commit
f110945fd6
3 changed files with 100 additions and 69 deletions
|
@ -16,7 +16,8 @@ mod tests {
|
|||
swap: WasiFn<(u32, u32), (u32, u32)>,
|
||||
sort: WasiFn<Vec<u32>, Vec<u32>>,
|
||||
print: WasiFn<String, ()>,
|
||||
// and_back: WasiFn<u32, u32>,
|
||||
and_back: WasiFn<u32, u32>,
|
||||
imports: WasiFn<u32, u32>,
|
||||
}
|
||||
|
||||
async {
|
||||
|
@ -24,6 +25,12 @@ mod tests {
|
|||
.unwrap()
|
||||
.host_function("mystery_number", |input: u32| input + 7)
|
||||
.unwrap()
|
||||
.host_function("import_noop", |_: ()| ())
|
||||
.unwrap()
|
||||
.host_function("import_identity", |input: u32| input)
|
||||
.unwrap()
|
||||
.host_function("import_swap", |(a, b): (u32, u32)| (b, a))
|
||||
.unwrap()
|
||||
.init(include_bytes!("../../../plugins/bin/test_plugin.wasm"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -36,7 +43,8 @@ mod tests {
|
|||
swap: runtime.function("swap").unwrap(),
|
||||
sort: runtime.function("sort").unwrap(),
|
||||
print: runtime.function("print").unwrap(),
|
||||
// and_back: runtime.function("and_back").unwrap(),
|
||||
and_back: runtime.function("and_back").unwrap(),
|
||||
imports: runtime.function("imports").unwrap(),
|
||||
};
|
||||
|
||||
let unsorted = vec![1, 3, 4, 2, 5];
|
||||
|
@ -49,7 +57,10 @@ mod tests {
|
|||
assert_eq!(runtime.call(&plugin.swap, (1, 2)).await.unwrap(), (2, 1));
|
||||
assert_eq!(runtime.call(&plugin.sort, unsorted).await.unwrap(), sorted);
|
||||
assert_eq!(runtime.call(&plugin.print, "Hi!".into()).await.unwrap(), ());
|
||||
// assert_eq!(runtime.call(&plugin.and_back, 1).await.unwrap(), 8);
|
||||
assert_eq!(runtime.call(&plugin.and_back, 1).await.unwrap(), 8);
|
||||
assert_eq!(runtime.call(&plugin.imports, 1).await.unwrap(), 8);
|
||||
|
||||
// dbg!("{}", runtime.call(&plugin.and_back, 1).await.unwrap());
|
||||
}
|
||||
.block_on()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue