1
0
mirror of https://github.com/nlohmann/json synced 2024-11-30 15:40:07 +00:00

🔨 trying to make tests run with MSVC #1031

This commit is contained in:
Niels Lohmann 2018-04-02 11:34:36 +02:00
parent eb06d0531a
commit ab89ae4e50
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69

View File

@ -32,27 +32,45 @@ SOFTWARE.
using nlohmann::json; using nlohmann::json;
// from https://www.reddit.com/r/cpp/comments/75gohf/i_just_found_a_use_for_the_poop_emoji_in_c/
constexpr bool compiler_supports_utf8();
constexpr bool compiler_supports_utf8()
{
return (static_cast<unsigned char>("💩"[0]) == 0xF0) and
(static_cast<unsigned char>("💩"[1]) == 0x9F) and
(static_cast<unsigned char>("💩"[2]) == 0x92) and
(static_cast<unsigned char>("💩"[3]) == 0xA9);
}
TEST_CASE("wide strings") TEST_CASE("wide strings")
{ {
SECTION("std::wstring") SECTION("std::wstring")
{
if (compiler_supports_utf8())
{ {
std::wstring w = L"[12.2,\"Ⴥaäö💤🧢\"]"; std::wstring w = L"[12.2,\"Ⴥaäö💤🧢\"]";
json j = json::parse(w); json j = json::parse(w);
CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]"); CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]");
} }
}
SECTION("std::u16string") SECTION("std::u16string")
{
if (compiler_supports_utf8())
{ {
std::u16string w = u"[12.2,\"Ⴥaäö💤🧢\"]"; std::u16string w = u"[12.2,\"Ⴥaäö💤🧢\"]";
json j = json::parse(w); json j = json::parse(w);
CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]"); CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]");
} }
}
SECTION("std::u32string") SECTION("std::u32string")
{
if (compiler_supports_utf8())
{ {
std::u32string w = U"[12.2,\"Ⴥaäö💤🧢\"]"; std::u32string w = U"[12.2,\"Ⴥaäö💤🧢\"]";
json j = json::parse(w); json j = json::parse(w);
CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]"); CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]");
} }
}
} }