Files
wit-bindgen/tests/runtime/strings.rs
Alex Crichton a2935a4fa4 Update wit-bindgen for upcoming WIT changes (#580)
* Update Rust codegen for new WIT changes

* Update the markdown generation for new WIT

* more-rust

* Update the C generator for new WIT

* Get Rust guest tests compiling

* Get rust host tests working

* Get all C tests passing

* Turn off teavm-java and Go tests for now

* Fixup lockfile after rebase

* Bump crate versions

* Update dependency sources

* Update to wasmtime dep
2023-05-26 12:30:24 -05:00

40 lines
1.0 KiB
Rust

use anyhow::Result;
use wasmtime::Store;
wasmtime::component::bindgen!(in "tests/runtime/strings");
#[derive(Default)]
pub struct MyImports;
impl test::strings::imports::Host for MyImports {
fn take_basic(&mut self, s: String) -> Result<()> {
assert_eq!(s, "latin utf16");
Ok(())
}
fn return_unicode(&mut self) -> Result<String> {
Ok("🚀🚀🚀 𠈄𓀀".to_string())
}
}
#[test]
fn run() -> Result<()> {
crate::run_test(
"strings",
|linker| Strings::add_to_linker(linker, |x| &mut x.0),
|store, component, linker| Strings::instantiate(store, component, linker),
run_test,
)
}
fn run_test(exports: Strings, store: &mut Store<crate::Wasi<MyImports>>) -> Result<()> {
exports.call_test_imports(&mut *store)?;
assert_eq!(exports.call_return_empty(&mut *store)?, "");
assert_eq!(exports.call_roundtrip(&mut *store, "str")?, "str");
assert_eq!(
exports.call_roundtrip(&mut *store, "🚀🚀🚀 𠈄𓀀")?,
"🚀🚀🚀 𠈄𓀀"
);
Ok(())
}