diff options
author | pozhilov <pozhilov@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
commit | 23bf1d16dddf213a6aa8e8d5c8621e1242a1f118 (patch) | |
tree | ed030ff443eb83431f11e53b6460b1b73d035412 /library/cpp/json/writer | |
parent | 7156b3713e77ce36387436e5558320917698b7a2 (diff) | |
download | ydb-23bf1d16dddf213a6aa8e8d5c8621e1242a1f118.tar.gz |
Restoring authorship annotation for <pozhilov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/json/writer')
-rw-r--r-- | library/cpp/json/writer/json_value.cpp | 20 | ||||
-rw-r--r-- | library/cpp/json/writer/json_value.h | 2 | ||||
-rw-r--r-- | library/cpp/json/writer/json_value_ut.cpp | 166 |
3 files changed, 94 insertions, 94 deletions
diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp index c61e8d1dc4..fa948fe469 100644 --- a/library/cpp/json/writer/json_value.cpp +++ b/library/cpp/json/writer/json_value.cpp @@ -462,38 +462,38 @@ namespace NJson { bool TJsonValue::GetBooleanSafe(const bool defaultValue) const { if (Type == JSON_UNDEFINED) return defaultValue; - + return GetBooleanSafe(); } - + long long TJsonValue::GetIntegerSafe(const long long defaultValue) const { if (Type == JSON_UNDEFINED) return defaultValue; - + return GetIntegerSafe(); } - + unsigned long long TJsonValue::GetUIntegerSafe(const unsigned long long defaultValue) const { if (Type == JSON_UNDEFINED) return defaultValue; - + return GetUIntegerSafe(); } - + double TJsonValue::GetDoubleSafe(const double defaultValue) const { if (Type == JSON_UNDEFINED) return defaultValue; - + return GetDoubleSafe(); } - + TString TJsonValue::GetStringSafe(const TString& defaultValue) const { if (Type == JSON_UNDEFINED) return defaultValue; - + return GetStringSafe(); } - + const TJsonValue::TMapType& TJsonValue::GetMapSafe() const { if (Type != JSON_MAP) ythrow TJsonException() << "Not a map"; diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h index 3f0f50bc4c..234861a4a8 100644 --- a/library/cpp/json/writer/json_value.h +++ b/library/cpp/json/writer/json_value.h @@ -135,7 +135,7 @@ namespace NJson { unsigned long long GetUIntegerRobust() const noexcept; double GetDoubleRobust() const noexcept; TString GetStringRobust() const; - + // Exception-free accessors bool GetBoolean(bool* value) const noexcept; bool GetInteger(long long* value) const noexcept; diff --git a/library/cpp/json/writer/json_value_ut.cpp b/library/cpp/json/writer/json_value_ut.cpp index dc7f6affdf..b87710bf29 100644 --- a/library/cpp/json/writer/json_value_ut.cpp +++ b/library/cpp/json/writer/json_value_ut.cpp @@ -507,98 +507,98 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) { } Y_UNIT_TEST(NonexistentFieldAccessTest) { - { - TJsonValue json; - json.InsertValue("some", "key"); - - UNIT_ASSERT(!json["some"]["weird"]["access"]["sequence"].Has("value")); - UNIT_ASSERT(!json["some"]["weird"]["access"]["sequence"].IsDefined()); - - UNIT_ASSERT(json["some"].GetType() == JSON_MAP); - } - } - + { + TJsonValue json; + json.InsertValue("some", "key"); + + UNIT_ASSERT(!json["some"]["weird"]["access"]["sequence"].Has("value")); + UNIT_ASSERT(!json["some"]["weird"]["access"]["sequence"].IsDefined()); + + UNIT_ASSERT(json["some"].GetType() == JSON_MAP); + } + } + Y_UNIT_TEST(DefaultValuesTest) { - { - TJsonValue json; - json.InsertValue("some", "key"); - json.InsertValue("existing", 1.2); - - UNIT_ASSERT_VALUES_EQUAL(json["existing"].GetDoubleSafe(), 1.2); - UNIT_ASSERT_VALUES_EQUAL(json["existing"].GetDoubleSafe(15), 1.2); - - UNIT_ASSERT_EXCEPTION(json["some"].GetUIntegerSafe(), yexception); - UNIT_ASSERT_EXCEPTION(json["some"].GetUIntegerSafe(12), yexception); - - UNIT_ASSERT_EXCEPTION(json["nonexistent"].GetUIntegerSafe(), yexception); - UNIT_ASSERT_VALUES_EQUAL(json["nonexistent"].GetUIntegerSafe(12), 12); - UNIT_ASSERT_VALUES_EQUAL(json["nonexistent"]["more_nonexistent"].GetUIntegerSafe(12), 12); - - json.InsertValue("map", TJsonValue(JSON_MAP)); - - UNIT_ASSERT_VALUES_EQUAL(json["map"]["nonexistent"].GetUIntegerSafe(12), 12); - } - } - + { + TJsonValue json; + json.InsertValue("some", "key"); + json.InsertValue("existing", 1.2); + + UNIT_ASSERT_VALUES_EQUAL(json["existing"].GetDoubleSafe(), 1.2); + UNIT_ASSERT_VALUES_EQUAL(json["existing"].GetDoubleSafe(15), 1.2); + + UNIT_ASSERT_EXCEPTION(json["some"].GetUIntegerSafe(), yexception); + UNIT_ASSERT_EXCEPTION(json["some"].GetUIntegerSafe(12), yexception); + + UNIT_ASSERT_EXCEPTION(json["nonexistent"].GetUIntegerSafe(), yexception); + UNIT_ASSERT_VALUES_EQUAL(json["nonexistent"].GetUIntegerSafe(12), 12); + UNIT_ASSERT_VALUES_EQUAL(json["nonexistent"]["more_nonexistent"].GetUIntegerSafe(12), 12); + + json.InsertValue("map", TJsonValue(JSON_MAP)); + + UNIT_ASSERT_VALUES_EQUAL(json["map"]["nonexistent"].GetUIntegerSafe(12), 12); + } + } + Y_UNIT_TEST(GetArrayPointerInArrayTest) { - TJsonValue outer; - { - TJsonValue json; - json.AppendValue(1); - json.AppendValue(2); - json.AppendValue(3); - - outer.AppendValue(json); - } + TJsonValue outer; + { + TJsonValue json; + json.AppendValue(1); + json.AppendValue(2); + json.AppendValue(3); + + outer.AppendValue(json); + } const TJsonValue::TArray* array = nullptr; - GetArrayPointer(outer, 0, &array); - UNIT_ASSERT_VALUES_EQUAL((*array)[1], 2); - } - + GetArrayPointer(outer, 0, &array); + UNIT_ASSERT_VALUES_EQUAL((*array)[1], 2); + } + Y_UNIT_TEST(GetArrayPointerInMapTest) { - TJsonValue outer; - { - TJsonValue json; - json.AppendValue(1); - json.AppendValue(2); - json.AppendValue(3); - - outer.InsertValue("x", json); - } + TJsonValue outer; + { + TJsonValue json; + json.AppendValue(1); + json.AppendValue(2); + json.AppendValue(3); + + outer.InsertValue("x", json); + } const TJsonValue::TArray* array = nullptr; - GetArrayPointer(outer, "x", &array); - UNIT_ASSERT_VALUES_EQUAL((*array)[1], 2); - } - + GetArrayPointer(outer, "x", &array); + UNIT_ASSERT_VALUES_EQUAL((*array)[1], 2); + } + Y_UNIT_TEST(GetMapPointerInArrayTest) { - TJsonValue outer; - { - TJsonValue json; - json.InsertValue("a", 1); - json.InsertValue("b", 2); - json.InsertValue("c", 3); - - outer.AppendValue(json); - } + TJsonValue outer; + { + TJsonValue json; + json.InsertValue("a", 1); + json.InsertValue("b", 2); + json.InsertValue("c", 3); + + outer.AppendValue(json); + } const TJsonValue::TMapType* map = nullptr; - GetMapPointer(outer, 0, &map); - UNIT_ASSERT_VALUES_EQUAL((*map).at("b"), 2); - } - + GetMapPointer(outer, 0, &map); + UNIT_ASSERT_VALUES_EQUAL((*map).at("b"), 2); + } + Y_UNIT_TEST(GetMapPointerInMapTest) { - TJsonValue outer; - { - TJsonValue json; - json.InsertValue("a", 1); - json.InsertValue("b", 2); - json.InsertValue("c", 3); - - outer.InsertValue("x", json); - } + TJsonValue outer; + { + TJsonValue json; + json.InsertValue("a", 1); + json.InsertValue("b", 2); + json.InsertValue("c", 3); + + outer.InsertValue("x", json); + } const TJsonValue::TMapType* map = nullptr; - GetMapPointer(outer, "x", &map); - UNIT_ASSERT_VALUES_EQUAL((*map).at("b"), 2); - } + GetMapPointer(outer, "x", &map); + UNIT_ASSERT_VALUES_EQUAL((*map).at("b"), 2); + } Y_UNIT_TEST(GetIntegerRobustBignumStringTest) { TString value = "1626862681464633683"; |