33 TEST(Dynamic, ObjectBasics) {
68 newObject[
"a"] =
true;
71 EXPECT_EQ(*newObject.keys().begin(), newObject.items().begin()->first);
72 EXPECT_EQ(*newObject.values().begin(), newObject.items().begin()->second);
73 std::vector<std::pair<std::string, dynamic>> found;
75 newObject.keys().begin()->asString(), *newObject.values().begin());
82 std::next(newObject.items().begin())->second);
84 std::next(newObject.keys().begin())->asString(),
87 std::sort(found.begin(), found.end());
102 d3[
"foo"] = dynamic::array(1, 2, 3);
119 EXPECT_EQ(objInsert.find(
"1")->second.size(), 1);
133 newObject[objDefinedInOneOrder] = 12;
134 EXPECT_EQ(newObject.at(objDefinedInOneOrder).getInt(), 12);
135 EXPECT_EQ(newObject.at(sameObjInDifferentOrder).getInt(), 12);
165 EXPECT_EQ(newMergeObj, combinedPreferObj2);
168 mergeObj1.
update(mergeObj2);
169 EXPECT_EQ(mergeObj1, combinedPreferObj2);
170 dynamic arr = dynamic::array(1, 2, 3, 4, 5, 6);
173 mergeObj1 = origMergeObj1;
175 EXPECT_EQ(mergeObj1, combinedPreferObj1);
180 struct StaticStrings {
181 static constexpr
auto kA =
"a";
182 static constexpr
const char* kB =
"b";
191 TEST(Dynamic, ObjectHeterogeneousAccess) {
304 EXPECT_EQ(obj[StaticStrings::kFoo], 789);
312 obj[StaticStrings::kBar] = 43;
316 EXPECT_EQ(obj.erase(StaticStrings::kB), 1);
327 TEST(Dynamic, CastFromVectorOfBooleans) {
336 TEST(Dynamic, CastFromConstVectorOfBooleans) {
337 const std::vector<bool>
b = {
true,
false};
354 auto it = obj.find(
"key2");
362 auto ret = obj.erase(
std::next(obj.items().begin()), obj.items().end());
365 obj.erase(obj.items().begin());
370 dynamic arr = dynamic::array(1, 2, 3, 4, 5, 6);
393 dynamic array = dynamic::array(1, 2, 3);
405 array.
resize(12,
"something");
411 dynamic val = dynamic::array(
"foo",
"bar", dynamic::array(
"foo1",
"bar1"));
419 val2.at(2).at(0) =
"foo3";
420 val2.at(2).at(1) =
"bar3";
429 obj2.
at(
"a") = dynamic::array(1, 2, 3);
431 dynamic expected = dynamic::array(1, 2, 3);
435 TEST(Dynamic, ArrayReassignment) {
437 dynamic d1 = dynamic::array(o);
440 d1 = dynamic::array(o);
450 LOG(ERROR) <<
"operator < returned " <<
static_cast<int>(
foo)
451 <<
" instead of throwing";
452 }
catch (std::exception
const&) {
488 TEST(Dynamic, GetSetDefaultTest) {
494 EXPECT_EQ(d2.setDefault(
"foo",
"quux"),
"bar");
495 d2.setDefault(
"bar", dynamic::array).push_back(42);
509 dynamic k10{10}, k20{20}, kTrue{
true};
520 TEST(Dynamic, ObjectForwarding) {
531 dynamic array = dynamic::array(1, 2,
"three");
543 *
object.get_ptr(
"one") = 11;
551 dynamic::array(1, 2, 3),
559 dynamic::array(5, 6),
566 for (
const auto& source : ds) {
567 for (
const auto&
dest : dd) {
692 TEST(Dynamic, GetSmallThings) {
728 dd.
at(
"key1").getString() +=
" hello";
760 std::stringstream ss;
765 TEST(Dynamic, WriteThroughArrayIterators) {
767 dynamic d = dynamic::array(cint, cint, cint);
770 for (
auto&
val : d) {
776 for (
auto&
val : d) {
783 for (
auto&
val : d) {
789 TEST(Dynamic, MoveOutOfArrayIterators) {
791 dynamic d = dynamic::array(ds, ds, ds);
794 for (
auto&
val : d) {
799 for (
auto&
val : d) {
804 for (
auto&
val : d) {
810 TEST(Dynamic, WriteThroughObjectIterators) {
833 TEST(Dynamic, MoveOutOfObjectIterators) {
854 TEST(Dynamic, ArrayIteratorInterop) {
855 dynamic d = dynamic::array(0, 1, 2);
859 auto cit = cdref.
begin();
872 decltype(cit) cit2 = it;
876 TEST(Dynamic, ObjectIteratorInterop) {
882 auto cit = cdref.
find(0);
889 auto it2 = d.
erase(it);
893 decltype(cit) cit2 = it2;
897 TEST(Dynamic, MergePatchWithNonObject) {
900 dynamic patch = dynamic::array(1, 2, 3);
906 TEST(Dynamic, MergePatchReplaceInFlatObject) {
916 TEST(Dynamic, MergePatchAddInFlatObject) {
926 TEST(Dynamic, MergePatchReplaceInNestedObject) {
931 EXPECT_EQ(100, target[
"a"][
"d"].getInt());
935 TEST(Dynamic, MergePatchAddInNestedObject) {
941 EXPECT_EQ(10, target[
"a"][
"d"].getInt());
942 EXPECT_EQ(
"f", target[
"a"][
"e"].getString());
946 TEST(Dynamic, MergeNestePatch) {
954 auto ary = patch[
"a"][
"d"];
962 TEST(Dynamic, MergePatchRemoveInFlatObject) {
971 TEST(Dynamic, MergePatchRemoveInNestedObject) {
977 EXPECT_EQ(10, target[
"a"][
"d"].getInt());
982 TEST(Dynamic, MergePatchRemoveNonExistent) {
992 TEST(Dynamic, MergeDiffFlatObjects) {
995 auto patch = dynamic::merge_diff(source, target);
1006 TEST(Dynamic, MergeDiffNestedObjects) {
1008 "d", dynamic::array(1, 2, 3));
1010 "d", dynamic::array(2, 3, 4));
1012 auto patch = dynamic::merge_diff(source, target);
1034 dynamic ary = dynamic::array(
"bar",
"baz", dynamic::array(
"bletch",
"xyzzy"));
1035 target[
"foo"] = ary;
1047 target[
"xyz"][
"def"] = dynamic::array(1, 2, 3);
1048 target[
"long_array"] = dynamic::array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
size_t parse(const char *buf, size_t len)
const Map::mapped_type * get_ptr(const Map &map, const Key &key)
#define EXPECT_ANY_THROW(statement)
static ObjectMaker object()
IfIsNonStringDynamicConvertible< K, dynamic > getDefault(K &&k, const dynamic &v=dynamic::object) const &
std::atomic< int64_t > sum(0)
#define EXPECT_THROW(statement, expected_exception)
double getDouble() const &
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
RfcParam d5(false, exampleHex3)
IfIsNonStringDynamicConvertible< K, std::size_t > count(K &&) const
const std::string & getString() const &
IfIsNonStringDynamicConvertible< K, dynamic & > setDefault(K &&k, V &&v)
constexpr auto size(C const &c) -> decltype(c.size())
RfcParam d4(true, exampleHex2)
constexpr auto empty(C const &c) -> decltype(c.empty())
void insert(K &&, V &&val)
static map< string, int > m
IfIsNonStringDynamicConvertible< K, const_item_iterator > find(K &&) const
void push_back(dynamic const &)
folly::Singleton< int > bar
IfIsNonStringDynamicConvertible< K, std::size_t > erase(K &&)
#define EXPECT_TRUE(condition)
void update(const dynamic &mergeObj)
IterableProxy< const_item_iterator > items() const
static void array(EmptyArrayTag)
#define EXPECT_NE(val1, val2)
IfIsNonStringDynamicConvertible< K, dynamic const & > at(K &&) const &
#define EXPECT_FALSE(condition)
RfcParam d3(false, exampleHex1)
Range< const char * > StringPiece
void update_missing(const dynamic &other)
const_iterator begin() const
void merge_patch(const dynamic &patch)
void merge(unsigned int iters, size_t maxSize, size_t bufSize)
#define ASSERT_TRUE(condition)
void resize(std::size_t n, dynamic const &=nullptr)
const_iterator end() const
const dynamic * get_ptr(json_pointer const &) const &
constexpr detail::First first
std::string make_long_string()