Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/rfl/enums.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#ifndef RFL_ENUMS_HPP_
#define RFL_ENUMS_HPP_

#include <string>
#include <sstream>
#include <string>

#include "Result.hpp"
#include "internal/enums/get_enum_names.hpp"
#include "internal/strings/strings.hpp"
#include "thirdparty/enchantum/enchantum.hpp"
#include "thirdparty/enchantum/bitflags.hpp"
#include "thirdparty/enchantum/enchantum.hpp"

namespace rfl {

Expand Down Expand Up @@ -77,6 +77,9 @@ std::string enum_to_string(const EnumType _enum) {
++i;
val >>= 1;
}
if (flags.empty()) {
return "0";
}
return internal::strings::join("|", flags);
} else {
return to_string_or_number(_enum);
Expand Down
36 changes: 36 additions & 0 deletions tests/json/test_enum8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <gtest/gtest.h>

#include <cassert>
#include <rfl.hpp>
#include <rfl/json.hpp>

#include "write_and_read.hpp"

namespace test_enum8 {

enum class TestEnum : uint64_t {
None = 0,
Hello = 1 << 0,
World = 1 << 1,
HelloWorld = Hello | World
};

TestEnum operator|(TestEnum a, TestEnum b) noexcept {
return static_cast<TestEnum>(static_cast<uint64_t>(a) |
static_cast<uint64_t>(b));
}

struct SomeClass {
TestEnum e;
TestEnum f;
TestEnum g;
};

TEST(json, test_enum8) {
SomeClass t{
.e = TestEnum::None, .f = TestEnum::Hello, .g = TestEnum::HelloWorld};

write_and_read(t, R"({"e":"0","f":"Hello","g":"Hello|World"})");
}

} // namespace test_enum8
Loading