Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Sep 17, 2024
1 parent add926f commit 91b69ab
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/cpp/test_headers/expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// work around g++ system header limitation
#define unexpected unexpected_old
#include <exception>
#undef unexpected
#include <expected.hpp>

namespace std {
Expand Down
56 changes: 56 additions & 0 deletions tests/runtime/results/wasm.new.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <assert.h>
#include <results_cpp.h>

template <class T>
bool equal(T const&a, T const&b) {
return a==b;
}

std::expected<float, wit::string> exports::test::results::test::StringError(float a) {
return ::test::results::test::StringError(a);
}

std::expected<float, ::test::results::test::E> exports::test::results::test::EnumError(float a) {
auto result = ::test::results::test::EnumError(a);
if (result.has_value()) { return result.value(); }
return std::unexpected(result.error());
// if (result.error()==::test::results::test::E::kA) { return std::unexpected(::test::results::test::E::kA); }
// if (result.error()==::test::results::test::E::kB) { return std::unexpected(::test::results::test::E::kB); }
// if (result.error()==::test::results::test::E::kC) { return std::unexpected(::test::results::test::E::kC); }
}

std::expected<float, ::test::results::test::E2> exports::test::results::test::RecordError(float a) {
auto result = ::test::results::test::RecordError(a);
if (result.has_value()) { return result.value(); }
return std::unexpected(::test::results::test::E2{ result.error().line, result.error().column });
}

std::expected<float, ::test::results::test::E3> exports::test::results::test::VariantError(float a) {
auto result = ::test::results::test::VariantError(a);
if (result.has_value()) { return result.value(); }
return std::unexpected(result.error());

// match test_imports::variant_error(a) {
// Ok(b) => Ok(b),
// Err(test_imports::E3::E1(test_imports::E::A)) => {
// Err(test_exports::E3::E1(test_exports::E::A))
// }
// Err(test_imports::E3::E1(test_imports::E::B)) => {
// Err(test_exports::E3::E1(test_exports::E::B))
// }
// Err(test_imports::E3::E1(test_imports::E::C)) => {
// Err(test_exports::E3::E1(test_exports::E::C))
// }
// Err(test_imports::E3::E2(test_imports::E2 { line, column })) => {
// Err(test_exports::E3::E2(test_exports::E2 { line, column }))
// }
// }
}

std::expected<uint32_t, void> exports::test::results::test::EmptyError(uint32_t a) {
return ::test::results::test::EmptyError(a);
}

std::expected<std::expected<void, wit::string>, wit::string> exports::test::results::test::DoubleError(uint32_t a) {
return ::test::results::test::DoubleError(a)
}

0 comments on commit 91b69ab

Please sign in to comment.