mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 00:26:19 +08:00
Added a test for string views (#223)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <string_view>
|
||||
|
||||
namespace test_string_view {
|
||||
|
||||
struct TestStruct {
|
||||
std::string_view name;
|
||||
};
|
||||
|
||||
TEST(json, test_string_view) {
|
||||
const std::string name = "Homer Simpson";
|
||||
const auto test_struct = TestStruct{.name = name};
|
||||
|
||||
const auto json_string = rfl::json::write(test_struct);
|
||||
const std::string expected = R"({"name":"Homer Simpson"})";
|
||||
EXPECT_EQ(json_string, expected)
|
||||
<< "Test failed on write. Expected:" << std::endl
|
||||
<< expected << std::endl
|
||||
<< "Got: " << std::endl
|
||||
<< json_string << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
} // namespace test_string_view
|
||||
Reference in New Issue
Block a user