mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-02 16:16:19 +08:00
@@ -45,10 +45,6 @@ class Literal {
|
|||||||
|
|
||||||
Literal(const std::string& _str) : value_(find_value(_str).value()) {}
|
Literal(const std::string& _str) : value_(find_value(_str).value()) {}
|
||||||
|
|
||||||
/// A single-field literal is special because it
|
|
||||||
/// can also have a default constructor.
|
|
||||||
template <ValueType num_fields = num_fields_,
|
|
||||||
typename = std::enable_if_t<num_fields <= 1>>
|
|
||||||
Literal() : value_(0) {}
|
Literal() : value_(0) {}
|
||||||
|
|
||||||
~Literal() = default;
|
~Literal() = default;
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include <chrono>
|
||||||
|
#include <rfl.hpp>
|
||||||
|
#include <rfl/json.hpp>
|
||||||
|
|
||||||
|
#include "rfl/DefaultIfMissing.hpp"
|
||||||
|
#include "write_and_read.hpp"
|
||||||
|
|
||||||
|
namespace test_duration_default {
|
||||||
|
|
||||||
|
struct TestStruct {
|
||||||
|
std::chrono::seconds duration;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(json, test_duration_default) {
|
||||||
|
const auto test = TestStruct{.duration = std::chrono::seconds(10)};
|
||||||
|
write_and_read<rfl::DefaultIfMissing>(
|
||||||
|
test, R"({"duration":{"count":10,"unit":"seconds"}})");
|
||||||
|
}
|
||||||
|
} // namespace test_duration_default
|
||||||
Reference in New Issue
Block a user