unit-udl.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include "doctest_compatibility.h"
  9. #include <nlohmann/json.hpp>
  10. TEST_CASE("user-defined string literals")
  11. {
  12. auto j_expected = nlohmann::json::parse(R"({"foo": "bar", "baz": 42})");
  13. auto ptr_expected = nlohmann::json::json_pointer("/foo/bar");
  14. SECTION("using namespace nlohmann::literals::json_literals")
  15. {
  16. using namespace nlohmann::literals::json_literals; // NOLINT(google-build-using-namespace)
  17. CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected);
  18. CHECK("/foo/bar"_json_pointer == ptr_expected);
  19. }
  20. SECTION("using namespace nlohmann::json_literals")
  21. {
  22. using namespace nlohmann::json_literals; // NOLINT(google-build-using-namespace)
  23. CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected);
  24. CHECK("/foo/bar"_json_pointer == ptr_expected);
  25. }
  26. SECTION("using namespace nlohmann::literals")
  27. {
  28. using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
  29. CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected);
  30. CHECK("/foo/bar"_json_pointer == ptr_expected);
  31. }
  32. SECTION("using namespace nlohmann")
  33. {
  34. using namespace nlohmann; // NOLINT(google-build-using-namespace)
  35. CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected);
  36. CHECK("/foo/bar"_json_pointer == ptr_expected);
  37. }
  38. #ifndef JSON_TEST_NO_GLOBAL_UDLS
  39. SECTION("global namespace")
  40. {
  41. CHECK(R"({"foo": "bar", "baz": 42})"_json == j_expected);
  42. CHECK("/foo/bar"_json_pointer == ptr_expected);
  43. }
  44. #endif
  45. }