diff --git a/tests/runtime/common-types/compose.wac b/tests/runtime/common-types/compose.wac new file mode 100644 index 000000000..a54149470 --- /dev/null +++ b/tests/runtime/common-types/compose.wac @@ -0,0 +1,15 @@ +package example:composition; + +let leaf = new test:leaf { + ... +}; +let middle = new test:middle { + to-test: leaf.to-test, + ... +}; +let runner = new test:runner { + to-test: middle.to-test, + ... +}; + +export runner...; diff --git a/tests/runtime/common-types/leaf.cpp b/tests/runtime/common-types/leaf.cpp new file mode 100644 index 000000000..56acae02e --- /dev/null +++ b/tests/runtime/common-types/leaf.cpp @@ -0,0 +1,15 @@ +#include + +using namespace test::common::test_types; + +R1 exports::test::common::to_test::Wrap(F1 flag) { + if (flag == F1::kA) { + return R1{ 1, flag }; + } else { + return R1{ 2, flag }; + } +} + +V1 exports::test::common::to_test::VarF(void) { + return V1(V1::B(42)); +} diff --git a/tests/runtime/common-types/middle.cpp b/tests/runtime/common-types/middle.cpp new file mode 100644 index 000000000..1f0aec36a --- /dev/null +++ b/tests/runtime/common-types/middle.cpp @@ -0,0 +1,11 @@ +#include + +using namespace test::common::test_types; + +R1 exports::test::common::to_test::Wrap(F1 flag) { + return ::test::common::to_test::Wrap(flag); +} + +V1 exports::test::common::to_test::VarF(void) { + return ::test::common::to_test::VarF(); +} \ No newline at end of file diff --git a/tests/runtime/common-types/middle.rs b/tests/runtime/common-types/middle.rs new file mode 100644 index 000000000..0a3aa3aa9 --- /dev/null +++ b/tests/runtime/common-types/middle.rs @@ -0,0 +1,19 @@ +include!(env!("BINDINGS")); + +use crate::test::common::to_test::{F1, R1, V1}; + +use exports::test::common::to_test; + +pub struct Test {} + +export!(Test); + +impl to_test::Guest for Test { + fn wrap(flag: F1) -> R1 { + crate::test::common::to_test::wrap(flag) + } + + fn var_f() -> V1 { + crate::test::common::to_test::var_f() + } +} diff --git a/tests/runtime/common-types/runner.cpp b/tests/runtime/common-types/runner.cpp new file mode 100644 index 000000000..fe4dd89af --- /dev/null +++ b/tests/runtime/common-types/runner.cpp @@ -0,0 +1,20 @@ +#include +#include + +int main() { + using namespace ::test::common::test_types; + + R1 res = test::common::to_test::Wrap(F1::kA); + assert(res.b == F1::kA); + assert(res.a == 1); + + R1 res2 = test::common::to_test::Wrap(F1::kB); + assert(res2.b == F1::kB); + assert(res2.a == 2); + + V1 res3 = test::common::to_test::VarF(); + assert(res3.variants.index() == 1); + assert(std::get<1>(res3.variants).value == 42); + + return 0; +} diff --git a/tests/runtime/common-types/test.wit b/tests/runtime/common-types/test.wit new file mode 100644 index 000000000..aefb6bac2 --- /dev/null +++ b/tests/runtime/common-types/test.wit @@ -0,0 +1,30 @@ +//@ dependencies = ['middle', 'leaf'] +//@ wac = 'compose.wac' + +package test:common; + +interface test-types { + flags f1 { a, b } + record r1 { a: u8, b: f1 } + variant v1 { a, b(u8) } +} + +interface to-test { + use test-types.{f1, r1, v1}; + + wrap: func(flag: f1) -> r1; + var-f: func() -> v1; +} + +world leaf { + export to-test; +} + +world middle { + import to-test; + export to-test; +} + +world runner { + import to-test; +}