From 441a6f267f849deb8a52faabb07c4072fb2a77bd Mon Sep 17 00:00:00 2001
From: Niels <niels.lohmann@gmail.com>
Date: Sun, 8 Feb 2015 16:08:48 +0100
Subject: [PATCH] more test cases

---
 src/json.hpp      | 14 +++++++------
 src/json.hpp.re2c | 14 +++++++------
 test/unit.cpp     | 50 +++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 62 insertions(+), 16 deletions(-)

diff --git a/src/json.hpp b/src/json.hpp
index 83f8d40d..7207aeec 100644
--- a/src/json.hpp
+++ b/src/json.hpp
@@ -497,6 +497,8 @@ class basic_json
     ///////////////////////
 
     /*!
+    @brief serialization
+
     Serialization function for JSON objects. The function tries to mimick Python's
     @p json.dumps() function, and currently supports its @p indent parameter.
 
@@ -536,7 +538,7 @@ class basic_json
     // value conversion //
     //////////////////////
 
-    /// get an object
+    /// get an object (explicit)
     template <class T, typename
               std::enable_if<
                   std::is_constructible<string_t, typename T::key_type>::value and
@@ -553,7 +555,7 @@ class basic_json
         }
     }
 
-    /// get an array
+    /// get an array (explicit)
     template <class T, typename
               std::enable_if<
                   not std::is_same<T, string_t>::value and
@@ -570,7 +572,7 @@ class basic_json
         }
     }
 
-    /// get a string
+    /// get a string (explicit)
     template <typename T, typename
               std::enable_if<
                   std::is_constructible<T, string_t>::value, int>::type
@@ -586,7 +588,7 @@ class basic_json
         }
     }
 
-    /// get a boolean
+    /// get a boolean (explicit)
     template <typename T, typename
               std::enable_if<
                   std::is_same<boolean_t, T>::value, int>::type
@@ -602,7 +604,7 @@ class basic_json
         }
     }
 
-    /// explicitly get a number
+    /// get a number (explicit)
     template<typename T, typename
              std::enable_if<
                  not std::is_same<boolean_t, T>::value and
@@ -621,7 +623,7 @@ class basic_json
         }
     }
 
-    /// explicitly get a value
+    /// get a value (implicit)
     template<typename T>
     inline operator T() const
     {
diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c
index bc683e53..7e4e4701 100644
--- a/src/json.hpp.re2c
+++ b/src/json.hpp.re2c
@@ -497,6 +497,8 @@ class basic_json
     ///////////////////////
 
     /*!
+    @brief serialization
+
     Serialization function for JSON objects. The function tries to mimick Python's
     @p json.dumps() function, and currently supports its @p indent parameter.
 
@@ -536,7 +538,7 @@ class basic_json
     // value conversion //
     //////////////////////
 
-    /// get an object
+    /// get an object (explicit)
     template <class T, typename
               std::enable_if<
                   std::is_constructible<string_t, typename T::key_type>::value and
@@ -553,7 +555,7 @@ class basic_json
         }
     }
 
-    /// get an array
+    /// get an array (explicit)
     template <class T, typename
               std::enable_if<
                   not std::is_same<T, string_t>::value and
@@ -570,7 +572,7 @@ class basic_json
         }
     }
 
-    /// get a string
+    /// get a string (explicit)
     template <typename T, typename
               std::enable_if<
                   std::is_constructible<T, string_t>::value, int>::type
@@ -586,7 +588,7 @@ class basic_json
         }
     }
 
-    /// get a boolean
+    /// get a boolean (explicit)
     template <typename T, typename
               std::enable_if<
                   std::is_same<boolean_t, T>::value, int>::type
@@ -602,7 +604,7 @@ class basic_json
         }
     }
 
-    /// explicitly get a number
+    /// get a number (explicit)
     template<typename T, typename
              std::enable_if<
                  not std::is_same<boolean_t, T>::value and
@@ -621,7 +623,7 @@ class basic_json
         }
     }
 
-    /// explicitly get a value
+    /// get a value (implicit)
     template<typename T>
     inline operator T() const
     {
diff --git a/test/unit.cpp b/test/unit.cpp
index df4dc975..f31a22da 100644
--- a/test/unit.cpp
+++ b/test/unit.cpp
@@ -1034,23 +1034,26 @@ TEST_CASE("other constructors and destructor")
 
 TEST_CASE("object inspection")
 {
-    SECTION("dump")
+    SECTION("serialization")
     {
         json j {{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"} };
 
         SECTION("no indent")
         {
-            CHECK(j.dump() == "{\"array\":[1,2,3,4],\"boolean\":false,\"null\":null,\"number\":42,\"object\":{},\"string\":\"Hello world\"}");
+            CHECK(j.dump() ==
+                  "{\"array\":[1,2,3,4],\"boolean\":false,\"null\":null,\"number\":42,\"object\":{},\"string\":\"Hello world\"}");
         }
 
         SECTION("indent=0")
         {
-            CHECK(j.dump(0) == "{\n\"array\": [\n1,\n2,\n3,\n4\n],\n\"boolean\": false,\n\"null\": null,\n\"number\": 42,\n\"object\": {},\n\"string\": \"Hello world\"\n}");
+            CHECK(j.dump(0) ==
+                  "{\n\"array\": [\n1,\n2,\n3,\n4\n],\n\"boolean\": false,\n\"null\": null,\n\"number\": 42,\n\"object\": {},\n\"string\": \"Hello world\"\n}");
         }
 
         SECTION("indent=4")
         {
-            CHECK(j.dump(4) == "{\n    \"array\": [\n        1,\n        2,\n        3,\n        4\n    ],\n    \"boolean\": false,\n    \"null\": null,\n    \"number\": 42,\n    \"object\": {},\n    \"string\": \"Hello world\"\n}");
+            CHECK(j.dump(4) ==
+                  "{\n    \"array\": [\n        1,\n        2,\n        3,\n        4\n    ],\n    \"boolean\": false,\n    \"null\": null,\n    \"number\": 42,\n    \"object\": {},\n    \"string\": \"Hello world\"\n}");
         }
 
         SECTION("dump and floating-point numbers")
@@ -1157,3 +1160,42 @@ TEST_CASE("object inspection")
         }
     }
 }
+
+TEST_CASE("value conversion")
+{
+    SECTION("get an object (explicit)")
+    {
+        json::object_t o_reference = {{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"} };
+        json j(o_reference);
+
+        SECTION("json::object_t")
+        {
+            json::object_t o = j.get<std::map<std::string, json>>();
+            CHECK(json(o) == j);
+        }
+
+        SECTION("std::map<std::string, json>")
+        {
+            std::map<std::string, json> o = j.get<std::map<std::string, json>>();
+            CHECK(json(o) == j);
+        }
+
+        SECTION("std::multimap<std::string, json>")
+        {
+            std::multimap<std::string, json> o = j.get<std::multimap<std::string, json>>();
+            CHECK(json(o) == j);
+        }
+
+        SECTION("std::unordered_map<std::string, json>")
+        {
+            std::unordered_map<std::string, json> o = j.get<std::unordered_map<std::string, json>>();
+            CHECK(json(o) == j);
+        }
+
+        SECTION("std::unordered_multimap<std::string, json>")
+        {
+            std::unordered_multimap<std::string, json> o = j.get<std::unordered_multimap<std::string, json>>();
+            CHECK(json(o) == j);
+        }
+    }
+}