Skip to content

Commit b3b0370

Browse files
Added a test for string views (#223)
1 parent 70b57ea commit b3b0370

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/json/test_string_view.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <functional>
4+
#include <iostream>
5+
#include <rfl.hpp>
6+
#include <rfl/json.hpp>
7+
#include <string_view>
8+
9+
namespace test_string_view {
10+
11+
struct TestStruct {
12+
std::string_view name;
13+
};
14+
15+
TEST(json, test_string_view) {
16+
const std::string name = "Homer Simpson";
17+
const auto test_struct = TestStruct{.name = name};
18+
19+
const auto json_string = rfl::json::write(test_struct);
20+
const std::string expected = R"({"name":"Homer Simpson"})";
21+
EXPECT_EQ(json_string, expected)
22+
<< "Test failed on write. Expected:" << std::endl
23+
<< expected << std::endl
24+
<< "Got: " << std::endl
25+
<< json_string << std::endl
26+
<< std::endl;
27+
}
28+
} // namespace test_string_view

0 commit comments

Comments
 (0)