mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Result: Add default template for Result<T, E>
It currently is a tagged pair instead of a tagged union because it was much easier to write and the optimization can come later. BUG=dawn:19 Change-Id: Idbfd86d559655b38871c2d1768bdd758e797dfbd Reviewed-on: https://dawn-review.googlesource.com/c/2701 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
813bfbd061
commit
df72914a60
@@ -39,6 +39,8 @@ void TestSuccess(Result<T, E>* result, T expectedSuccess) {
|
||||
static int dummyError = 0xbeef;
|
||||
static float dummySuccess = 42.0f;
|
||||
|
||||
// Result<void, E*>
|
||||
|
||||
// Test constructing an error Result<void, E*>
|
||||
TEST(ResultOnlyPointerError, ConstructingError) {
|
||||
Result<void, int*> result(&dummyError);
|
||||
@@ -88,6 +90,8 @@ TEST(ResultOnlyPointerError, ReturningSuccess) {
|
||||
ASSERT_FALSE(result.IsError());
|
||||
}
|
||||
|
||||
// Result<T*, E*>
|
||||
|
||||
// Test constructing an error Result<T*, E*>
|
||||
TEST(ResultBothPointer, ConstructingError) {
|
||||
Result<float*, int*> result(&dummyError);
|
||||
@@ -134,4 +138,52 @@ TEST(ResultBothPointer, ReturningSuccess) {
|
||||
TestSuccess(&result, &dummySuccess);
|
||||
}
|
||||
|
||||
// Result<T, E>
|
||||
|
||||
// Test constructing an error Result<T, E>
|
||||
TEST(ResultGeneric, ConstructingError) {
|
||||
Result<std::vector<float>, int*> result(&dummyError);
|
||||
TestError(&result, &dummyError);
|
||||
}
|
||||
|
||||
// Test moving an error Result<T, E>
|
||||
TEST(ResultGeneric, MovingError) {
|
||||
Result<std::vector<float>, int*> result(&dummyError);
|
||||
Result<std::vector<float>, int*> movedResult(std::move(result));
|
||||
TestError(&movedResult, &dummyError);
|
||||
}
|
||||
|
||||
// Test returning an error Result<T, E>
|
||||
TEST(ResultGeneric, ReturningError) {
|
||||
auto CreateError = []() -> Result<std::vector<float>, int*> {
|
||||
return {&dummyError};
|
||||
};
|
||||
|
||||
Result<std::vector<float>, int*> result = CreateError();
|
||||
TestError(&result, &dummyError);
|
||||
}
|
||||
|
||||
// Test constructing a success Result<T, E>
|
||||
TEST(ResultGeneric, ConstructingSuccess) {
|
||||
Result<std::vector<float>, int*> result({1.0f});
|
||||
TestSuccess(&result, {1.0f});
|
||||
}
|
||||
|
||||
// Test moving a success Result<T, E>
|
||||
TEST(ResultGeneric, MovingSuccess) {
|
||||
Result<std::vector<float>, int*> result({1.0f});
|
||||
Result<std::vector<float>, int*> movedResult(std::move(result));
|
||||
TestSuccess(&movedResult, {1.0f});
|
||||
}
|
||||
|
||||
// Test returning a success Result<T, E>
|
||||
TEST(ResultGeneric, ReturningSuccess) {
|
||||
auto CreateSuccess = []() -> Result<std::vector<float>, int*> {
|
||||
return {{1.0f}};
|
||||
};
|
||||
|
||||
Result<std::vector<float>, int*> result = CreateSuccess();
|
||||
TestSuccess(&result, {1.0f});
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
Reference in New Issue
Block a user