refactor: comnbine all in to one single header
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
#include <string>
|
||||
#include "../src/nerr.h"
|
||||
#include "../src/ro.h"
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace nerr;
|
||||
using namespace ro;
|
||||
|
||||
#define assert(v,fmt,...) if(!(v)) { \
|
||||
throw Error(nerr::sfmt("ASSERT ERROR %s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)); \
|
||||
throw Error(ro::sfmt("ASSERT ERROR %s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)); \
|
||||
}
|
||||
|
||||
|
||||
@ -20,18 +20,13 @@ void test(const char* desc, const std::function<void()>& lambda)
|
||||
lambda();
|
||||
std::cout << "OK" << std::endl;
|
||||
}
|
||||
catch(nerr::Error e)
|
||||
catch(ro::Error e)
|
||||
{
|
||||
std::cout << "FAILED" << std::endl;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Result<string, Error> test_return()
|
||||
{
|
||||
return string("Error");
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
test("Test Option", [](){
|
||||
@ -123,7 +118,6 @@ int main(int argc, char const *argv[])
|
||||
test("Result map", [](){
|
||||
auto err = ERR("Error");
|
||||
auto fn = [](string data){
|
||||
cout << data << endl;
|
||||
return 1;
|
||||
};
|
||||
Result<string, Error> ret = err;
|
||||
@ -140,7 +134,6 @@ int main(int argc, char const *argv[])
|
||||
|
||||
test("Result map err", [](){
|
||||
auto fn = [](int x){
|
||||
cout << "Error code is " << x << endl;
|
||||
return "Hello";
|
||||
};
|
||||
Result<bool, int> ret = true;
|
||||
@ -165,4 +158,5 @@ int main(int argc, char const *argv[])
|
||||
v = ret.map_or<int>(0, fn);
|
||||
assert(v == 3, "Value mismatch %d",v);
|
||||
});
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user