Commit fc7b0a04 authored by miloyip's avatar miloyip

Add const Value& version of SetValueByPointer() and improve coverage

parent 45bed001
......@@ -742,6 +742,11 @@ typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename
return pointer.Set(root, value, a);
}
template <typename T>
typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, const typename T::ValueType& value, typename T::AllocatorType& a) {
return pointer.Set(root, value, a);
}
template <typename T>
typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, const typename T::Ch* value, typename T::AllocatorType& a) {
return pointer.Set(root, value, a);
......@@ -765,6 +770,11 @@ typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], ty
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
}
template <typename T, typename CharType, size_t N>
typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::ValueType& value, typename T::AllocatorType& a) {
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
}
template <typename T, typename CharType, size_t N>
typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::Ch* value, typename T::AllocatorType& a) {
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
......@@ -790,6 +800,11 @@ typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename
return pointer.Set(root, value);
}
template <typename T>
typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, const typename T::ValueType& value) {
return pointer.Set(root, value);
}
template <typename T>
typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, const typename T::Ch* value) {
return pointer.Set(root, value);
......@@ -813,6 +828,11 @@ typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], ty
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value);
}
template <typename T, typename CharType, size_t N>
typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::ValueType& value) {
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value);
}
template <typename T, typename CharType, size_t N>
typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::Ch* value) {
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value);
......
......@@ -693,6 +693,11 @@ TEST(Pointer, Set) {
Pointer("/foo/null").Set(d, Value().Move(), a);
EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull());
// Const Value version
const Value foo(d["foo"], a);
Pointer("/clone").Set(d, foo, a);
EXPECT_EQ(foo, *GetValueByPointer(d, "/clone"));
// Generic version
Pointer("/foo/int").Set(d, -1, a);
EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt());
......@@ -747,6 +752,11 @@ TEST(Pointer, Set_NoAllocator) {
Pointer("/foo/null").Set(d, Value().Move());
EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull());
// Const Value version
const Value foo(d["foo"], d.GetAllocator());
Pointer("/clone").Set(d, foo);
EXPECT_EQ(foo, *GetValueByPointer(d, "/clone"));
// Generic version
Pointer("/foo/int").Set(d, -1);
EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt());
......@@ -1066,6 +1076,11 @@ TEST(Pointer, SetValueByPointer_Pointer) {
SetValueByPointer(d, Pointer("/foo/null"), Value().Move(), a);
EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull());
// Const Value version
const Value foo(d["foo"], d.GetAllocator());
SetValueByPointer(d, Pointer("/clone"), foo, a);
EXPECT_EQ(foo, *GetValueByPointer(d, "/clone"));
// Generic version
SetValueByPointer(d, Pointer("/foo/int"), -1, a);
EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt());
......@@ -1118,6 +1133,11 @@ TEST(Pointer, SetValueByPointer_String) {
SetValueByPointer(d, "/foo/null", Value().Move(), a);
EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull());
// Const Value version
const Value foo(d["foo"], d.GetAllocator());
SetValueByPointer(d, "/clone", foo, a);
EXPECT_EQ(foo, *GetValueByPointer(d, "/clone"));
// Generic version
SetValueByPointer(d, "/foo/int", -1, a);
EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt());
......@@ -1169,6 +1189,11 @@ TEST(Pointer, SetValueByPointer_Pointer_NoAllocator) {
SetValueByPointer(d, Pointer("/foo/null"), Value().Move());
EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull());
// Const Value version
const Value foo(d["foo"], d.GetAllocator());
SetValueByPointer(d, Pointer("/clone"), foo);
EXPECT_EQ(foo, *GetValueByPointer(d, "/clone"));
// Generic version
SetValueByPointer(d, Pointer("/foo/int"), -1);
EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt());
......@@ -1220,6 +1245,11 @@ TEST(Pointer, SetValueByPointer_String_NoAllocator) {
SetValueByPointer(d, "/foo/null", Value().Move());
EXPECT_TRUE(GetValueByPointer(d, "/foo/null")->IsNull());
// Const Value version
const Value foo(d["foo"], d.GetAllocator());
SetValueByPointer(d, "/clone", foo);
EXPECT_EQ(foo, *GetValueByPointer(d, "/clone"));
// Generic version
SetValueByPointer(d, "/foo/int", -1);
EXPECT_EQ(-1, GetValueByPointer(d, "/foo/int")->GetInt());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment