diff options
| author | nae202 <[email protected]> | 2025-09-23 07:48:35 +0300 |
|---|---|---|
| committer | nae202 <[email protected]> | 2025-09-23 08:03:21 +0300 |
| commit | 63774bc851bb76e24f369ef4e0328e5f05edbb4b (patch) | |
| tree | d3226ed9a5f200097949f6001a7e3183aff7adfa /library/cpp/json/writer | |
| parent | f4cbf746a0b6649479cfb305eceababced0ac10a (diff) | |
Style fix
commit_hash:d506e2a0f2770f3662449a3711e976499eb9ccbb
Diffstat (limited to 'library/cpp/json/writer')
| -rw-r--r-- | library/cpp/json/writer/json.cpp | 35 | ||||
| -rw-r--r-- | library/cpp/json/writer/json.h | 50 | ||||
| -rw-r--r-- | library/cpp/json/writer/json_ut.cpp | 2 | ||||
| -rw-r--r-- | library/cpp/json/writer/json_value.cpp | 238 | ||||
| -rw-r--r-- | library/cpp/json/writer/json_value.h | 10 | ||||
| -rw-r--r-- | library/cpp/json/writer/json_value_ut.cpp | 21 |
6 files changed, 164 insertions, 192 deletions
diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index a732e470521..0b2a6e1b47b 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -25,7 +25,6 @@ namespace NJsonWriter { StringStream.Reset(new TStringStream); Stream = StringStream.Get(); } - Stack.reserve(64); // should be enough for most cases StackPush(JE_OUTER_SPACE); } @@ -84,12 +83,13 @@ namespace NJsonWriter { } void TBuf::PrintIndentation(bool closing) { - if (!IndentSpaces) + if (!IndentSpaces) { return; + } const int indentation = IndentSpaces * (Stack.size() - 1); - if (!indentation && !closing) + if (!indentation && !closing) { return; - + } PrintWhitespaces(Max(0, indentation), true); } @@ -103,7 +103,7 @@ namespace NJsonWriter { const TStringBuf buffer = whitespacesTemplate.SubString(prependWithNewLine ? 0 : 1, count); count -= buffer.size(); UnsafeWriteRawBytes(buffer); - prependWithNewLine = false; // skip '\n' in subsequent writes + prependWithNewLine = false; // skip '\n' in subsequent writes } while (count > 0); } @@ -282,7 +282,7 @@ namespace NJsonWriter { } } }; - } + } // namespace inline void TBuf::WriteBareString(const TStringBuf s, EHtmlEscapeMode hem) { RawWriteChar('"'); @@ -320,10 +320,10 @@ namespace NJsonWriter { RawWriteChar(hexDigits[(c & 0x0f)]); } -#define MATCH(sym, string) \ - case sym: \ - UnsafeWriteRawBytes(beg, cur - beg); \ - UnsafeWriteRawBytes(TStringBuf(string)); \ +#define MATCH(sym, string) \ + case sym: \ + UnsafeWriteRawBytes(beg, cur - beg); \ + UnsafeWriteRawBytes(TStringBuf(string)); \ return true inline bool TBuf::EscapedWriteChar(const char* beg, const char* cur, EHtmlEscapeMode hem) { @@ -336,12 +336,11 @@ namespace NJsonWriter { MATCH('>', ">"); MATCH('&', "&"); } - //for other characters, we fall through to the non-HTML-escaped part + // for other characters, we fall through to the non-HTML-escaped part } - - if (hem == HEM_RELAXED && c == '/') + if (hem == HEM_RELAXED && c == '/') { return false; - + } if (hem != HEM_UNSAFE) { switch (c) { case '/': @@ -357,7 +356,6 @@ namespace NJsonWriter { } // for other characters, fall through to the non-escaped part } - switch (c) { MATCH('"', "\\\""); MATCH('\\', "\\\\"); @@ -372,7 +370,6 @@ namespace NJsonWriter { WriteHexEscape(c); return true; } - return false; } @@ -407,8 +404,9 @@ namespace NJsonWriter { case JSON_ARRAY: { BeginList(); const TJsonValue::TArray& arr = v->GetArray(); - for (const auto& it : arr) + for (const auto& it : arr) { WriteJsonValue(&it, sortKeys, mode, ndigits); + } EndList(); break; } @@ -513,5 +511,4 @@ namespace NJsonWriter { NeedNewline = from.NeedNewline; Stack.swap(from.Stack); } - -} +} // namespace NJsonWriter diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h index 0aae2531b94..4a6e0af8129 100644 --- a/library/cpp/json/writer/json.h +++ b/library/cpp/json/writer/json.h @@ -10,10 +10,10 @@ namespace NJson { class TJsonValue; -} +} // namespace NJson namespace NJsonWriter { - enum EJsonEntity : ui8 { + enum EJsonEntity: ui8 { JE_OUTER_SPACE = 1, JE_LIST, JE_OBJECT, @@ -39,7 +39,7 @@ namespace NJsonWriter { TVector<EJsonEntity> Stack; }; - class TBuf : TNonCopyable { + class TBuf: TNonCopyable { public: TBuf(EHtmlEscapeMode mode = HEM_DONT_ESCAPE_HTML, IOutputStream* stream = nullptr); @@ -71,49 +71,49 @@ namespace NJsonWriter { TBuf& EndObject(); /*** Indent the resulting JSON with spaces. - * By default (spaces==0) no formatting is done. */ + * By default (spaces==0) no formatting is done. */ TBuf& SetIndentSpaces(int spaces) { IndentSpaces = spaces; return *this; } /*** NaN and Inf are not valid json values, - * so if WriteNanAsString is set, writer would write string - * intead of throwing exception (default case) */ + * so if WriteNanAsString is set, writer would write string + * intead of throwing exception (default case) */ TBuf& SetWriteNanAsString(bool writeNanAsString = true) { WriteNanAsString = writeNanAsString; return *this; } /*** Return the string formed in the internal TStringStream. - * You may only call it if the `stream' parameter was NULL - * at construction time. */ + * You may only call it if the `stream' parameter was NULL + * at construction time. */ const TString& Str() const; /*** Dump and forget the string constructed so far. - * You may only call it if the `stream' parameter was NULL - * at construction time. */ + * You may only call it if the `stream' parameter was NULL + * at construction time. */ void FlushTo(IOutputStream* stream); /*** Write a literal string that represents a JSON value - * (string, number, object, array, bool, or null). - * - * Example: - * j.UnsafeWriteValue("[1, 2, 3, \"o'clock\", 4, \"o'clock rock\"]"); - * - * As in all of the Unsafe* functions, no escaping is done. */ + * (string, number, object, array, bool, or null). + * + * Example: + * j.UnsafeWriteValue("[1, 2, 3, \"o'clock\", 4, \"o'clock rock\"]"); + * + * As in all of the Unsafe* functions, no escaping is done. */ void UnsafeWriteValue(const TStringBuf& s); void UnsafeWriteValue(const char* s, size_t len); /*** When in the context of an object, write a literal string - * that represents a key:value pair (or several pairs). - * - * Example: - * j.BeginObject(); - * j.UnsafeWritePair("\"adam\": \"male\", \"eve\": \"female\""); - * j.EndObject(); - * - * As in all of the Unsafe* functions, no escaping is done. */ + * that represents a key:value pair (or several pairs). + * + * Example: + * j.BeginObject(); + * j.UnsafeWritePair("\"adam\": \"male\", \"eve\": \"female\""); + * j.EndObject(); + * + * As in all of the Unsafe* functions, no escaping is done. */ TPairContext UnsafeWritePair(const TStringBuf& s); /*** Copy the supplied string directly into the output stream. */ @@ -286,4 +286,4 @@ namespace NJsonWriter { } TString WrapJsonToCallback(const TBuf& buf, TStringBuf callback); -} +} // namespace NJsonWriter diff --git a/library/cpp/json/writer/json_ut.cpp b/library/cpp/json/writer/json_ut.cpp index 1768e912249..564b9ac8adf 100644 --- a/library/cpp/json/writer/json_ut.cpp +++ b/library/cpp/json/writer/json_ut.cpp @@ -265,4 +265,4 @@ Y_UNIT_TEST_SUITE(JsonWriter) { UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"({"\u003C\u003E&":"Ololo","<>&":"Ololo2"})"); } } -} +} // Y_UNIT_TEST_SUITE(JsonWriter) diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp index e71e9ce8199..6a0546fe043 100644 --- a/library/cpp/json/writer/json_value.cpp +++ b/library/cpp/json/writer/json_value.cpp @@ -20,25 +20,25 @@ AreJsonMapsEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) { Y_ABORT_UNLESS(lhs.GetType() == JSON_MAP, "lhs has not a JSON_MAP type."); - if (rhs.GetType() != JSON_MAP) + if (rhs.GetType() != JSON_MAP) { return false; - + } typedef TJsonValue::TMapType TMapType; const TMapType& lhsMap = lhs.GetMap(); const TMapType& rhsMap = rhs.GetMap(); - if (lhsMap.size() != rhsMap.size()) + if (lhsMap.size() != rhsMap.size()) { return false; - + } for (const auto& lhsIt : lhsMap) { TMapType::const_iterator rhsIt = rhsMap.find(lhsIt.first); - if (rhsIt == rhsMap.end()) + if (rhsIt == rhsMap.end()) { return false; - - if (lhsIt.second != rhsIt->second) + } + if (lhsIt.second != rhsIt->second) { return false; + } } - return true; } @@ -48,22 +48,22 @@ AreJsonArraysEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) { Y_ABORT_UNLESS(lhs.GetType() == JSON_ARRAY, "lhs has not a JSON_ARRAY type."); - if (rhs.GetType() != JSON_ARRAY) + if (rhs.GetType() != JSON_ARRAY) { return false; - + } typedef TJsonValue::TArray TArray; const TArray& lhsArray = lhs.GetArray(); const TArray& rhsArray = rhs.GetArray(); - if (lhsArray.size() != rhsArray.size()) + if (lhsArray.size() != rhsArray.size()) { return false; - + } for (TArray::const_iterator lhsIt = lhsArray.begin(), rhsIt = rhsArray.begin(); lhsIt != lhsArray.end(); ++lhsIt, ++rhsIt) { - if (*lhsIt != *rhsIt) + if (*lhsIt != *rhsIt) { return false; + } } - return true; } @@ -106,16 +106,18 @@ namespace NJson { } TJsonValue& TJsonValue::operator=(const TJsonValue& val) { - if (this == &val) + if (this == &val) { return *this; + } TJsonValue tmp(val); tmp.Swap(*this); return *this; } TJsonValue& TJsonValue::operator=(TJsonValue&& val) noexcept { - if (this == &val) + if (this == &val) { return *this; + } TJsonValue tmp(std::move(val)); tmp.Swap(*this); return *this; @@ -181,12 +183,11 @@ namespace NJson { } TJsonValue& TJsonValue::SetType(const EJsonValueType type) { - if (Type == type) + if (Type == type) { return *this; - + } Clear(); Type = type; - switch (Type) { case JSON_STRING: new (&Value.String) TString(); @@ -205,7 +206,6 @@ namespace NJson { case JSON_DOUBLE: break; } - return *this; } @@ -273,8 +273,9 @@ namespace NJson { void TJsonValue::EraseValue(const TStringBuf key) { if (IsMap()) { TMapType::iterator it = Value.Map->find(key); - if (it != Value.Map->end()) + if (it != Value.Map->end()) { Value.Map->erase(it); + } } } @@ -313,8 +314,9 @@ namespace NJson { TJsonValue& TJsonValue::operator[](const size_t idx) { SetType(JSON_ARRAY); - if (Value.Array->size() <= idx) + if (Value.Array->size() <= idx) { Value.Array->resize(idx + 1); + } return (*Value.Array)[idx]; } @@ -330,21 +332,21 @@ namespace NJson { const TJsonValue::TArray Array{}; const TJsonValue Value{}; }; - } + } // namespace const TJsonValue& TJsonValue::operator[](const size_t idx) const noexcept { const TJsonValue* ret = nullptr; - if (GetValuePointer(idx, &ret)) + if (GetValuePointer(idx, &ret)) { return *ret; - + } return Singleton<TDefaultsHolder>()->Value; } const TJsonValue& TJsonValue::operator[](const TStringBuf& key) const noexcept { const TJsonValue* ret = nullptr; - if (GetValuePointer(key, &ret)) + if (GetValuePointer(key, &ret)) { return *ret; - + } return Singleton<TDefaultsHolder>()->Value; } @@ -353,9 +355,9 @@ namespace NJson { } long long TJsonValue::GetInteger() const { - if (!IsInteger()) + if (!IsInteger()) { return 0; - + } switch (Type) { case JSON_INTEGER: return Value.Integer; @@ -373,19 +375,16 @@ namespace NJson { } unsigned long long TJsonValue::GetUInteger() const { - if (!IsUInteger()) + if (!IsUInteger()) { return 0; - + } switch (Type) { case JSON_UINTEGER: return Value.UInteger; - case JSON_INTEGER: return Value.Integer; - case JSON_DOUBLE: return Value.Double; - default: Y_ASSERT(false && "Unexpected type."); return 0; @@ -393,19 +392,16 @@ namespace NJson { } double TJsonValue::GetDouble() const { - if (!IsDouble()) + if (!IsDouble()) { return 0.0; - + } switch (Type) { case JSON_DOUBLE: return Value.Double; - case JSON_INTEGER: return Value.Integer; - case JSON_UINTEGER: return Value.UInteger; - default: Y_ASSERT(false && "Unexpected type."); return 0.0; @@ -425,79 +421,79 @@ namespace NJson { } bool TJsonValue::GetBooleanSafe() const { - if (Type != JSON_BOOLEAN) + if (Type != JSON_BOOLEAN) { ythrow TJsonException() << "Not a boolean"; - + } return Value.Boolean; } long long TJsonValue::GetIntegerSafe() const { - if (!IsInteger()) + if (!IsInteger()) { ythrow TJsonException() << "Not an integer"; - + } return GetInteger(); } unsigned long long TJsonValue::GetUIntegerSafe() const { - if (!IsUInteger()) + if (!IsUInteger()) { ythrow TJsonException() << "Not an unsigned integer"; - + } return GetUInteger(); } double TJsonValue::GetDoubleSafe() const { - if (!IsDouble()) + if (!IsDouble()) { ythrow TJsonException() << "Not a double"; - + } return GetDouble(); } const TString& TJsonValue::GetStringSafe() const { - if (Type != JSON_STRING) + if (Type != JSON_STRING) { ythrow TJsonException() << "Not a string"; - + } return Value.String; } bool TJsonValue::GetBooleanSafe(const bool defaultValue) const { - if (Type == JSON_UNDEFINED) + if (Type == JSON_UNDEFINED) { return defaultValue; - + } return GetBooleanSafe(); } long long TJsonValue::GetIntegerSafe(const long long defaultValue) const { - if (Type == JSON_UNDEFINED) + if (Type == JSON_UNDEFINED) { return defaultValue; - + } return GetIntegerSafe(); } unsigned long long TJsonValue::GetUIntegerSafe(const unsigned long long defaultValue) const { - if (Type == JSON_UNDEFINED) + if (Type == JSON_UNDEFINED) { return defaultValue; - + } return GetUIntegerSafe(); } double TJsonValue::GetDoubleSafe(const double defaultValue) const { - if (Type == JSON_UNDEFINED) + if (Type == JSON_UNDEFINED) { return defaultValue; - + } return GetDoubleSafe(); } TString TJsonValue::GetStringSafe(const TString& defaultValue) const { - if (Type == JSON_UNDEFINED) + if (Type == JSON_UNDEFINED) { return defaultValue; - + } return GetStringSafe(); } const TJsonValue::TMapType& TJsonValue::GetMapSafe() const { - if (Type != JSON_MAP) + if (Type != JSON_MAP) { ythrow TJsonException() << "Not a map"; - + } return *Value.Map; } @@ -506,9 +502,9 @@ namespace NJson { } const TJsonValue::TArray& TJsonValue::GetArraySafe() const { - if (Type != JSON_ARRAY) + if (Type != JSON_ARRAY) { ythrow TJsonException() << "Not an array"; - + } return *Value.Array; } @@ -646,73 +642,73 @@ namespace NJson { } bool TJsonValue::GetBoolean(bool* value) const noexcept { - if (Type != JSON_BOOLEAN) + if (Type != JSON_BOOLEAN) { return false; - + } *value = Value.Boolean; return true; } bool TJsonValue::GetInteger(long long* value) const noexcept { - if (!IsInteger()) + if (!IsInteger()) { return false; - + } *value = GetInteger(); return true; } bool TJsonValue::GetUInteger(unsigned long long* value) const noexcept { - if (!IsUInteger()) + if (!IsUInteger()) { return false; - + } *value = GetUInteger(); return true; } bool TJsonValue::GetDouble(double* value) const noexcept { - if (!IsDouble()) + if (!IsDouble()) { return false; - + } *value = GetDouble(); return true; } bool TJsonValue::GetString(TString* value) const { - if (Type != JSON_STRING) + if (Type != JSON_STRING) { return false; - + } *value = Value.String; return true; } bool TJsonValue::GetMap(TJsonValue::TMapType* value) const { - if (Type != JSON_MAP) + if (Type != JSON_MAP) { return false; - + } *value = *Value.Map; return true; } bool TJsonValue::GetArray(TJsonValue::TArray* value) const { - if (Type != JSON_ARRAY) + if (Type != JSON_ARRAY) { return false; - + } *value = *Value.Array; return true; } bool TJsonValue::GetMapPointer(const TJsonValue::TMapType** value) const noexcept { - if (Type != JSON_MAP) + if (Type != JSON_MAP) { return false; - + } *value = Value.Map; return true; } bool TJsonValue::GetArrayPointer(const TJsonValue::TArray** value) const noexcept { - if (Type != JSON_ARRAY) + if (Type != JSON_ARRAY) { return false; - + } *value = Value.Array; return true; } @@ -770,13 +766,10 @@ namespace NJson { switch (Type) { case JSON_INTEGER: return true; - case JSON_UINTEGER: return (Value.UInteger <= static_cast<unsigned long long>(Max<long long>())); - case JSON_DOUBLE: return ((long long)Value.Double == Value.Double); - default: return false; } @@ -786,13 +779,10 @@ namespace NJson { switch (Type) { case JSON_UINTEGER: return true; - case JSON_INTEGER: return (Value.Integer >= 0); - case JSON_DOUBLE: return ((unsigned long long)Value.Double == Value.Double); - default: return false; } @@ -804,13 +794,10 @@ namespace NJson { switch (Type) { case JSON_DOUBLE: return true; - case JSON_INTEGER: return (1ll << std::numeric_limits<double>::digits) >= Abs(Value.Integer); - case JSON_UINTEGER: return (1ull << std::numeric_limits<double>::digits) >= Value.UInteger; - default: return false; } @@ -860,12 +847,10 @@ namespace NJson { } else { currentJson = CreateOrNullptr(currentJson, step, create_tag); } - if (!currentJson) { return nullptr; } } - return currentJson; } } // anonymous namespace @@ -909,7 +894,6 @@ namespace NJson { if (!callback.Do(path, parent, *this)) { return; } - if (Type == JSON_MAP) { for (auto&& i : *Value.Map) { i.second.DoScan(!!path ? TString::Join(path, ".", i.first) : i.first, this, callback); @@ -947,40 +931,24 @@ namespace NJson { bool TJsonValue::operator==(const TJsonValue& rhs) const { switch (Type) { - case JSON_UNDEFINED: { + case JSON_UNDEFINED: return (rhs.GetType() == JSON_UNDEFINED); - } - - case JSON_NULL: { + case JSON_NULL: return rhs.IsNull(); - } - - case JSON_BOOLEAN: { + case JSON_BOOLEAN: return (rhs.IsBoolean() && Value.Boolean == rhs.Value.Boolean); - } - - case JSON_INTEGER: { + case JSON_INTEGER: return (rhs.IsInteger() && GetInteger() == rhs.GetInteger()); - } - - case JSON_UINTEGER: { + case JSON_UINTEGER: return (rhs.IsUInteger() && GetUInteger() == rhs.GetUInteger()); - } - - case JSON_STRING: { + case JSON_STRING: return (rhs.IsString() && Value.String == rhs.Value.String); - } - - case JSON_DOUBLE: { + case JSON_DOUBLE: return (rhs.IsDouble() && fabs(GetDouble() - rhs.GetDouble()) <= FLT_EPSILON); - } - case JSON_MAP: return AreJsonMapsEqual(*this, rhs); - case JSON_ARRAY: return AreJsonArraysEqual(*this, rhs); - default: Y_ASSERT(false && "Unknown type."); return false; @@ -995,7 +963,6 @@ namespace NJson { } else { std::memcpy(&output.Value, &Value, sizeof(Value)); } - output.Type = Type; Type = JSON_UNDEFINED; } @@ -1009,8 +976,10 @@ namespace NJson { void TJsonValue::Save(IOutputStream* s) const { ::Save(s, static_cast<ui8>(Type)); switch (Type) { - case JSON_UNDEFINED:break; - case JSON_NULL:break; + case JSON_UNDEFINED: + break; + case JSON_NULL: + break; case JSON_BOOLEAN: ::Save(s, Value.Boolean); break; @@ -1042,8 +1011,10 @@ namespace NJson { SetType(static_cast<EJsonValueType>(loadedType)); } switch (Type) { - case JSON_UNDEFINED:break; - case JSON_NULL:break; + case JSON_UNDEFINED: + break; + case JSON_NULL: + break; case JSON_BOOLEAN: ::Load(s, Value.Boolean); break; @@ -1072,48 +1043,49 @@ namespace NJson { bool GetMapPointer(const TJsonValue& jv, const size_t index, const TJsonValue::TMapType** value) { const TJsonValue* v; - if (!jv.GetValuePointer(index, &v) || !v->IsMap()) + if (!jv.GetValuePointer(index, &v) || !v->IsMap()) { return false; - + } *value = &v->GetMap(); return true; } bool GetArrayPointer(const TJsonValue& jv, const size_t index, const TJsonValue::TArray** value) { const TJsonValue* v; - if (!jv.GetValuePointer(index, &v) || !v->IsArray()) + if (!jv.GetValuePointer(index, &v) || !v->IsArray()) { return false; - + } *value = &v->GetArray(); return true; } bool GetMapPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TMapType** value) { const TJsonValue* v; - if (!jv.GetValuePointer(key, &v) || !v->IsMap()) + if (!jv.GetValuePointer(key, &v) || !v->IsMap()) { return false; - + } *value = &v->GetMap(); return true; } bool GetArrayPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TArray** value) { const TJsonValue* v; - if (!jv.GetValuePointer(key, &v) || !v->IsArray()) + if (!jv.GetValuePointer(key, &v) || !v->IsArray()) { return false; - + } *value = &v->GetArray(); return true; } void TJsonValue::BackChecks() const { - if (Type != JSON_ARRAY) + if (Type != JSON_ARRAY) { ythrow TJsonException() << "Not an array"; - - if (Value.Array->empty()) + } + if (Value.Array->empty()) { ythrow TJsonException() << "Get back on empty array"; + } } -} +} // namespace NJson template <> void Out<NJson::TJsonValue>(IOutputStream& out, const NJson::TJsonValue& v) { diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h index 789a629807c..ec919697dc7 100644 --- a/library/cpp/json/writer/json_value.h +++ b/library/cpp/json/writer/json_value.h @@ -120,7 +120,7 @@ namespace NJson { const TMapType& GetMap() const Y_LIFETIME_BOUND; const TArray& GetArray() const Y_LIFETIME_BOUND; - //throwing TJsonException possible + // throwing TJsonException possible bool GetBooleanSafe() const; long long GetIntegerSafe() const; unsigned long long GetUIntegerSafe() const; @@ -273,7 +273,8 @@ namespace NJson { public: TJsonMap() : TJsonValue(NJson::JSON_MAP) - {} + { + } TJsonMap(const std::initializer_list<std::pair<TString, TJsonValue>>& list) : TJsonValue(NJson::JSON_MAP) @@ -286,7 +287,8 @@ namespace NJson { public: TJsonArray() : TJsonValue(NJson::JSON_ARRAY) - {} + { + } TJsonArray(const std::initializer_list<TJsonValue>& list) : TJsonValue(NJson::JSON_ARRAY) @@ -294,4 +296,4 @@ namespace NJson { GetArraySafe() = TJsonValue::TArray(list); } }; -} +} // namespace NJson diff --git a/library/cpp/json/writer/json_value_ut.cpp b/library/cpp/json/writer/json_value_ut.cpp index 6fc1e56f792..21b396a64de 100644 --- a/library/cpp/json/writer/json_value_ut.cpp +++ b/library/cpp/json/writer/json_value_ut.cpp @@ -8,10 +8,10 @@ using namespace NJson; Y_UNIT_TEST_SUITE(TJsonValueTest) { Y_UNIT_TEST(Equal) { - UNIT_ASSERT(1 == TJsonValue(1)); - UNIT_ASSERT(TJsonValue(1) == 1); - UNIT_ASSERT(2 != TJsonValue(1)); - UNIT_ASSERT(TJsonValue(1) != 2); + UNIT_ASSERT(1 == TJsonValue(1)); + UNIT_ASSERT(TJsonValue(1) == 1); + UNIT_ASSERT(2 != TJsonValue(1)); + UNIT_ASSERT(TJsonValue(1) != 2); } Y_UNIT_TEST(UndefTest) { @@ -175,15 +175,16 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) { const int NUM_KEYS = 1000; TJsonValue lhs; - for (int i = 0; i < NUM_KEYS; ++i) + for (int i = 0; i < NUM_KEYS; ++i) { lhs.InsertValue(ToString(i), i); - + } TJsonValue rhs; - for (int i = 0; i < NUM_KEYS; i += 2) + for (int i = 0; i < NUM_KEYS; i += 2) { rhs.InsertValue(ToString(i), i); - for (int i = 1; i < NUM_KEYS; i += 2) + } + for (int i = 1; i < NUM_KEYS; i += 2) { rhs.InsertValue(ToString(i), i); - + } UNIT_ASSERT(lhs == rhs); UNIT_ASSERT(rhs == lhs); } @@ -681,4 +682,4 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) { UNIT_ASSERT_VALUES_EQUAL(filled["4"].GetMapSafe().size(), 1); UNIT_ASSERT_VALUES_EQUAL(filled["4"]["5"], TJsonValue{5}); } -} // TJsonValueTest +} // Y_UNIT_TEST_SUITE(TJsonValueTest) |
