mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-06 18:56:19 +08:00
Use a proper stack trace inside the tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -17,7 +18,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_all_of" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto homer =
|
||||
Person{.first_name = "Homer", .last_name = "Simpson", .age = 45};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
@@ -10,7 +11,7 @@
|
||||
namespace test_alphanumeric_map {
|
||||
|
||||
void test() {
|
||||
std::cout << "test_alphanumeric_map" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
std::map<rfl::AlphaNumeric, std::unique_ptr<std::string>> homer;
|
||||
homer.insert(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <memory>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -9,7 +10,7 @@
|
||||
|
||||
namespace test_alphanumeric_unordered_map {
|
||||
void test() {
|
||||
std::cout << "test_alphanumeric_unordered_map" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
using Map =
|
||||
std::unordered_map<rfl::AlphaNumeric, std::unique_ptr<std::string>>;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -21,7 +22,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_anonymous_fields" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person{.first_name = "Bart",
|
||||
.last_name = "Simpson",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -20,7 +21,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_any_of" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto homer =
|
||||
Person{.first_name = "Homer", .last_name = "Simpson", .age = 45};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
@@ -16,7 +17,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_array" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto bart = Person{.first_name = "Bart"};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -26,7 +27,7 @@ struct C {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_as" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto a = A{.f1 = "Hello", .f2 = rfl::make_box<std::string>("World")};
|
||||
|
||||
|
||||
@@ -2,37 +2,41 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
void test_as_flatten() {
|
||||
std::cout << "test_as_flatten" << std::endl;
|
||||
namespace test_as_flatten {
|
||||
|
||||
struct A {
|
||||
rfl::Field<"f1", std::string> f1;
|
||||
rfl::Field<"f2", rfl::Box<std::string>> f2;
|
||||
};
|
||||
struct A {
|
||||
rfl::Field<"f1", std::string> f1;
|
||||
rfl::Field<"f2", rfl::Box<std::string>> f2;
|
||||
};
|
||||
|
||||
struct B {
|
||||
rfl::Field<"f3", std::string> f3;
|
||||
rfl::Field<"f4", rfl::Box<std::string>> f4;
|
||||
};
|
||||
struct B {
|
||||
rfl::Field<"f3", std::string> f3;
|
||||
rfl::Field<"f4", rfl::Box<std::string>> f4;
|
||||
};
|
||||
|
||||
struct C {
|
||||
rfl::Flatten<A> a;
|
||||
rfl::Flatten<B> b;
|
||||
rfl::Field<"f5", int> f5;
|
||||
};
|
||||
struct C {
|
||||
rfl::Flatten<A> a;
|
||||
rfl::Flatten<B> b;
|
||||
rfl::Field<"f5", int> f5;
|
||||
};
|
||||
|
||||
auto a = A{.f1 = "Hello", .f2 = rfl::make_box<std::string>("World")};
|
||||
void test() {
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto b = B{.f3 = "Hello", .f4 = rfl::make_box<std::string>("World")};
|
||||
auto a = A{.f1 = "Hello", .f2 = rfl::make_box<std::string>("World")};
|
||||
|
||||
const auto c =
|
||||
rfl::as<C>(std::move(a), std::move(b), rfl::make_field<"f5">(5));
|
||||
auto b = B{.f3 = "Hello", .f4 = rfl::make_box<std::string>("World")};
|
||||
|
||||
write_and_read(
|
||||
c, R"({"f1":"Hello","f2":"World","f3":"Hello","f4":"World","f5":5})");
|
||||
const auto c =
|
||||
rfl::as<C>(std::move(a), std::move(b), rfl::make_field<"f5">(5));
|
||||
|
||||
write_and_read(
|
||||
c, R"({"f1":"Hello","f2":"World","f3":"Hello","f4":"World","f5":5})");
|
||||
}
|
||||
} // namespace test_as_flatten
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -28,7 +29,7 @@ struct DecisionTree {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_box" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto leaf1 = DecisionTree::Leaf{.value = 3.0};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -30,7 +31,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_custom_class1" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person("Bart");
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -29,7 +30,7 @@ struct FiveDigitCode {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_custom_class2" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto result = rfl::json::read<FiveDigitCode>("123");
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -55,7 +56,7 @@ struct Parser<ReaderType, WriterType, test_custom_class3::Person>
|
||||
namespace test_custom_class3 {
|
||||
|
||||
void test() {
|
||||
std::cout << "test_custom_class3" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person("Bart", "Simpson", 10);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -56,7 +57,7 @@ struct Parser<ReaderType, WriterType, test_custom_class4::Person>
|
||||
namespace test_custom_class4 {
|
||||
|
||||
void test() {
|
||||
std::cout << "test_custom_class4" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = test_custom_class4::Person(
|
||||
"Bart", rfl::make_box<std::string>("Simpson"), 10);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -30,7 +31,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_custom_constructor" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto res = rfl::json::read<Person>(
|
||||
R"({"firstName":"Homer","lastName":"Simpson","birthday":"1987-04-19"})");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -16,7 +17,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_default_values" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person{.first_name = "Bart"};
|
||||
const auto lisa = Person{.first_name = "Lisa"};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_deque" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::deque<Person>>();
|
||||
children->emplace_back(Person{.first_name = "Bart"});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_email" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto homer = Person{.first_name = "Homer",
|
||||
.last_name = "Simpson",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -16,7 +17,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_error_messages" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const std::string faulty_string =
|
||||
R"({"firstName":"Homer","lastName":12345,"birthday":"04/19/1987"})";
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -27,7 +28,7 @@ using Shapes = rfl::Variant<rfl::Field<"circle", Circle>,
|
||||
rfl::Field<"square", rfl::Box<Square>>>;
|
||||
|
||||
void test() {
|
||||
std::cout << "test_field_variant" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const Shapes r =
|
||||
rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -22,7 +23,7 @@ struct Employee {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_flatten" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto employee = Employee{
|
||||
.person = Person{.first_name = "Homer",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -22,7 +23,7 @@ struct Employee {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_flatten_anonymous" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto employee = Employee{
|
||||
.person = Person{.first_name = "Homer",
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
void test_flatten_tuple() {
|
||||
std::cout << "test_flatten_tuple" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
using Person = std::tuple<std::string, rfl::Box<std::string>, int>;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_forward_list" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::forward_list<Person>>();
|
||||
children->emplace_front(Person{.first_name = "Maggie"});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_list" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::list<Person>>();
|
||||
children->emplace_back(Person{.first_name = "Bart"});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -19,7 +20,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_literal" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person{.first_name = FirstName::make<"Bart">()};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace test_literal_map {
|
||||
using FieldName = rfl::Literal<"firstName", "lastName">;
|
||||
|
||||
void test() {
|
||||
std::cout << "test_literal_map" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
std::map<FieldName, std::unique_ptr<std::string>> homer;
|
||||
homer.insert(std::make_pair(FieldName::make<"firstName">(),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <memory>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -16,7 +17,7 @@ using FieldName = rfl::Literal<"firstName", "lastName">;
|
||||
using Map = std::unordered_map<FieldName, std::unique_ptr<std::string>>;
|
||||
|
||||
void test() {
|
||||
std::cout << "test_literal_unordered_map" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
Map homer;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <map>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_map" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::map<int, Person>>();
|
||||
children->insert(std::make_pair(1, Person{.first_name = "Bart"}));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <map>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
@@ -17,7 +18,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_map_with_key_validation" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::map<Between1and3, Person>>();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -37,7 +38,7 @@ struct Monster {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_monster_example" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto sword = Weapon{.name = "Sword", .damage = 3};
|
||||
const auto axe = Weapon{.name = "Axe", .damage = 5};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -16,7 +17,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_move_replace" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto lisa = Person{.first_name = "Lisa",
|
||||
.last_name = "Simpson",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <map>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_multimap" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::multimap<int, Person>>();
|
||||
children->insert(std::make_pair(1, Person{.first_name = "Bart"}));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_multiset" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::multiset<std::string>>(
|
||||
std::multiset<std::string>({"Bart", "Lisa", "Maggie"}));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -20,7 +21,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_one_of" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto homer =
|
||||
Person{.first_name = "Homer", .last_name = "Simpson", .age = 45};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_optional_fields" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person{.first_name = "Bart"};
|
||||
|
||||
|
||||
@@ -1,27 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
// Makes sure that the example in the README works as expected.
|
||||
// It would be embarrassing if it didn't...
|
||||
|
||||
namespace test_readme_example {
|
||||
|
||||
// Age must be a plausible number, between 0 and 130. This will
|
||||
// be validated automatically.
|
||||
using Age = rfl::Validator<unsigned int, rfl::Minimum<0>, rfl::Maximum<130>>;
|
||||
|
||||
// "firstName", "lastName" and "children" are the field names
|
||||
// as they will appear in the JSON. The C++ standard is
|
||||
// snake case, the JSON standard is camel case, so the names
|
||||
// will not always be identical.
|
||||
struct Person {
|
||||
rfl::Rename<"firstName", std::string> first_name;
|
||||
rfl::Rename<"lastName", std::string> last_name;
|
||||
rfl::Rename<"lastName", std::string> last_name = "Simpson";
|
||||
std::string town = "Springfield";
|
||||
rfl::Timestamp<"%Y-%m-%d"> birthday;
|
||||
Age age;
|
||||
rfl::Email email;
|
||||
@@ -29,30 +22,25 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_readme_example" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person{.first_name = "Bart",
|
||||
.last_name = "Simpson",
|
||||
.birthday = "1987-04-19",
|
||||
.age = 10,
|
||||
.email = "bart@simpson.com",
|
||||
.children = std::vector<Person>()};
|
||||
.email = "bart@simpson.com"};
|
||||
|
||||
const auto lisa = Person{.first_name = "Lisa",
|
||||
.last_name = "Simpson",
|
||||
.birthday = "1987-04-19",
|
||||
.age = 8,
|
||||
.email = "lisa@simpson.com"};
|
||||
|
||||
const auto maggie = Person{.first_name = "Maggie",
|
||||
.last_name = "Simpson",
|
||||
.birthday = "1987-04-19",
|
||||
.age = 0,
|
||||
.email = "maggie@simpson.com"};
|
||||
|
||||
const auto homer =
|
||||
Person{.first_name = "Homer",
|
||||
.last_name = "Simpson",
|
||||
.birthday = "1987-04-19",
|
||||
.age = 45,
|
||||
.email = "homer@simpson.com",
|
||||
@@ -60,6 +48,6 @@ void test() {
|
||||
|
||||
write_and_read(
|
||||
homer,
|
||||
R"({"firstName":"Homer","lastName":"Simpson","birthday":"1987-04-19","age":45,"email":"homer@simpson.com","children":[{"firstName":"Bart","lastName":"Simpson","birthday":"1987-04-19","age":10,"email":"bart@simpson.com","children":[]},{"firstName":"Lisa","lastName":"Simpson","birthday":"1987-04-19","age":8,"email":"lisa@simpson.com","children":[]},{"firstName":"Maggie","lastName":"Simpson","birthday":"1987-04-19","age":0,"email":"maggie@simpson.com","children":[]}]})");
|
||||
R"({"firstName":"Homer","lastName":"Simpson","town":"Springfield","birthday":"1987-04-19","age":45,"email":"homer@simpson.com","children":[{"firstName":"Bart","lastName":"Simpson","town":"Springfield","birthday":"1987-04-19","age":10,"email":"bart@simpson.com","children":[]},{"firstName":"Lisa","lastName":"Simpson","town":"Springfield","birthday":"1987-04-19","age":8,"email":"lisa@simpson.com","children":[]},{"firstName":"Maggie","lastName":"Simpson","town":"Springfield","birthday":"1987-04-19","age":0,"email":"maggie@simpson.com","children":[]}]})");
|
||||
}
|
||||
} // namespace test_readme_example
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -28,7 +29,7 @@ struct DecisionTree {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_ref" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto leaf1 = DecisionTree::Leaf{.value = 3.0};
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_rename {
|
||||
|
||||
using Age = rfl::Validator<unsigned int,
|
||||
rfl::AllOf<rfl::Minimum<0>, rfl::Maximum<130>>>;
|
||||
|
||||
struct Person {
|
||||
rfl::Rename<"firstName", std::string> first_name;
|
||||
rfl::Rename<"lastName", std::string> last_name;
|
||||
rfl::Timestamp<"%Y-%m-%d"> birthday;
|
||||
Age age;
|
||||
rfl::Email email;
|
||||
std::vector<Person> children;
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_anonymous_fields" << std::endl;
|
||||
|
||||
const auto bart = Person{.first_name = "Bart",
|
||||
.last_name = "Simpson",
|
||||
.birthday = "1987-04-19",
|
||||
.age = 10,
|
||||
.email = "bart@simpson.com"};
|
||||
|
||||
const auto lisa = Person{.first_name = "Lisa",
|
||||
.last_name = "Simpson",
|
||||
.birthday = "1987-04-19",
|
||||
.age = 8,
|
||||
.email = "lisa@simpson.com"};
|
||||
|
||||
const auto maggie = Person{.first_name = "Maggie",
|
||||
.last_name = "Simpson",
|
||||
.birthday = "1987-04-19",
|
||||
.age = 0,
|
||||
.email = "maggie@simpson.com"};
|
||||
|
||||
const auto homer =
|
||||
Person{.first_name = "Homer",
|
||||
.last_name = "Simpson",
|
||||
.birthday = "1987-04-19",
|
||||
.age = 45,
|
||||
.email = "homer@simpson.com",
|
||||
.children = std::vector<Person>({bart, lisa, maggie})};
|
||||
|
||||
write_and_read(
|
||||
homer,
|
||||
R"({"firstName":"Homer","lastName":"Simpson","birthday":"1987-04-19","age":45,"email":"homer@simpson.com","children":[{"firstName":"Bart","lastName":"Simpson","birthday":"1987-04-19","age":10,"email":"bart@simpson.com","children":[]},{"firstName":"Lisa","lastName":"Simpson","birthday":"1987-04-19","age":8,"email":"lisa@simpson.com","children":[]},{"firstName":"Maggie","lastName":"Simpson","birthday":"1987-04-19","age":0,"email":"maggie@simpson.com","children":[]}]})");
|
||||
}
|
||||
} // namespace test_rename
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -16,7 +17,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_replace" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto lisa = Person{.first_name = "Lisa",
|
||||
.last_name = "Simpson",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -22,7 +23,7 @@ struct Employee {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_replace_flatten" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto employee = Employee{
|
||||
.person = Person{.first_name = "Homer",
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -22,7 +23,7 @@ struct Employee {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_replace_with_other_struct" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto employee = Employee{
|
||||
.person =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_result" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const rfl::Result<Person> bart = Person{.first_name = "Bart"};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -20,7 +21,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_save_load" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person{.first_name = "Bart",
|
||||
.last_name = "Simpson",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_set" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::set<std::string>>(
|
||||
std::set<std::string>({"Bart", "Lisa", "Maggie"}));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -18,7 +19,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_size" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto bart = Person{
|
||||
.first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"};
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
#include <memory>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_string_map {
|
||||
void test() {
|
||||
std::cout << "test_string_map" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
std::map<std::string, std::unique_ptr<std::string>> homer;
|
||||
homer.insert(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <memory>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -9,7 +10,7 @@
|
||||
|
||||
namespace test_string_unordered_map {
|
||||
void test() {
|
||||
std::cout << "test_string_unordered_map" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
using Map = std::unordered_map<std::string, std::unique_ptr<std::string>>;
|
||||
Map homer;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -25,7 +26,7 @@ struct Square {
|
||||
using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>;
|
||||
|
||||
void test() {
|
||||
std::cout << "test_tagged_union" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const Shapes r = Rectangle{.height = 10, .width = 5};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -28,7 +29,7 @@ struct Square {
|
||||
using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>;
|
||||
|
||||
void test() {
|
||||
std::cout << "test_tagged_union2" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const Shapes r = Rectangle{.height = 10, .width = 5};
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -18,7 +19,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_timestamp" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const auto result = TS::from_string("nonsense");
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <memory>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -16,7 +17,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_unique_ptr" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::vector<Person>>();
|
||||
children->emplace_back(Person{.first_name = "Bart"});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -28,7 +29,7 @@ struct DecisionTree {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_unique_ptr2" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto leaf1 = DecisionTree::Leaf{.value = 3.0};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_unordered_map" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::unordered_map<int, Person>>();
|
||||
children->insert(std::make_pair(1, Person{.first_name = "Bart"}));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <map>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_unordered_multimap" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::unordered_multimap<int, Person>>();
|
||||
children->insert(std::make_pair(1, Person{.first_name = "Bart"}));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_unordered_multiset" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::unordered_multiset<std::string>>(
|
||||
std::unordered_multiset<std::string>({"Bart", "Lisa", "Maggie"}));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,7 +16,7 @@ struct Person {
|
||||
};
|
||||
|
||||
void test() {
|
||||
std::cout << "test_unordered_set" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
auto children = std::make_unique<std::unordered_set<std::string>>(
|
||||
std::unordered_set<std::string>({"Bart", "Lisa", "Maggie"}));
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -25,7 +26,7 @@ struct Square {
|
||||
using Shapes = std::variant<Circle, Rectangle, std::unique_ptr<Square>>;
|
||||
|
||||
void test() {
|
||||
std::cout << "test_variant" << std::endl;
|
||||
std::cout << std::source_location::current().function_name() << std::endl;
|
||||
|
||||
const Shapes r = Rectangle{.height = 10, .width = 5};
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#include "test_optional_fields.hpp"
|
||||
#include "test_readme_example.hpp"
|
||||
#include "test_ref.hpp"
|
||||
#include "test_rename.hpp"
|
||||
#include "test_replace.hpp"
|
||||
#include "test_replace_flatten.hpp"
|
||||
#include "test_replace_with_other_struct.hpp"
|
||||
@@ -71,7 +70,6 @@ int main() {
|
||||
test_timestamp::test();
|
||||
test_flatten::test();
|
||||
test_flatten_anonymous::test();
|
||||
test_rename::test();
|
||||
test_deque::test();
|
||||
test_forward_list::test();
|
||||
test_list::test();
|
||||
@@ -104,7 +102,7 @@ int main() {
|
||||
test_replace_flatten::test();
|
||||
test_replace_with_other_struct::test();
|
||||
test_as::test();
|
||||
test_as_flatten();
|
||||
test_as_flatten::test();
|
||||
|
||||
test_custom_constructor::test();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user