1 // __ _____ _____ _____ 2 // __| | __| | | | JSON for Modern C++ (supporting code) 3 // | | |__ | | | | | | version 3.11.2 4 // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 // 6 // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me> 7 // SPDX-License-Identifier: MIT 8 9 #include "doctest_compatibility.h" 10 11 #include <nlohmann/json.hpp> 12 13 TEST_CASE("user-defined string literals") 14 { 15 auto j_expected = nlohmann::json::parse(R"({"foo": "bar", "baz": 42})"); 16 auto ptr_expected = nlohmann::json::json_pointer("/foo/bar"); 17 18 SECTION("using namespace nlohmann::literals::json_literals") 19 { 20 using namespace nlohmann::literals::json_literals; // NOLINT(google-build-using-namespace) 21 22 CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); 23 CHECK("/foo/bar"_json_pointer == ptr_expected); 24 } 25 26 SECTION("using namespace nlohmann::json_literals") 27 { 28 using namespace nlohmann::json_literals; // NOLINT(google-build-using-namespace) 29 30 CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); 31 CHECK("/foo/bar"_json_pointer == ptr_expected); 32 } 33 34 SECTION("using namespace nlohmann::literals") 35 { 36 using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) 37 38 CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); 39 CHECK("/foo/bar"_json_pointer == ptr_expected); 40 } 41 42 SECTION("using namespace nlohmann") 43 { 44 using namespace nlohmann; // NOLINT(google-build-using-namespace) 45 46 CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); 47 CHECK("/foo/bar"_json_pointer == ptr_expected); 48 } 49 50 #ifndef JSON_TEST_NO_GLOBAL_UDLS 51 SECTION("global namespace") 52 { 53 CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected); 54 CHECK("/foo/bar"_json_pointer == ptr_expected); 55 } 56 #endif 57 } 58