mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 21:13:51 +07:00
Test the C++11 stand-in for std::string_view of json_view
Six members of string_ref (length, begin, end, operator[], operator!=, and operator<<) were not reached before C++17, where string_ref is std::string_view. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <nlohmann/detail/view/builder.hpp>
|
#include <nlohmann/detail/view/builder.hpp>
|
||||||
|
#include <nlohmann/detail/view/string_ref.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -214,6 +215,22 @@ struct generator
|
|||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
TEST_CASE("json_view string_ref")
|
||||||
|
{
|
||||||
|
// std::string_view in C++17, a stand-in with the same members before
|
||||||
|
using nlohmann::detail::view::string_ref;
|
||||||
|
const std::string text = "abc";
|
||||||
|
const string_ref r(text);
|
||||||
|
CHECK(r.length() == 3);
|
||||||
|
CHECK(std::string(r.begin(), r.end()) == "abc");
|
||||||
|
CHECK(r[1] == 'b');
|
||||||
|
CHECK(r != string_ref("abd"));
|
||||||
|
CHECK_FALSE(r != string_ref("abcd", 3));
|
||||||
|
std::ostringstream o;
|
||||||
|
o << r;
|
||||||
|
CHECK(o.str() == "abc");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("json_view builder")
|
TEST_CASE("json_view builder")
|
||||||
{
|
{
|
||||||
SECTION("scalars and containers")
|
SECTION("scalars and containers")
|
||||||
|
|||||||
Reference in New Issue
Block a user