Files
reflect-cpp/tests/test_one_of.hpp
T
2023-11-02 20:02:34 +01:00

29 lines
739 B
C++

#include <iostream>
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <string>
#include <vector>
#include "write_and_read.hpp"
void test_one_of() {
std::cout << "test_one_of" << std::endl;
using Age = rfl::Validator<
unsigned int,
rfl::OneOf<rfl::AllOf<rfl::Minimum<0.>, rfl::Maximum<10.>>,
rfl::AllOf<rfl::Minimum<40.>, rfl::Maximum<130.>>>>;
struct Person {
rfl::Field<"firstName", std::string> first_name;
rfl::Field<"lastName", std::string> last_name;
rfl::Field<"age", Age> age;
};
const auto homer =
Person{.first_name = "Homer", .last_name = "Simpson", .age = 45};
write_and_read(homer,
R"({"firstName":"Homer","lastName":"Simpson","age":45})");
}