From b3b0370ce2737336d0482cf6a23d4eb7daf75a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=2E=20Patrick=20Urbanke=20=28=E5=8A=89=E8=87=AA=E6=88=90?= =?UTF-8?q?=29?= Date: Sun, 20 Oct 2024 12:51:05 +0200 Subject: [PATCH] Added a test for string views (#223) --- tests/json/test_string_view.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/json/test_string_view.cpp diff --git a/tests/json/test_string_view.cpp b/tests/json/test_string_view.cpp new file mode 100644 index 00000000..e82759da --- /dev/null +++ b/tests/json/test_string_view.cpp @@ -0,0 +1,28 @@ +#include + +#include +#include +#include +#include +#include + +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