mirror of
https://github.com/boostorg/leaf.git
synced 2026-01-19 04:22:08 +00:00
BOOST_LEAF_VAR_test and BOOST_LEAF_AUTO_test
This commit is contained in:
18
.vscode/tasks.json
vendored
18
.vscode/tasks.json
vendored
@@ -86,6 +86,24 @@
|
||||
"command": "${workspaceRoot}/.vscode/msvc.bat && cd ${workspaceRoot}/bld/debug && meson test accumulate_nested_success_result_test"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "BOOST_LEAF_AUTO_test",
|
||||
"type": "shell",
|
||||
"command": "cd ${workspaceRoot}/bld/debug && meson test BOOST_LEAF_AUTO_test",
|
||||
"problemMatcher": { "base": "$gcc", "fileLocation": ["relative","${workspaceRoot}/bld/debug"] },
|
||||
"windows": {
|
||||
"command": "${workspaceRoot}/.vscode/msvc.bat && cd ${workspaceRoot}/bld/debug && meson test BOOST_LEAF_AUTO_test"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "BOOST_LEAF_VAR_test",
|
||||
"type": "shell",
|
||||
"command": "cd ${workspaceRoot}/bld/debug && meson test BOOST_LEAF_VAR_test",
|
||||
"problemMatcher": { "base": "$gcc", "fileLocation": ["relative","${workspaceRoot}/bld/debug"] },
|
||||
"windows": {
|
||||
"command": "${workspaceRoot}/.vscode/msvc.bat && cd ${workspaceRoot}/bld/debug && meson test BOOST_LEAF_VAR_test"
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "boost_exception_test",
|
||||
"type": "shell",
|
||||
|
||||
@@ -81,6 +81,8 @@ tests = [
|
||||
'accumulate_nested_new_error_result_test',
|
||||
'accumulate_nested_success_exception_test',
|
||||
'accumulate_nested_success_result_test',
|
||||
'BOOST_LEAF_AUTO_test',
|
||||
'BOOST_LEAF_VAR_test',
|
||||
'capture_exception_async_test',
|
||||
'capture_exception_result_async_test',
|
||||
'capture_exception_state_test',
|
||||
|
||||
48
test/BOOST_LEAF_AUTO_test.cpp
Normal file
48
test/BOOST_LEAF_AUTO_test.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/leaf/result.hpp>
|
||||
#include <boost/leaf/handle_error.hpp>
|
||||
#include "lightweight_test.hpp"
|
||||
|
||||
namespace leaf = boost::leaf;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
int r = leaf::try_handle_all(
|
||||
[]() -> leaf::result<int>
|
||||
{
|
||||
leaf::result<int> r(42);
|
||||
BOOST_LEAF_AUTO(rx, r);
|
||||
BOOST_TEST_EQ(r.value(), rx);
|
||||
return 0;
|
||||
},
|
||||
[]
|
||||
{
|
||||
return 1;
|
||||
} );
|
||||
BOOST_TEST_EQ(r, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int r = leaf::try_handle_all(
|
||||
[]() -> leaf::result<int>
|
||||
{
|
||||
int x = 42;
|
||||
leaf::result<int &> r(x);
|
||||
BOOST_LEAF_AUTO(rx, r);
|
||||
BOOST_TEST_EQ(x, rx);
|
||||
return 0;
|
||||
},
|
||||
[]
|
||||
{
|
||||
return 1;
|
||||
} );
|
||||
BOOST_TEST_EQ(r, 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
65
test/BOOST_LEAF_VAR_test.cpp
Normal file
65
test/BOOST_LEAF_VAR_test.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2018-2020 Emil Dotchevski and Reverge Studios, Inc.
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/leaf/result.hpp>
|
||||
#include <boost/leaf/handle_error.hpp>
|
||||
#include "lightweight_test.hpp"
|
||||
|
||||
namespace leaf = boost::leaf;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
int r = leaf::try_handle_all(
|
||||
[]() -> leaf::result<int>
|
||||
{
|
||||
leaf::result<int> r(42);
|
||||
BOOST_LEAF_VAR(auto && rx, r);
|
||||
BOOST_TEST_EQ(r.value(), rx);
|
||||
return 0;
|
||||
},
|
||||
[]
|
||||
{
|
||||
return 1;
|
||||
} );
|
||||
BOOST_TEST_EQ(r, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int r = leaf::try_handle_all(
|
||||
[]() -> leaf::result<int>
|
||||
{
|
||||
int x = 42;
|
||||
leaf::result<int &> r(x);
|
||||
BOOST_LEAF_VAR(auto && rx, r);
|
||||
BOOST_TEST_EQ(x, rx);
|
||||
return 0;
|
||||
},
|
||||
[]
|
||||
{
|
||||
return 1;
|
||||
} );
|
||||
BOOST_TEST_EQ(r, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int r = leaf::try_handle_all(
|
||||
[]() -> leaf::result<int>
|
||||
{
|
||||
int x = 42;
|
||||
leaf::result<int &> r(x);
|
||||
BOOST_LEAF_VAR(auto & rx, r);
|
||||
BOOST_TEST_EQ(&x, &rx);
|
||||
return 0;
|
||||
},
|
||||
[]
|
||||
{
|
||||
return 1;
|
||||
} );
|
||||
BOOST_TEST_EQ(r, 0);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -38,6 +38,8 @@ run accumulate_nested_new_error_exception_test.cpp ;
|
||||
run accumulate_nested_new_error_result_test.cpp ;
|
||||
run accumulate_nested_success_exception_test.cpp ;
|
||||
run accumulate_nested_success_result_test.cpp ;
|
||||
run BOOST_LEAF_AUTO_test.cpp ;
|
||||
run BOOST_LEAF_VAR_test.cpp ;
|
||||
run boost_exception_test.cpp ;
|
||||
run capture_exception_async_test.cpp ;
|
||||
run capture_exception_result_async_test.cpp ;
|
||||
|
||||
Reference in New Issue
Block a user