changeset 490:d2b2071a9b85

Json: add empty object() and array(), #367
author David Demelier <markand@malikania.fr>
date Sun, 15 Nov 2015 13:30:28 +0100
parents 4376ec6e5329
children c03f84bdabe9
files modules/json/json.h modules/json/test/main.cpp
diffstat 2 files changed, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/json/json.h	Fri Nov 13 23:08:34 2015 +0100
+++ b/modules/json/json.h	Sun Nov 15 13:30:28 2015 +0100
@@ -1164,6 +1164,16 @@
 std::string escape(const std::string &input);
 
 /**
+ * Convenient function to create an empty array.
+ *
+ * @return an empty array
+ */
+inline Value array()
+{
+	return Value(Type::Array);
+}
+
+/**
  * Convenient function for creating array from initializer list.
  *
  * @param values the values
@@ -1175,6 +1185,16 @@
 }
 
 /**
+ * Convenient function to create an empty object.
+ *
+ * @return an empty object
+ */
+inline Value object()
+{
+	return Value(Type::Object);
+}
+
+/**
  * Convenient function for creating object from initializer list.
  *
  * @param values the values
--- a/modules/json/test/main.cpp	Fri Nov 13 23:08:34 2015 +0100
+++ b/modules/json/test/main.cpp	Sun Nov 15 13:30:28 2015 +0100
@@ -156,6 +156,38 @@
 	}
 }
 
+TEST(Constructors, emptyObject)
+{
+	json::Value object(json::Type::Object);
+
+	ASSERT_TRUE(object.isObject());
+	ASSERT_EQ(0U, object.size());
+}
+
+TEST(Constructors, emptyObject2)
+{
+	json::Value object = json::object();
+
+	ASSERT_TRUE(object.isObject());
+	ASSERT_EQ(0U, object.size());
+}
+
+TEST(Constructors, emptyArray)
+{
+	json::Value array(json::Type::Array);
+
+	ASSERT_TRUE(array.isArray());
+	ASSERT_EQ(0U, array.size());
+}
+
+TEST(Constructors, emptyArray2)
+{
+	json::Value array = json::array();
+
+	ASSERT_TRUE(array.isArray());
+	ASSERT_EQ(0U, array.size());
+}
+
 /*
  * Object
  * ------------------------------------------------------------------